Repository navigation
VS Code: highlight every fence and py-doc construct, fold blocks, add snippets - #221
Merged
Merged
Conversation
… snippets - Fences: every diagram fence and poster block py-doc draws is highlighted in its language. Mermaid, Graphviz (and the blockdiag family) and PlantUML have grammars of the extension's own; Vega, WaveDrom, WireViz and bytefield use VS Code's JSON, JavaScript, YAML and Clojure; poster blocks, plot and the written-form fences have one grammar for their key: lines, key=value options, cells, icons and numbers. Fence-line attributes are highlighted too. - Markdown: rich tables cell by cell (<br>, list items, < and ^ merges, cell styles, [[BLOCK:]]), callouts, fenced divs and pandoc attribute blocks, beside the directives and variables. - Folding for conditions, blocks, landscape sections, rich tables and fenced divs; snippets for the common constructs. - Tests tokenize with vscode-textmate and Oniguruma, VS Code's own engine; CI also runs them against VS Code 1.105's Markdown grammar. A Python test keeps the fence grammar in step with py-doc's fences. - The extension README is a full guide; version 2.3.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WHtcxeRPPmXcydfxoEHGJ4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The VS Code extension (2.3.0) now helps while writing py-doc Markdown, not only with the live preview.
Highlighting
Every fence py-doc draws is highlighted in its own language. A Python test checks the list against py-doc's renderers and poster blocks, so a new fence can't be missed.
mermaid%%commentsdot,graphvizand the blockdiag familyplantuml,puml@startuml, element keywords, arrows, stereotypes, colours,'commentsvega,vega-lite,wavedrom,wireviz,bytefield-svgplot,circuit,chess,music/abc,pikchr,railroadand the science fenceskey:lines,key=valueoptions,a | bcells, icons, numbers with units, colours, commentsAttributes on the fence line, such as
width="100%", are highlighted too. The extension's grammars use their own scope names, so they don't clash with dedicated Mermaid, Graphviz or PlantUML extensions.py-doc constructs in Markdown, beside the directives and
{{variables}}added in Rich table cells: [[LISTTABLE]] with lists, header rows, merged cells and diagrams #219:[[LISTTABLE]]rows cell by cell:<br>,-and1.items,<and^merges,{bg=… valign=…}and[[BLOCK:]]slots, with ordinary Markdown inside the cells.> [!NOTE],> **Warning:**).::: {.pagebreak},:::: columns).Code blocks and inline code are left as code.
Folding and snippets
[[IF:]]/[[NOT:]]to[[ENDIF]](nested too),[[BLOCK:]]to[[ENDBLOCK]],[[LANDSCAPE]]to[[PORTRAIT]], a[[LISTTABLE]]with its rows, and:::fenced divs. It comes fromsrc/folding.jsthrough a folding range provider, beside VS Code's own folding of headings.listtable,block,cellstyle, the five callouts, captions,include,if/not,pagebreak,landscape,style,var,mermaid/dot/plantuml,chart/cards,notes/columns.Instructions
The extension README is now a full guide:
.vsix, by command or from the Extensions view, and updating and removing itThe user guide's VS Code section and the root README mention the new features. CHANGELOG 2.3.0.
Testing
test/highlight.test.jstokenizes py-doc Markdown withvscode-textmateandvscode-oniguruma, the engine VS Code uses (new dev-only dependencies). That caught two real problems: a capture-pattern loop, and arrow patterns matching single hyphens.PYDOC_MARKDOWN_GRAMMARset to the real grammar, they also check that py-doc syntax in code blocks stays plain.vscodejob fetches VS Code 1.105.0's Markdown grammar, checks its SHA-256, and runs the highlighting tests against it.test/folding.test.js,test/snippets.test.js, andtests/test_editor_grammar.pyin Python.npm run lint && npm test: 31 passed, plus the real-grammar test run locally against 1.105.0.python -m pytest: 1996 passed.ruff check .andruff format --check .are clean.py-doc lint docs --strictis clean with Vale.npx @vscode/vsce packagebuilds a 69-file.vsixwith the grammars, snippets and folding, without the dev dependencies.I haven't tried it in a running VS Code window. The token tests use VS Code's own engine and Markdown grammar, but how the colours look depends on your theme.
Generated by Claude Code