Text in, a tree out. Code is its tokens with structure over them: enough to colour, outline, fold and find things in 36 languages. Markdown is a whole document.
syntax.parseA node is {kind, value, from, to, text, children}. Over the tokens: a declaration (what, name), a call (name), a block, and a group for what is inside other brackets.
Edit it: the tree, the tokens and the outline below follow. from and to count characters as the page's text does.
…
Press a row to see the text it covers; a row with children folds.
The leaves
The same text as a flat run of tokens: what colouring wants.
syntax.tokensThe leaves in order as {kind, text}. What lies between them has kind "": joined, they are the text again.
Reading…
Show what lies betweenspaces as ·, line ends as ↵
0 tokens
reading…
syntax.linesThe same tokens, a list for each line: a for inside a for draws the code.
Reading…
0 lines; the small number at the end of each is how many tokens it holds. Highlight and the editor are drawn from this call.
Structure
An outline of declarationsWalk the tree for kind "declaration": each has what it is and its name. Bodies nest, by braces or by how far lines are set in.
Reading…
0 declarations in the js above. Pick another language at the top to see its own.
A language it does not knowThe call fails, and says so: a resource then has its else, or failure().
Languagetry js, or anything
syntax.tokens("let x = 1", …)
Reading…
Highlight shows such code plain instead of failing.
"markdown" is a documentheading (level), paragraph, list (ordered), item (checked), code (lang, code), quote, rule, table with row and cell, and inside them emphasis, strong, strike, codespan, link (url), image, text.