{.quotelead}', '
') ret = re.sub(r'
\n((?:\n)*)(?:\{\.quote(\w+)\})', r'
\n\g<1>', ret, flags=re.MULTILINE) return ret def _convert_with_pandoc(mdwn, inputfmt='markdown', outputfmt='html5', ext_enabled=None, ext_disabled=None, standalone=True, selfcontained=True, title='Untitled'): ''' Invoke pandoc to do the actual conversion of Markdown to HTML5. ''' if not ext_enabled: ext_enabled = [ 'backtick_code_blocks', 'line_blocks', 'fancy_lists', 'startnum', 'definition_lists', 'example_lists', 'table_captions', 'simple_tables', 'multiline_tables', 'grid_tables', 'pipe_tables', 'all_symbols_escapable', 'intraword_underscores', 'strikeout', 'superscript', 'subscript', 'fenced_divs', 'bracketed_spans', 'footnotes', 'inline_notes', 'emoji', 'tex_math_double_backslash', 'autolink_bare_uris' ] if not ext_disabled: ext_disabled = [ 'tex_math_single_backslash', 'tex_math_dollars', 'smart', 'raw_html' ] enabled = '+'.join(ext_enabled) disabled = '-'.join(ext_disabled) inputfmt = f'{inputfmt}+{enabled}-{disabled}' args = ['--metadata=document-css:false'] if standalone: args.append('--standalone') if selfcontained: args.append('--self-contained') if title: args.append(f'--metadata=title:{title}') return pypandoc.convert_text(mdwn, format=inputfmt, to=outputfmt, extra_args=args) def _apply_styling(html): ''' Inline all styles defined and used into the individual HTML tags. ''' return pynliner.Pynliner().from_string(html).with_cssString(DEFAULT_CSS).run() def _postprocess_html(html): ''' Postprocess the generated and styled HTML. ''' # Preprocessing leaves a sentinel to work around # https://github.com/jgm/pandoc/issues/7398, and so we need to remove it: html = html.replace(' PANDOC_BUG_7398 ', '') return html def convert_markdown_to_html(mdwn): ''' Converts the input Markdown to HTML, handling separately the body, as well as an optional signature. ''' parts = re.split(r'^-- \n', mdwn, 1, flags=re.MULTILINE) body = parts[0] if len(parts) == 2: sig = parts[1] else: sig = None html='' if body: body = _preprocess_markdown(body) body = _identify_quotes_for_later(body) html = _convert_with_pandoc(body, standalone=True, selfcontained=True, title=None) html = _reformat_quotes(html) if sig: sig = _preprocess_signature(sig) sig = _preprocess_markdown(sig) sig = _convert_with_pandoc(sig, standalone=False, selfcontained=False, title=None) sig = SIGNATURE_HTML.format(sig=sig) eob = html.find('