def testExpandLinks(self):
    """
    <a href=$xref:bash>bash</a>
    ->
    <a href=/cross-ref?tag=bash#bash>

    NOTE: THIs could really be done with a ref like <a.*href="(.*)">
    But we're testing it
    """
    print(oil_doc.ExpandLinks(TEST_HTML))
Example #2
0
    def testExpandLinks(self):
        """
    <a href=$xref:bash>bash</a>
    ->
    <a href=/cross-ref?tag=bash#bash>

    NOTE: THIs could really be done with a ref like <a.*href="(.*)">
    But we're testing it
    """
        h = oil_doc.ExpandLinks(TEST_HTML)
        self.assert_('/blog/tags.html' in h, h)
Example #3
0
def Render(opts, in_file, out_file, use_fastlex=True):
    html = md2html(in_file.read())

    if use_fastlex:
        html = oil_doc.RemoveComments(html)

        # Hack for allowing tables without <p> in cells, which CommonMark seems to require?
        html = html.replace('<p><pstrip>', '')
        html = html.replace('</pstrip></p>', '')

        # Stages of transformation.
        html = oil_doc.ExpandLinks(html)

        html = oil_doc.HighlightCode(html)

    # h2 is the title.  h1 is unused.
    if opts.toc_tags:
        toc_tags = opts.toc_tags
    else:
        toc_tags = ('h3', 'h4')

    parser = TocExtractor()
    parser.feed(html)

    log('')
    log('*** HTML headings:')
    for heading in parser.headings:
        log(heading)

    if parser.toc_begin_line == -1:  # Not found!
        out_file.write(html)  # Pass through
        return

    insertions = _MakeTocAndAnchors(opts, toc_tags, parser.headings,
                                    parser.toc_begin_line)

    log('')
    log('*** Text Insertions:')
    for ins in insertions:
        log(ins)

    log('')
    log('*** Output:')

    lines = html.splitlines(True)  # keep newlines
    _ApplyInsertions(lines, insertions, out_file)