1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
# Utility functions for custom Sphinx extensions
from myst_parser.docutils_ import Parser
from myst_parser.mdit_to_docutils.base import make_document
# Given a string written in markdown
# parse its content
# and return the corresponding docutils document
def md_to_docutils(text):
parser = Parser()
doc = make_document(parser_cls=Parser)
parser.parse(text, doc)
return doc
# Given a docutils node
# find an attribute that corresponds to a link (if it exists)
# and return its key
def get_link_key(node):
link_keys = ['uri', 'refuri', 'refname']
for key in link_keys:
if key in node.attributes.keys():
return key
return None
|