Coverage for onnxcustom/utils/doc_helper.py: 74%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2@file
3@brief Helpers to improve documentation rendering.
4"""
5import re
8def fix_link_operator_md(markdown):
9 """
10 The redering of file `Operator.md <https://github.com/onnx/onnx/
11 blob/master/docs/Operators.md>`_ breaks links. This function
12 restores some of them.
14 :param markdown: a string or a filename
15 :return: modified content
16 """
17 if len(markdown) < 5000 and markdown.endswith('.md'):
18 with open(markdown, 'r', encoding='utf-8') as f:
19 content = f.read()
20 else:
21 content = markdown # pragma: no cover
23 reg = re.compile(
24 "([|]<a href=\\\"#(?P<name>[.A-Za-z]+)\\\">(?P=name)</a>[|])")
25 pattern = "|[{1}](#a-name-{0}-a-a-name-{0}-{0}-a)|"
27 lines = content.split('\n')
28 new_lines = []
29 for line in lines:
30 find = reg.search(line)
31 if find:
32 gr = find.groups()
33 exp = gr[0]
34 op = gr[1]
35 rep = pattern.format(op.lower(), op).replace(".", "-")
36 line = line.replace(exp, rep)
37 new_lines.append(line)
38 return "\n".join(new_lines)