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)
| 73 | return result_top + result_bottom |
| 74 | |
| 75 | def 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 | |
| 109 | def tagAndCollect(lines, id_tag=True, back_links=False, exclude_h=None): |
| 110 | """ |