Hacker News new | past | comments | ask | show | jobs | submit login

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/ )



Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: