mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-26 10:00:34 +00:00
4f42df8bef
* Rename v9 highlight.js plugin to highlight-legacy * Add ES6 version of highlight.js plugin * highlightblock.js - ensure this ES6 plugin will not cause error on legacy browsers - update the code to use new highlight.js APIs - change class tagging to match more closely with highlight.js - allow users to add language definitions as JS "highlight" modules * styles.tid - update to match v11 * howto.tid - add instructions on how to add language definitions as JS modules * highlight.min.js, default.min.css - version 11.4.0 common languages only * Remove extraneous whitespaces * Update readme.tid * Update bundled languages bundled: common + apache + nginx + latex + dockerfile + fortran * Update highlight-legacy subtiddlers' titles * Touch up highlight-legacy docs * Touch up highlight plugin docs * Fix pre block styling - add "hljs" class to <pre> so the element can be styled
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
/*\
|
|
title: $:/plugins/tiddlywiki/highlight/highlightblock.js
|
|
type: application/javascript
|
|
module-type: widget
|
|
|
|
Wraps up the fenced code blocks parser for highlight and use in TiddlyWiki5
|
|
|
|
\*/
|
|
(function() {
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
var TYPE_MAPPINGS_BASE = "$:/config/HighlightPlugin/TypeMappings/";
|
|
|
|
var CodeBlockWidget = require("$:/core/modules/widgets/codeblock.js").codeblock;
|
|
|
|
var hljs = require("$:/plugins/tiddlywiki/highlight/highlight.js");
|
|
|
|
if(hljs.getLanguage !== undefined) {
|
|
// load language definitions
|
|
$tw.utils.each($tw.modules.types["highlight"],function(moduleInfo,moduleName) {
|
|
$tw.utils.evalSandboxed(moduleInfo.definition,{hljs:hljs, exports:{}},moduleName);
|
|
});
|
|
|
|
CodeBlockWidget.prototype.postRender = function() {
|
|
var domNode = this.domNodes[0],
|
|
language = this.language,
|
|
tiddler = this.wiki.getTiddler(TYPE_MAPPINGS_BASE + language);
|
|
if(tiddler) {
|
|
language = tiddler.fields.text || "";
|
|
}
|
|
if(language && hljs.getLanguage(language)) {
|
|
domNode.className = "hljs";
|
|
domNode.children[0].className = language.toLowerCase() + " hljs";
|
|
if($tw.browser && !domNode.isTiddlyWikiFakeDom) {
|
|
hljs.highlightElement(domNode.children[0]);
|
|
} else {
|
|
var text = domNode.textContent;
|
|
domNode.children[0].innerHTML = hljs.highlight(text,{language: language, ignoreIllegals: true}).value;
|
|
// If we're using the fakedom then specially save the original raw text
|
|
if(domNode.isTiddlyWikiFakeDom) {
|
|
domNode.children[0].textInnerHTML = text;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
})();
|