diff --git a/src/helper/merge-html-plugin.ts b/src/helper/merge-html-plugin.ts
index 96eb5ce..3ca2fe3 100644
--- a/src/helper/merge-html-plugin.ts
+++ b/src/helper/merge-html-plugin.ts
@@ -19,14 +19,10 @@ export const mergeHTMLPlugin = (function () {
.replace(/'/g, ''');
}
- /* plugin itself */
-
const mergeHTMLPlugin: HLJSPlugin = {
- // preserve the original HTML token stream
'before:highlightElement': ({ el }: {el: Node}) => {
originalStream = nodeStream(el);
},
- // merge it afterwards with the highlighted token stream
'after:highlightElement': ({ el, result, text }: {el: Element; result: HighlightResult; text: string}) => {
if (originalStream.length === 0) return;
@@ -37,8 +33,6 @@ export const mergeHTMLPlugin = (function () {
}
};
- /* Stream merging support functions */
-
interface Event {
event: 'start' | 'stop';
offset: number;
@@ -62,9 +56,6 @@ export const mergeHTMLPlugin = (function () {
node: child
});
offset = _nodeStream(child, offset);
- // Prevent void elements from having an end tag that would actually
- // double them in the output. There are more void elements in HTML
- // but we list only those realistically expected in code display.
if (tag(child).match(/br|hr|img|input/) == null) {
result.push({
event: 'stop',
@@ -92,27 +83,9 @@ export const mergeHTMLPlugin = (function () {
return (original[0].offset < highlighted[0].offset) ? original : highlighted;
}
- /*
- To avoid starting the stream just before it should stop the order is
- ensured that original always starts first and closes last:
-
- if (event1 == 'start' && event2 == 'start')
- return original;
- if (event1 == 'start' && event2 == 'stop')
- return highlighted;
- if (event1 == 'stop' && event2 == 'start')
- return original;
- if (event1 == 'stop' && event2 == 'stop')
- return highlighted;
-
- ... which is collapsed to:
- */
return highlighted[0].event === 'start' ? original : highlighted;
}
- /**
- * @param {Node} node
- */
function open (node: Node): void {
function attributeString (attr: Attr): string {
return ' ' + attr.nodeName + '="' + escapeHTML(attr.value) + '"';
@@ -134,12 +107,6 @@ export const mergeHTMLPlugin = (function () {
result += escapeHTML(value.substring(processed, stream[0].offset));
processed = stream[0].offset;
if (stream === original) {
- /*
- On any opening or closing tag of the original markup we first close
- the entire highlighted node stack, then render the original tag along
- with all the following original tags at the same offset and then
- reopen all the tags on the highlighted stack.
- */
nodeStack.reverse().forEach(close);
do {
render(stream.splice(0, 1)[0]);