예제 #1
0
def convert(markup, flavor, options=None):
    text_storage = TextStorage()
    env_storage = EnvironmentStorage(options)
    style_cls = Style.with_identifier(flavor)

    block_parser = Parser(style_cls)
    block_renderer = Renderer(style_cls, text_storage, env_storage)

    return block_renderer.render(block_parser.parse(markup))
예제 #2
0
def convert(markup, flavor, options=None):
  text_storage = TextStorage()
  env_storage = EnvironmentStorage(options)
  style_cls = Style.with_identifier(flavor)

  block_parser = Parser(style_cls)
  block_renderer = Renderer(style_cls, text_storage, env_storage)

  return block_renderer.render(block_parser.parse(markup))
예제 #3
0
파일: Color.py 프로젝트: lwxted/n0ted0wn
 def _transform_args(self):
   if not self._params:
     return None
   self.color = self._params[0]
   from n0ted0wn.Block.Parser import Parser
   self.blocks_list = Parser(self.style_cls, 0).parse(self.content)
   return self
예제 #4
0
    def _transform_args(self):
        if '* [ ] ' not in self.content and \
           '* [x] ' not in self.content and \
           '* [X] ' not in self.content:
            return None
        lines = self.content.split('\n')
        parsed_items = []
        for l in lines:
            if l.startswith('  ') or not l.strip():
                parsed_items[-1][2].append(l)
            else:
                item_marker_len = len('* [ ] ')
                done = l.startswith('* [x] ') or l.startswith('* [X] ')
                if not l.startswith('* [ ] ') and not done:
                    return None
                # Starts with * [ ] or * [x] or * [X]
                parsed_items.append((done, l[item_marker_len:], []))

        from n0ted0wn.Block.Parser import Parser

        for (done, label, lines) in parsed_items:
            self.parsed_items.append(
                (done, label, Parser(self.style_cls,
                                     2).parse('\n'.join(lines))))

        return self
예제 #5
0
    def _transform_args(self):
        item_marker_index = self.content.find('* ')
        if item_marker_index == -1:
            return None

        lines = self.content.split('\n')
        grouped_lines = []
        for l in lines:
            if l.startswith('  ') or not l.strip():
                if not grouped_lines:
                    return None
                grouped_lines[-1].append(l)
            else:
                counter_marker = '* '
                if not l.startswith(counter_marker):
                    return None
                grouped_lines.append([' ' * len(counter_marker) + \
                  l[len(counter_marker):]])

        from n0ted0wn.Block.Parser import Parser

        for lines in grouped_lines:
            self.parsed_blocks_list.append(
                Parser(self.style_cls, 2).parse('\n'.join(lines)))
        return self
예제 #6
0
    def _transform_args(self):
        first_dot_index = self.content.find('. ')
        if first_dot_index == -1:
            return None
        start_index_str = self.content[0:first_dot_index]
        if not start_index_str.isdigit():
            return None
        self.start_index = int(start_index_str)

        current_index = self.start_index
        lines = self.content.split('\n')
        grouped_lines = []
        for l in lines:
            counter_marker = unicode(current_index) + '. '
            if l.startswith(counter_marker):
                grouped_lines.append((current_index, [' ' * len(counter_marker) + \
                  l[len(counter_marker):]]))
                current_index += 1
            elif l.startswith(' ' * (len(unicode(current_index - 1)) + 2)) or \
              not l.strip():
                if not grouped_lines:
                    return None
                grouped_lines[-1][1].append(l)
            else:
                return None

        from n0ted0wn.Block.Parser import Parser

        for (index, lines) in grouped_lines:
            self.parsed_blocks_list.append(
                Parser(self.style_cls,
                       len(unicode(index)) + 2).parse('\n'.join(lines)))
        return self
예제 #7
0
 def parse(cls, raw, style_cls):
     raw = raw.strip()
     first_dot_index = raw.find('. ')
     if first_dot_index == -1:
         return None
     start_index_str = raw[0:first_dot_index]
     if not start_index_str.isdigit():
         return None
     start_index = int(start_index_str)
     current_index = start_index
     items = []
     lines = raw.split('\n')
     for l in lines:
         content_marker = unicode(current_index) + '. '
         if l.startswith(content_marker):
             items.append(l[len(content_marker):])
             current_index += 1
         else:
             prev_content_marker_str_len = len(
                 unicode(current_index - 1)) + 2
             if l.startswith(' ' * prev_content_marker_str_len):
                 if not items:
                     return None
                 else:
                     items[-1] += '\n' + l[prev_content_marker_str_len:]
             else:
                 return None
     from n0ted0wn.Block.Parser import Parser
     return OrderedList(raw, start_index, \
       [Parser(style_cls, 0).parse(item) for item in items], style_cls)
예제 #8
0
 def _transform_args(self):
     first_line_break = self.content.find('\n')
     if first_line_break == -1:
         return None
     self.title = self.content[:first_line_break]
     from n0ted0wn.Block.Parser import Parser
     self.explanation_blocks_list = Parser(self.style_cls, 0)\
       .parse(self.content[first_line_break + 1:])
     return self
예제 #9
0
파일: MonthDay.py 프로젝트: lwxted/n0ted0wn
 def _transform_args(self):
     from n0ted0wn.Block.Parser import Parser
     if not self._params:
         return None
     try:
         self.month = int(self._params[0])
     except ValueError:
         return None
     self.content_blocks_list = Parser(self.style_cls,
                                       0).parse(self.content)
     return self
예제 #10
0
 def parse(cls, raw, style_cls):
     lines = raw.strip().split('\n')
     items = []
     for l in lines:
         if l.startswith('* '):
             items.append(l[2:])
         elif l.startswith('  '):
             if not items:
                 return None
             else:
                 items[-1] += '\n' + l[2:]
         else:
             return None
     from n0ted0wn.Block.Parser import Parser
     return cls(raw, \
       [Parser(style_cls, 0).parse(item) for item in items], style_cls)
예제 #11
0
파일: Center.py 프로젝트: lwxted/n0ted0wn
 def _transform_args(self):
   from n0ted0wn.Block.Parser import Parser
   self.blocks_list = Parser(self.style_cls, 0).parse(self.content)
   return self