예제 #1
0
    def testEnumeratedList(self):
        node = get_root()

        def get_item(text):
            node = Node("ListItem")
            para = Node("Paragraph")
            para.children.append(TextNode(text))
            node.children.append(para)
            return node

        list_node = Node("List")
        list_node.attributes["MarkerStyle"] = "Decimal"
        list_node.children.append(get_item("first"))
        list_node.children.append(get_item("second"))
        list_node.children.append(get_item("third"))

        node.children.append(list_node)

        actual = tree_from_string(
            """\
            1. first
            2. second
            3. third"""
        )

        self.assertEqual(actual, node)
예제 #2
0
def get_sl_paragraph():
    para = Node("TextBlock")
    para.attributes["FontSize"] = FONT_SIZE
    para.attributes["Margin"] = "0,10,0,0"
    para.attributes["TextWrapping"] = "Wrap"
    para.attributes["FontFamily"] = FONTS
    return para
예제 #3
0
    def testLiteralBlock(self):
        node = get_root()
        literal = Node("Paragraph")
        literal.attributes["FontFamily"] = MONOSPACE
        literal.attributes["xml:space"] = "preserve"
        node.children.append(literal)
        literal.children.append(TextNode("foo"))

        self.assertEqual(tree_from_string("::\n\n    foo"), node)
예제 #4
0
    def testLiteral(self):
        node = get_root_sl()
        para = get_sl_paragraph()
        literal = Node("Run")
        literal.attributes["FontFamily"] = MONOSPACE
        para.children.append(literal)
        literal.children.append(TextNode("foo  bar"))
        node.children.append(para)

        self.assertEqual(tree_from_string_sl("``foo  bar``"), node)
예제 #5
0
    def testLiteral(self):
        node = get_root()
        para = Node("Paragraph")
        literal = Node("Run")
        literal.attributes["FontFamily"] = MONOSPACE
        literal.attributes["xml:space"] = "preserve"
        para.children.append(literal)
        literal.children.append(TextNode("foo  bar"))
        node.children.append(para)

        self.assertEqual(tree_from_string("``foo  bar``"), node)
예제 #6
0
    def testBold(self):
        tree = tree_from_string_sl("**Hello**")

        node = get_root_sl()
        para = get_sl_paragraph()
        italic = Node("Run")
        italic.attributes["FontWeight"] = "Bold"
        para.children.append(italic)
        para.children[0].children.append(TextNode("Hello"))

        node.children.append(para)
        self.assertEqual(tree, node)
예제 #7
0
 def testEquality(self):
     node = Node('foo')
     self.assertEqual(node, Node('foo'))
     self.assertNotEqual(node, Node('bar'))
     
     node.attributes['foo'] = 'fish'
     node2 = Node('foo')
     self.assertNotEqual(node, node2)
     
     node2.attributes['foo'] = 'fish'
     self.assertEqual(node, node2)
     
     node.children.append(Node('bar'))
     self.assertNotEqual(node, node2)
     
     node2.children.append(Node('bar'))
     self.assertEqual(node, node2)
예제 #8
0
    def testBlockquote(self):
        tree = tree_from_string_sl("Hello\n\n    foo\n")

        node = get_root_sl()
        para = get_sl_paragraph()
        para.children.append(TextNode("Hello"))
        node.children.append(para)

        block = Node("StackPanel")
        block.attributes["Margin"] = MARGIN
        para2 = get_sl_paragraph()
        para2.children.append(TextNode("foo"))
        block.children.append(para2)

        node.children.append(block)

        self.assertEqual(tree, node)
예제 #9
0
    def testBlockquote(self):
        tree = tree_from_string("Hello\n\n    foo\n")

        node = get_root()
        para = Node("Paragraph")
        para.children.append(TextNode("Hello"))
        node.children.append(para)

        section = Node("Section")
        section.attributes["Margin"] = "16,0,0,0"
        quote = Node("Paragraph")
        quote.children.append(TextNode("foo"))
        section.children.append(quote)

        node.children.append(section)

        self.assertEqual(tree, node)
예제 #10
0
def get_grid_sl(items, enumerated=True):
    node = get_root_sl()
    grid = Node("Grid")
    grid.attributes["Margin"] = "0,10,0,0"
    node.children.append(grid)
    columns = Node("Grid.ColumnDefinitions")
    grid.children.append(columns)
    col = Node("ColumnDefinition")
    col.attributes["Width"] = "Auto"
    columns.children.append(col)
    columns.children.append(Node("ColumnDefinition"))
    rows = Node("Grid.RowDefinitions")
    grid.children.append(rows)
    rows.children = [Node("RowDefinition") for _ in items]

    for i, item in enumerate(items):
        bullet = Node("TextBlock")
        point = "•"
        if enumerated:
            point = str(i + 1) + "."
        bullet.attributes["Grid.Row"] = str(i)
        bullet.attributes["Grid.Column"] = "0"
        bullet.attributes["FontFamily"] = FONTS
        bullet.children.append(TextNode(point))

        bullet_text = Node("StackPanel")
        bullet_text.attributes["Margin"] = "5,0,0,5"
        bullet_text.attributes["Grid.Row"] = str(i)
        bullet_text.attributes["Grid.Column"] = "1"
        para = get_sl_paragraph()
        del para.attributes["Margin"]
        para.children.append(TextNode(item))
        bullet_text.children.append(para)

        grid.children.append(bullet)
        grid.children.append(bullet_text)
    return node
예제 #11
0
 def get_title(fontsize, text, FontWeight=None, FontStyle=None):
     node = Node("TextBlock")
     node.children.append(TextNode(text))
     if FontWeight is not None:
         node.attributes["FontWeight"] = FontWeight
     node.attributes["Margin"] = "0,10,0,0"
     node.attributes["FontFamily"] = FONTS
     if FontStyle is not None:
         node.attributes["FontStyle"] = FontStyle
     node.attributes["FontSize"] = str(fontsize)
     return node
예제 #12
0
 def testToStringSimple(self):
     node = Node('foo')
     self.assertEqual(node.to_string(), '<foo />')
예제 #13
0
 def get_title(fontsize, text, **attributes):
     node = Node("Paragraph")
     node.children.append(TextNode(text))
     node.attributes.update(attributes.items())
     node.attributes["FontSize"] = str(fontsize)
     return node
예제 #14
0
def get_root():
    node = Node("FlowDocument")
    node.attributes["FontSize"] = FONT_SIZE
    node.attributes["xmlns"] = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    node.attributes["xmlns:x"] = "http://schemas.microsoft.com/winfx/2006/xaml"
    return node
예제 #15
0
 def testToStringChildren(self):
     node = Node('foo')
     node.children.append(Node('bar'))
     self.assertEqual(node.to_string(), '<foo><bar /></foo>')
예제 #16
0
 def testToStringAttributes(self):
     node = Node('foo')
     node.attributes['bar'] = 'baz'
     self.assertEqual(node.to_string(), '<foo bar="baz" />')
예제 #17
0
def get_root_sl():
    node = Node("StackPanel")
    node.attributes["x:Class"] = "System.Windows.Controls.StackPanel"
    node.attributes["xmlns"] = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    node.attributes["xmlns:x"] = "http://schemas.microsoft.com/winfx/2006/xaml"
    return node