(text, doc)
return "\n".join(lines)
Convert footnotes from github-flavored markdown into extended markdown

    The extended markdown format provides a more specific syntax for footnotes,
    which pandoc can process and convert into LaTeX footnotes.

    This function assumes each document has a unique set of footnotes, and that
    multiple docs can adopt the same footnote numbering. It keeps a global
    record of footnotes and increases the footnote number such that the
    concatenated text does not have duplicate footnotes.
Convert footnotes from github-flavored markdown into extended markdown
Convert footnotes from github - flavored markdown into extended markdown
def convert_footnotes(text, doc):
    """Convert footnotes from github-flavored markdown into extended markdown

    The extended markdown format provides a more specific syntax for footnotes,
    which pandoc can process and convert into LaTeX footnotes.

    This function assumes each document has a unique set of footnotes, and that
    multiple docs can adopt the same footnote numbering. It keeps a global
    record of footnotes and increases the footnote number such that the
    concatenated text does not have duplicate footnotes.

    """
    lines = text.splitlines()
    footnote = None

    for i, line in enumerate(lines):
        if "<sup>" in line:
            footnote = re.search(r"<sup>(.*?)</sup>", line).group(1)

            if doc not in footnote_map:
                footnote_map[doc] = {}

            # Assign a global footnote number
            if footnote in footnote_map[doc]:
                i_footnote = footnote_map[doc][footnote]['idx']
            else:
                i_footnote = sum([len(x) for x in footnote_map.values()]) + 1
                footnote_map[doc][footnote] = {
                    'idx': i_footnote,
                    'ref_missing': True
                }

            if footnote_map[doc][footnote]['ref_missing']:
                # Footnote reference (without colon)
                lines[i] = line.replace("<sup>" + footnote + "</sup>",
                                        "[^{}]".format(i_footnote))
                footnote_map[doc][footnote]['ref_missing'] = False
            else:
                # Footnote definition (with colon)
                lines[i] = line.replace("<sup>" + footnote + "</sup>",
                                        "[^{}]:".format(i_footnote))
    return "\n".join(lines)
def convert_footnotes ( text , doc ) : lines = text . splitlines ( ) footnote = None for i , line in enumerate ( lines ) : if "<sup>" in line : footnote = re . search ( r"<sup>(.*?)</sup>" , line ) . group ( 1 ) if doc not in footnote_map : footnote_map [ doc ] = { } # Assign a global footnote number if footnote in footnote_map [ doc ] : i_footnote = footnote_map [ doc ] [ footnote ] [ 'idx' ] else : i_footnote = sum ( [ len ( x ) for x in footnote_map . values ( ) ] ) + 1 footnote_map [ doc ] [ footnote ] = { 'idx' : i_footnote , 'ref_missing' : True } if footnote_map [ doc ] [ footnote ] [ 'ref_missing' ] : # Footnote reference (without colon) lines [ i ] = line . replace ( "<sup>" + footnote + "</sup>" , "[^{}]" . format ( i_footnote ) ) footnote_map [ doc ] [ footnote ] [ 'ref_missing' ] = False else : # Footnote definition (with colon) lines [ i ] = line . replace ( "<sup>" + footnote + "</sup>" , "[^{}]:" . format ( i_footnote ) ) return "\n" . join ( lines )