Пример #1
0
def test_character_block():
    block = CharacterBlock(trim("""
        @ X
        """))
    assert block.text() == '\n@ X'  # <-- with leading space for a heading
    expected = '<p class="subhead">X</p>'
    assert block.html_only(Html(), Settings()) == expected
Пример #2
0
def test_paragraph():
    block = Paragraph(trim("""
        x
        y
        x
        """))
    assert block.text() == 'x y x'
    assert block.html_only(Html(), Settings()) == '<p>x y x</p>'
Пример #3
0
def DISABLED_test_simplest_graph():  # <-- Restore when Dot() is added again.
    """
    Minimal sanity check.
    """
    text = trim("""
        digraph G {
            Hello -> World
        }
        """)
    dot = Dot([], text)
    svg = dot.html(Html())
    for _ in ['<svg', 'Hello', 'World', '</svg>']:
        assert _ in svg
Пример #4
0
    def html(self, numbering, slug, settings, fragment=False, preview=False):
        """
        Produce HTML, passing along any settings that were updated while
        processing any block.

        - A fragment has no title lines (rename: no_titles?).
          (Used in demo blocks.)
        - A preview has no section numbering in its title.
          (Used in the editor.)
        """
        renderer = Html({})
        renderer.settings = copy(settings)
        out = []
        # Headings (if required)
        if not fragment and slug != 'index':
            out += ['<hgroup>']
            title, summary = self.pop_titles()
            nav_id = get_section_nav_id(numbering, slug)
            if preview:
                head = '<h1 id="%s"><a href="#%s">%s</a></h1>' % (
                    nav_id, nav_id, renderer.inline.process(title))
            else:
                number = '.'.join([str(_) for _ in numbering])
                head = '<h1 id="%s"><a href="#%s">%s. &nbsp; %s</a></h1>' % (
                    nav_id, nav_id, number, renderer.inline.process(title))
            out += [head]
            if summary != '':
                out += [
                    '<p class="summary">%s</p>' %
                    renderer.inline.process(summary)
                ]
            out += ['</hgroup>']
        # Assemble
        local_settings = copy(settings)
        for _ in self.blocks:
            block_html, local_settings = _.html(renderer, local_settings)
            out += [block_html]
        return "\n\n".join(out)
Пример #5
0
    def __init__(self, settings=None):
        """
        Settings hold all necessary context information.
        """
        assert isinstance(settings, Settings) or settings is None

        self.settings = settings
        self.html = Html(self.settings)

        self.id_prefix = self.settings.get(
            'config:document',
            random_slug('wiki_')  # <-- else
        )

        self.outline = None
        self.cross_references = None
        self.footnotes = None
        self.links = None
        self.index = None
        self.tags = None
        self.bibliography = None
        self.citations = None
Пример #6
0
def test_function_block():
    block = FunctionBlock(Text, [], '-', 'x')
    assert block.text() == 'TEXT ---\nx\n---'
    assert block.html_only(Html(), Settings()) == '<pre>x</pre>'
Пример #7
0
def test_divider():
    block = Divider(trim("""
        - - -
        """))
    assert block.text() == '- - -'
    assert block.html_only(Html(), Settings()) == '<hr class="div-solid" />'