4 ms·
When adding languages you define a function/regex to match the start and end positions of each language block. Polymode then scans the document, and runs the ma
by accoil 4y ago
When adding languages you define a function/regex to match the start and end positions of each language block. Polymode then scans the document, and runs the matchers.
e.g this matches markdown code blocks (and also extracts the language from the start to select the mode to run)
(define-auto-innermode poly-markdown-fenced-code-innermode
:head-matcher (cons "^[ \t]*\\(```{?[[:alpha:]].*\n\\)" 1)
:tail-matcher (cons "^[ \t]*\\(```\\)[ \t]*$" 1)
:mode-matcher (cons "```[ \t]*{?\\(?:lang *= *\\)?\\([^ \t\n;=,}]+\\)" 1)
:head-mode 'host
:tail-mode 'host)
( via https://polymode.github.io/defining-polymodes/ https://polymode.github.io/defining-polymodes/ )