3 ms·
How does the language detection work?
by KRAKRISMOTT 4y ago
How does the language detection work?
- accoil 4y agoWhen 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/ )