config-perso/machines/kat-son/doc/0001-revert-don-t-parse-md-in-js.patch

148 lines
5.8 KiB
Diff
Raw Normal View History

2024-12-16 13:01:09 +01:00
From 5e5f68209b3b023fce260c9da1625844ca4d3c22 Mon Sep 17 00:00:00 2001
From: catvayor <catvayor@katvayor.net>
Date: Mon, 16 Dec 2024 00:11:47 +0100
Subject: [PATCH 1/2] revert: don't parse md in js
---
static/js/script.js | 106 +-------------------------------------------
1 file changed, 2 insertions(+), 104 deletions(-)
diff --git a/static/js/script.js b/static/js/script.js
index 04234d7..d3ec223 100644
--- a/static/js/script.js
+++ b/static/js/script.js
@@ -27,97 +27,6 @@ function encodeAttr(str) {
return (str+'').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
-/** Parse Markdown into an HTML String. */
-function parseMD(md, prevLinks) {
- let tokenizer = /((?:^|\n+)(?:\n---+|\* \*(?: \*)+)\n)|(?:^``` *(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)/gm,
- context = [],
- out = '',
- links = prevLinks || {},
- last = 0,
- chunk, prev, token, inner, t;
-
- function tag(token) {
- let desc = TAGS[token[1] || ''];
- let end = context[context.length-1] == token;
- if (!desc) return token;
- if (!desc[1]) return desc[0];
- if (end) context.pop();
- else context.push(token);
- return desc[end|0];
- }
-
- function flush() {
- let str = '';
- while (context.length) str += tag(context[context.length-1]);
- return str;
- }
-
- md = md.replace(/^\[(.+?)\]:\s*(.+)$/gm, (s, name, url) => {
- links[name.toLowerCase()] = url;
- return '';
- }).replace(/^\n+|\n+$/g, '');
-
- while ( (token=tokenizer.exec(md)) ) {
- prev = md.substring(last, token.index);
- last = tokenizer.lastIndex;
- chunk = token[0];
- if (prev.match(/[^\\](\\\\)*\\$/)) {
- // escaped
- }
- // Code/Indent blocks:
- else if (t = (token[3] || token[4])) {
- chunk = '<pre class="code '+(token[4]?'poetry':token[2].toLowerCase())+'"><code'+(token[2] ? ` class="language-${token[2].toLowerCase()}"` : '')+'>'+outdent(encodeAttr(t).replace(/^\n+|\n+$/g, ''))+'</code></pre>';
- }
- // > Quotes, -* lists:
- else if (t = token[6]) {
- if (t.match(/\./)) {
- token[5] = token[5].replace(/^\d+/gm, '');
- }
- inner = parse(outdent(token[5].replace(/^\s*[>*+.-]/gm, '')));
- if (t=='>') t = 'blockquote';
- else {
- t = t.match(/\./) ? 'ol' : 'ul';
- inner = inner.replace(/^(.*)(\n|$)/gm, '<li>$1</li>');
- }
- chunk = '<'+t+'>' + inner + '</'+t+'>';
- }
- // Images:
- else if (token[8]) {
- chunk = `<img src="${encodeAttr(token[8])}" alt="${encodeAttr(token[7])}">`;
- }
- // Links:
- else if (token[10]) {
- out = out.replace('<a>', `<a href="${encodeAttr(token[11] || links[prev.toLowerCase()])}">`);
- chunk = flush() + '</a>';
- }
- else if (token[9]) {
- chunk = '<a>';
- }
- // Headings:
- else if (token[12] || token[14]) {
- t = 'h' + (token[14] ? token[14].length : (token[13]>'=' ? 1 : 2));
- chunk = '<'+t+'>' + parse(token[12] || token[15], links) + '</'+t+'>';
- }
- // `code`:
- else if (token[16]) {
- chunk = '<code>'+encodeAttr(token[16])+'</code>';
- }
- // Inline formatting: *em*, **strong** & friends
- else if (token[17] || token[1]) {
- chunk = tag(token[17] || '--');
- }
- out += prev;
- out += chunk;
- }
-
- return (out + md.substring(last) + flush()).replace(/^\n+|\n+$/g, '');
-}
-
-
-/*************************
- * END MARKDOWN PARSER
- */
-
var search, results, allOptions, currentSet = [];
var lastUpdate = "?";
@@ -254,22 +163,11 @@ var updateOptionsTable = function(options) {
-function parseDescription(text){
-
- text = text.replace(/<https(\s*([^>]*))/gi ,'<a href="https$1">&lt;https$1</a>');
- text = text.replace(/\[\]\(#opt-(\s*([^)]*))/gi ,'<strong>$1</strong>').replace(/\)/gi,'');
- //[](#opt-wayland.windowManager.hyprland.plugins)
- text = text.replace(/\{var\}(\s*([^\n]*))/gi ,'<strong>$1</strong>').replace(/`/gi,'')
- text = text.replace(/:::\ \{\.note\}(\s*([^:::]*))/gi ,'<div class="alert alert-info" role="alert">$1</div>').replace(/:::/,'').replace(/\n/g, '<br />')
- return text;
-}
-
var expandOptionMD = function(el){
modalTitle.innerHTML = currentSet[el].title;
- let dhtml = parseMD(currentSet[el].doc);
- var elDesc = "<h5 style='margin:1em 0 0 0'>Description</h5><div>" + dhtml + "</div>";
+ var elDesc = "<h5 style='margin:1em 0 0 0'>Description</h5><div>" + currentSet[el].doc + "</div>";
var elArgs = "<h5 style='margin:1em 0 0 0'>Args</h5><div>" + currentSet[el].args.join(', ') + "</div>";
// var elNote = ( currentSet[el].note == "" ? "": "<h5 style='margin:1em 0 0 0'>Note</h5><div>" + currentSet[el].note + "</div>");
// var elDefault = "<h5 style='margin:1em 0 0 0'>Default</h5><div><pre style='margin-top:0.5em'>" + currentSet[el].default + "</pre></div>";
@@ -290,7 +188,7 @@ var expandOption = function(el){
//console.log(currentSet[el].description.replace(/:::\ \{\.note\}(\s*([^:::]*))/gi ,'<div class="alert alert-info" role="alert">$1</div>').replace(/:::/,''));
- var elDesc = "<h5 style='margin:1em 0 0 0'>Description</h5><div>" + parseDescription(currentSet[el].description) + "</div>";
+ var elDesc = "<h5 style='margin:1em 0 0 0'>Description</h5><div>" + currentSet[el].description + "</div>";
var elType = "<h5 style='margin:1em 0 0 0'>Type</h5><div>" + currentSet[el].type + "</div>";
//var elNote = ( currentSet[el].note == "" ? "": "<h5 style='margin:1em 0 0 0'>Note</h5><div>" + currentSet[el].note + "</div>");
var elDefault = ( currentSet[el].default == "" ? "" : "<h5 style='margin:1em 0 0 0'>Default</h5><div><pre style='margin-top:0.5em'>" + currentSet[el].default + "</pre></div>");
--
2.47.0