Skip to content

Commit

Permalink
chore: removed unnecessary comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Jurredr committed Dec 24, 2024
1 parent bbc08c0 commit 1ef3324
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions src/helper/merge-html-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -37,8 +33,6 @@ export const mergeHTMLPlugin = (function () {
}
};

/* Stream merging support functions */

interface Event {
event: 'start' | 'stop';
offset: number;
Expand All @@ -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',
Expand Down Expand Up @@ -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) + '"';
Expand All @@ -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]);
Expand Down

0 comments on commit 1ef3324

Please sign in to comment.