vscode-plantuml
vscode-plantuml copied to clipboard
Support curly braces for code fence language specifier in Markdown
Description
To render plantuml in Markdown Preview Enhanced, I need to write the following syntax:
```plantuml
@startuml
Please support the language specifier Syntax with curly braces as well: {plantuml}
Or even better: Make this a config option.
Use Case:
Language specifier with curly braces are parsed as a directive in Sphinx-doc using the MyST Markdown parser. The directive is then parsed by sphinxcontrib.plantuml, which renders the diagram. Language specifier without curly braces just generates a code block with marked-up text, as per Markdown specification.
I therefore would use the language specifier syntax with curly braces, which MyST translates into a reStructuredText directive.
Example:
```{plantuml}
@startuml
ℹ️ Actually, sphinxcontrib.plantuml expects the directive name "uml", but it's easy to add an alias "plantuml" for the directive.
@arwedus did you find a workaround for this?
@Geocali : I don't think there is a workaround for this.
In src/markdown-it-plantuml/rule.ts
import * as markdowIt from 'markdown-it';
export function plantumlWorker(state: any) {
// debugInfo(state.tokens);
let blockTokens: markdowIt.Token[] = state.tokens;
for (let blockToken of blockTokens) {
if (blockToken.type == "fence" &&( blockToken.info.startsWith("plantuml")|| blockToken.info.startsWith("puml"))) {
blockToken.type = "plantuml";
// always render as <img> for maximum compatibility:
// https://github.com/qjebbs/vscode-markdown-extended/issues/67#issuecomment-554996262
blockToken.tag = "img";
// if (state.env && state.env.htmlExporter) { // work with markdown extended export, solve #253
// blockToken.tag = "object";
// } else {
// blockToken.tag = "img";
// }
}
}
}
We could probably replace
(blockToken.type == "fence" &&( blockToken.info.startsWith("plantuml")|| blockToken.info.startsWith("puml")))
by
(blockToken.type == "fence" &&( blockToken.info.startsWith("plantuml")|| blockToken.info.startsWith("puml"))) || blockToken.info.startsWith("{uml}")||