Function: markdown-ts--slug-pandoc

markdown-ts--slug-pandoc is a byte-compiled function defined in markdown-ts-mode.el.gz.

Signature

(markdown-ts--slug-pandoc TEXT)

Documentation

Return the Pandoc-flavor auto-id slug for heading TEXT.

Mirrors Pandoc's algorithm: drop everything before the first letter, keep alphanumerics and _-., collapse whitespace runs to hyphens, lowercase. Falls back to "section" if empty.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode.el.gz
(defun markdown-ts--slug-pandoc (text)
  "Return the Pandoc-flavor auto-id slug for heading TEXT.
Mirrors Pandoc's algorithm: drop everything before the first
letter, keep alphanumerics and `_-.', collapse whitespace runs to
hyphens, lowercase.  Falls back to \"section\" if empty."
  (let* ((lc (downcase text))
         (from-letter (if (string-match "[[:alpha:]]" lc)
                          (substring lc (match-beginning 0))
                        ""))
         (kept (replace-regexp-in-string
                "[^[:alnum:]_.\n\t[:blank:]-]" "" from-letter))
         (hyphenated (replace-regexp-in-string "[[:blank:]\t\n]+" "-" kept))
         (trimmed (replace-regexp-in-string "-+\\'" "" hyphenated)))
    (if (string-empty-p trimmed) "section" trimmed)))