1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 16:33:00 +00:00

Add initial external diagram renderer support, but we are missing the backend.

This commit is contained in:
Starbeamrainbowlabs 2019-10-20 20:54:50 +01:00
parent 9249903d59
commit ca6546677b
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 45 additions and 2 deletions

View file

@ -337,7 +337,7 @@
"version": "0.10", "version": "0.10",
"author": "Emanuil Rusev & Starbeamrainbowlabs", "author": "Emanuil Rusev & Starbeamrainbowlabs",
"description": "An upgraded (now default!) parser based on Emanuil Rusev's Parsedown Extra PHP library (https:\/\/github.com\/erusev\/parsedown-extra), which is licensed MIT. Please be careful, as this module adds some weight to your installation.", "description": "An upgraded (now default!) parser based on Emanuil Rusev's Parsedown Extra PHP library (https:\/\/github.com\/erusev\/parsedown-extra), which is licensed MIT. Please be careful, as this module adds some weight to your installation.",
"lastupdate": 1571590586, "lastupdate": 1571601235,
"optional": false, "optional": false,
"extra_data": { "extra_data": {
"Parsedown.php": "https:\/\/raw.githubusercontent.com\/erusev\/parsedown\/fe7a50eceb4a3c867cc9fa9c0aa906b1067d1955\/Parsedown.php", "Parsedown.php": "https:\/\/raw.githubusercontent.com\/erusev\/parsedown\/fe7a50eceb4a3c867cc9fa9c0aa906b1067d1955\/Parsedown.php",

View file

@ -799,8 +799,25 @@ class PeppermintParsedown extends ParsedownExtreme
} }
protected function blockFencedCodeComplete($block) { protected function blockFencedCodeComplete($block) {
global $settings;
$result = parent::blockFencedCodeComplete($block); $result = parent::blockFencedCodeComplete($block);
error_log("[code block] " . var_export($block, true));
$language = preg_replace("/^language-/", "", $block["element"]["element"]["attributes"]["class"]);
if(!isset($settings->parser_ext_renderers->$language))
return $result;
$text = $result["element"]["element"]["text"];
$renderer = $settings->parser_ext_renderers->$language;
$result["element"] = [
"name" => "img",
"attributes" => [
"alt" => "Diagram rendered by {$renderer->name}",
"src" => "?action=parsedown-render-ext&language=$language&source=".rawurlencode($text)
]
];
return $result; return $result;
} }

View file

@ -21,6 +21,32 @@
"parser": { "type": "text", "description": "The parser to use when rendering pages. Defaults to an extended version of parsedown (http://parsedown.org/)", "default": "parsedown" }, "parser": { "type": "text", "description": "The parser to use when rendering pages. Defaults to an extended version of parsedown (http://parsedown.org/)", "default": "parsedown" },
"parser_cache": { "type": "checkbox", "description": "Whether parser output should be cached to speed things up. The cache directory is <code>._cache</code> in the data directory - delete it if you experience issues (unlikely).", "default": true }, "parser_cache": { "type": "checkbox", "description": "Whether parser output should be cached to speed things up. The cache directory is <code>._cache</code> in the data directory - delete it if you experience issues (unlikely).", "default": true },
"parser_cache_min_size": { "type": "number", "description": "The minimum size a source string must be (in bytes) before it's considered eligible for caching.", "default": 1024 }, "parser_cache_min_size": { "type": "number", "description": "The minimum size a source string must be (in bytes) before it's considered eligible for caching.", "default": 1024 },
"parser_ext_renderers": { "type": "parserext", "description": "Used by the parsedown parser as an object mapping fenced code block languages to their respective external renderers. Should be in the form <code>language_code</code> → <code>external renderer definition</code>. See the default for examples on how to define an external renderer.", "default": {
"nomnoml": {
"name": "nomnoml",
"description": "The nomnoml UML diagram renderer. Requires the nomnoml-cli npm package to be globally installed.",
"url": "http://nomnoml.com/",
"cli": "nomnoml --format svg",
"cli_mode": "pipe",
"output_format": "image/svg+xml"
},
"plantuml": {
"name": "PlantUML",
"description": "The PlantUML diagram renderer. Supports many different diagram types. Requires plantuml to be installed.",
"url": "http://plantuml.com/",
"cli": "plantuml -tsvg -pipe",
"cli_mode": "pipe",
"output_format": "image/svg+xml"
},
"lilypond": {
"name": "LilyPond",
"description": "A music notation typesetter. Requires lilypond to be installed.",
"url": "http://lilypond.org/manuals.html",
"cli": "lilypond --png --output {output_file} {input_file}",
"cli_mode": "file",
"output_format": "image/png"
}
} },
"interwiki_index_location": { "type": "text", "description": "The location to find the interwiki wiki definition file, which contains a list of wikis along with their names, prefixes, and root urls. May be a URL, or simply a file path - as it's passed to file_get_contents(). If left blank, interwiki link parsing is disabled.", "default": null }, "interwiki_index_location": { "type": "text", "description": "The location to find the interwiki wiki definition file, which contains a list of wikis along with their names, prefixes, and root urls. May be a URL, or simply a file path - as it's passed to file_get_contents(). If left blank, interwiki link parsing is disabled.", "default": null },
"clean_raw_html": { "type": "checkbox", "description": "Whether page sources should be cleaned of HTML before rendering. It is STRONGLY recommended that you keep this option turned on.", "default": true }, "clean_raw_html": { "type": "checkbox", "description": "Whether page sources should be cleaned of HTML before rendering. It is STRONGLY recommended that you keep this option turned on.", "default": true },
"all_untrusted": { "type": "checkbox", "description": "Whether to treat both page sources and comment text as untrusted input. Untrusted input has additional restrictions to protect against XSS attacks etc. Turn on if your wiki allows anonymous edits.", "default": false}, "all_untrusted": { "type": "checkbox", "description": "Whether to treat both page sources and comment text as untrusted input. Untrusted input has additional restrictions to protect against XSS attacks etc. Turn on if your wiki allows anonymous edits.", "default": false},