コード例 #1
0
def new_row(first_node: Node, last_node: Node) -> Node:
    if first_node.t != 'text':
        raise NotTableError(1)
    if last_node.t != 'text':
        raise NotTableError(2)
    if not first_node.literal.startswith('|'):
        raise NotTableError(3)
    if not last_node.literal.rstrip().endswith('|'):
        raise NotTableError(4)

    first_node.literal = first_node.literal[1:].lstrip()
    last_node.literal = last_node.literal.rstrip()[:-1].rstrip()

    if first_node.literal == '':
        if first_node.nxt is None:
            raise NotTableError(5)
        first_node = first_node.nxt

    if last_node.literal == '':
        if last_node.prv is None:
            raise NotTableError(6)
        last_node = last_node.prv

    row = Node('tablerow', None)
    for cell in yield_cells(first_node, last_node):
        row.append_child(cell)
    return row
コード例 #2
0
def new_cell(first_node: Node, last_node: Node) -> Node:
    node = first_node
    cell = Node('tablecell', None)
    while node:
        if node.t != 'text' or not '|' in node.literal:
            cell.append_child(copy.copy(node))
            if node == last_node:
                node = None
            else:
                node = node.nxt
        else:
            _node = node
            node = copy.copy(node)
            new_node = Node('text', None)
            text, remainder = node.literal.split('|', 1)
            node.literal = remainder.lstrip()
            new_node.literal = text.rstrip()
            if not node.literal:
                if _node == last_node:
                    node = None
                else:
                    node = node.nxt
            if new_node.literal:
                cell.append_child(new_node)
            break
    return cell, node
コード例 #3
0
ファイル: inlines.py プロジェクト: nikolas/CommonMark-py
 def parseHtmlTag(self, block):
     """Attempt to parse a raw HTML tag."""
     m = self.match(common.reHtmlTag)
     if m is None:
         return False
     else:
         node = Node('html_inline', None)
         node.literal = m
         block.append_child(node)
         return True
コード例 #4
0
ファイル: inlines.py プロジェクト: hamx0r/CommonMark-py
 def parseHtmlTag(self, block):
     """Attempt to parse a raw HTML tag."""
     m = self.match(common.reHtmlTag)
     if m is None:
         return False
     else:
         node = Node('html_inline', None)
         node.literal = m
         block.append_child(node)
         return True
コード例 #5
0
ファイル: inlines.py プロジェクト: nikolas/CommonMark-py
 def parseBackticks(self, block):
     """ Attempt to parse backticks, adding either a backtick code span or a
     literal sequence of backticks to the 'inlines' list."""
     ticks = self.match(reTicksHere)
     if ticks is None:
         return False
     after_open_ticks = self.pos
     matched = self.match(reTicks)
     while matched is not None:
         if matched == ticks:
             node = Node('code', None)
             contents = self.subject[after_open_ticks:self.pos-len(ticks)] \
                 .replace('\n', ' ')
             if contents.lstrip(' ') and contents[0] == contents[-1] == ' ':
                 node.literal = contents[1:-1]
             else:
                 node.literal = contents
             block.append_child(node)
             return True
         matched = self.match(reTicks)
     # If we got here, we didn't match a closing backtick sequence.
     self.pos = after_open_ticks
     block.append_child(text(ticks))
     return True
コード例 #6
0
ファイル: inlines.py プロジェクト: hamx0r/CommonMark-py
 def parseBackticks(self, block):
     """ Attempt to parse backticks, adding either a backtick code span or a
     literal sequence of backticks to the 'inlines' list."""
     ticks = self.match(reTicksHere)
     if ticks is None:
         return False
     after_open_ticks = self.pos
     matched = self.match(reTicks)
     while matched is not None:
         if matched == ticks:
             node = Node('code', None)
             contents = self.subject[after_open_ticks:self.pos-len(ticks)] \
                 .replace('\n', ' ')
             if contents.lstrip(' ') and contents[0] == contents[-1] == ' ':
                 node.literal = contents[1:-1]
             else:
                 node.literal = contents
             block.append_child(node)
             return True
         matched = self.match(reTicks)
     # If we got here, we didn't match a closing backtick sequence.
     self.pos = after_open_ticks
     block.append_child(text(ticks))
     return True
コード例 #7
0
 def parseBackticks(self, block):
     """ Attempt to parse backticks, adding either a backtick code span or a
     literal sequence of backticks to the 'inlines' list."""
     ticks = self.match(reTicksHere)
     if ticks is None:
         return False
     after_open_ticks = self.pos
     matched = self.match(reTicks)
     while matched is not None:
         if (matched == ticks):
             node = Node('code', None)
             c = self.subject[after_open_ticks:self.pos - len(ticks)]
             c = c.strip()
             c = re.sub(reWhitespace, ' ', c)
             node.literal = c
             block.append_child(node)
             return True
         matched = self.match(reTicks)
     # If we got here, we didn't match a closing backtick sequence.
     self.pos = after_open_ticks
     block.append_child(text(ticks))
     return True
コード例 #8
0
ファイル: inlines.py プロジェクト: nikolas/CommonMark-py
def text(s):
    node = Node('text', None)
    node.literal = s
    return node
コード例 #9
0
ファイル: inlines.py プロジェクト: hamx0r/CommonMark-py
def text(s):
    node = Node('text', None)
    node.literal = s
    return node