tur/markdown/slug
heading ids: python-markdown's toc rule, and GitHub's.
markdown/render-html gives each heading an id when its MdHtmlOpts says to (markdown-library-plan 6.3). Both rules start from the heading as the renderer writes it, with its comments and tags taken out and its character references decoded: a link keeps its text, an image loses its alt text.
- MdSlugPython is the toc extension of python-markdown 3.11, which builds this site's guides. Whitespace runs become one space, NFKD is applied and what is not ASCII dropped, everything but letters, digits, _, - and whitespace is removed, the ends are trimmed, the rest is lower-cased, and each run of - and whitespace becomes one -. A repeated id gets _1, _2 and so on, and an empty one is _1.
- MdSlugGitHub is GitHub's, as github-slugger 2.0 reproduces it. The text is lower-cased, everything but word characters (letters and other Alphabetic characters, combining marks, decimal digits and connector punctuation), - and the space is removed, and each space becomes a -. A repeated id gets -1, -2 and so on.
Since: markdown-library-plan M3
md/-cut-spans
(md/-cut-spans [s0 :String open :cstr close :cstr clen :int] :String)
internal: s with each span from open to the first close at or after it taken out, earliest first, until none is left (python-markdown's strip_tags); a fresh String.
md/-py-space?
(md/-py-space? [c :int] :bool)
internal: is code point c whitespace to Python's str.split: White_Space, or a separator U+001C to U+001F?
md/-collapse-space
(md/-collapse-space [s :String] :String)
internal: s with each run of whitespace one space and none at either end (Python's ' '.join(s.split())); a fresh String.
md/-decode-refs
(md/-decode-refs [s :String] :String)
internal: s with its character references decoded (Python's html.unescape, for what the renderer writes); a fresh String.
md/-heading-plain
(md/-heading-plain [html :String collapse :bool] :String)
internal: a heading's HTML as text: comments, then tags, taken out, whitespace runs collapsed when collapse is true, and references decoded; a fresh String.
md/-py-ascii-space?
(md/-py-ascii-space? [c :int] :bool)
internal: is ASCII byte c whitespace to Python's \s and strip?
md/-py-keep?
(md/-py-keep? [c :int] :bool)
internal: does ASCII byte c survive the removal of [^\w\s-]: a letter, a digit, _, - or whitespace?
md/-py-tidy
(md/-py-tidy [s :String] :String)
internal: the end of slugify: ASCII s with whitespace stripped from its ends, lower-cased, and each run of - and whitespace one -; a fresh String.
md/-slug-python
(md/-slug-python [text :String] :String)
internal: python-markdown's slugify(text, "-"); a fresh String.
md/-id-index
(md/-id-index [ids :(Vec String) s :String] :int)
internal: the index of s in ids, or -1.
md/-id-count-at
(md/-id-count-at [s :String] :int)
internal: the index of the _ that starts the _digits s ends in, or -1 (python-markdown's IDCOUNT_RE).
md/-push-incremented!
(md/-push-incremented! [b :StringBuilder s :String a0 :int z :int] :void)
internal: append the decimal number in bytes [a, z) of s plus one, without leading zeros, as Python's int(...) + 1 writes it.
md/-next-python-id
(md/-next-python-id [s :String] :String)
internal: python-markdown's next candidate after id s: its _N count plus one, or s with _1 added; a fresh String.
md/-add-python-id!
(md/-add-python-id! [ids :(Vec String) id0 :String] :void)
internal: python-markdown's unique(id, ids): push id onto ids, or the first next candidate ids does not hold, when id is empty or taken. Takes id.
md/-gh-connector?
(md/-gh-connector? [c :int] :bool)
internal: is c connector punctuation (Pc): _ and the eight others?
md/-gh-keep?
(md/-gh-keep? [c :int] :bool)
internal: does code point c stay in a GitHub id: a word character (Alphabetic, a combining mark, a decimal digit or connector punctuation), a - or a space?
md/-slug-github
(md/-slug-github [text :String] :String)
internal: github-slugger's slug of text: lower case, what md/-gh-keep? refuses removed, and each space a -; a fresh String.
md/-github-candidate!
(md/-github-candidate! [counts :(Vec int) o :int slug :String] :String)
internal: slug-N for the next count N of the slug at o in counts, which goes up by one; a fresh String.
md/-add-github-id!
(md/-add-github-id! [ids :(Vec String) counts :(Vec int) slug :String] :void)
internal: github-slugger's occurrence count: push slug onto ids, or slug-N for the next count of slug that ids does not hold, with a 0 count onto counts. Takes slug.