1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-22 13:52:54 +00:00

Websocket refactoring (#190)

Websocket refactoring
This commit is contained in:
Jan Korf
2024-02-24 19:21:47 +01:00
committed by GitHub
parent d91755dff5
commit d533557324
585 changed files with 114831 additions and 2198 deletions
+46
View File
@@ -0,0 +1,46 @@
import { escapeHTML } from './utils';
const SPAN_CLOSE = '</span>';
const emitsWrappingTags = (node) => {
return !!node.kind;
};
export default class HTMLRenderer {
constructor(tree, options) {
this.buffer = "";
this.classPrefix = options.classPrefix;
tree.walk(this);
}
// renderer API
addText(text) {
this.buffer += escapeHTML(text);
}
openNode(node) {
if (!emitsWrappingTags(node)) return;
let className = node.kind;
if (!node.sublanguage) {
className = `${this.classPrefix}${className}`;
}
this.span(className);
}
closeNode(node) {
if (!emitsWrappingTags(node)) return;
this.buffer += SPAN_CLOSE;
}
// helpers
span(className) {
this.buffer += `<span class="${className}">`;
}
value() {
return this.buffer;
}
}