MCPcopy Create free account
hub / github.com/catchorg/Catch2 / dashifyHeadline

Function dashifyHeadline

tools/scripts/updateDocumentToC.py:75–107  ·  view source on GitHub ↗

Takes a header line from a Markdown document and returns a tuple of the '#'-stripped version of the head line, a string version for anchor tags, and the level of the headline as integer. E.g., >>> dashifyHeadline('### some header lvl3') ('So

(line)

Source from the content-addressed store, hash-verified

73 return result_top + result_bottom
74
75def dashifyHeadline(line):
76 """
77 Takes a header line from a Markdown document and
78 returns a tuple of the
79 '#'-stripped version of the head line,
80 a string version for <a id=''></a> anchor tags,
81 and the level of the headline as integer.
82 E.g.,
83 >>> dashifyHeadline('### some header lvl3')
84 ('Some header lvl3', 'some-header-lvl3', 3)
85
86 """
87 stripped_right = line.rstrip('#')
88 stripped_both = stripped_right.lstrip('#')
89 level = len(stripped_right) - len(stripped_both)
90 stripped_wspace = stripped_both.strip()
91
92 # GitHub's sluggification works in an interesting way
93 # 1) '+', '/', '(', ')' and so on are just removed
94 # 2) spaces are converted into '-' directly
95 # 3) multiple -- are not collapsed
96
97 dashified = ''
98 for c in stripped_wspace:
99 if c in VALIDS:
100 dashified += c.lower()
101 elif c.isspace():
102 dashified += '-'
103 else:
104 # Unknown symbols are just removed
105 continue
106
107 return [stripped_wspace, dashified, level]
108
109def tagAndCollect(lines, id_tag=True, back_links=False, exclude_h=None):
110 """

Callers 1

tagAndCollectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected