File: utils.py

package info (click to toggle)
meshroom 2025.1.1-1
  • links: PTS, VCS
  • area: contrib
  • in suites: sid
  • size: 5,196 kB
  • sloc: python: 14,951; javascript: 105; sh: 103; modula3: 53; makefile: 28
file content (25 lines) | stat: -rw-r--r-- 678 bytes parent folder | download
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