mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-18 21:20:39 +01:00
unvendor: Replace showdown
This commit is contained in:
parent
8b8f2f1144
commit
7b0f7306c0
@ -53,7 +53,6 @@ module.exports = {
|
|||||||
droll: 'readonly',
|
droll: 'readonly',
|
||||||
moment: 'readonly',
|
moment: 'readonly',
|
||||||
Popper: 'readonly',
|
Popper: 'readonly',
|
||||||
showdown: 'readonly',
|
|
||||||
showdownKatex: 'readonly',
|
showdownKatex: 'readonly',
|
||||||
toastr: 'readonly',
|
toastr: 'readonly',
|
||||||
isProbablyReaderable: 'readonly',
|
isProbablyReaderable: 'readonly',
|
||||||
|
26
package-lock.json
generated
26
package-lock.json
generated
@ -56,6 +56,7 @@
|
|||||||
"rate-limiter-flexible": "^5.0.0",
|
"rate-limiter-flexible": "^5.0.0",
|
||||||
"response-time": "^2.3.2",
|
"response-time": "^2.3.2",
|
||||||
"sanitize-filename": "^1.6.3",
|
"sanitize-filename": "^1.6.3",
|
||||||
|
"showdown": "^2.1.0",
|
||||||
"sillytavern-transformers": "2.14.6",
|
"sillytavern-transformers": "2.14.6",
|
||||||
"simple-git": "^3.19.1",
|
"simple-git": "^3.19.1",
|
||||||
"tiktoken": "^1.0.16",
|
"tiktoken": "^1.0.16",
|
||||||
@ -7137,6 +7138,31 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/showdown": {
|
||||||
|
"version": "2.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/showdown/-/showdown-2.1.0.tgz",
|
||||||
|
"integrity": "sha512-/6NVYu4U819R2pUIk79n67SYgJHWCce0a5xTP979WbNp0FL9MN1I1QK662IDU1b6JzKTvmhgI7T7JYIxBi3kMQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"commander": "^9.0.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"showdown": "bin/showdown.js"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "individual",
|
||||||
|
"url": "https://www.paypal.me/tiviesantos"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/showdown/node_modules/commander": {
|
||||||
|
"version": "9.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz",
|
||||||
|
"integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": "^12.20.0 || >=14"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/side-channel": {
|
"node_modules/side-channel": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz",
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
"rate-limiter-flexible": "^5.0.0",
|
"rate-limiter-flexible": "^5.0.0",
|
||||||
"response-time": "^2.3.2",
|
"response-time": "^2.3.2",
|
||||||
"sanitize-filename": "^1.6.3",
|
"sanitize-filename": "^1.6.3",
|
||||||
|
"showdown": "^2.1.0",
|
||||||
"sillytavern-transformers": "2.14.6",
|
"sillytavern-transformers": "2.14.6",
|
||||||
"simple-git": "^3.19.1",
|
"simple-git": "^3.19.1",
|
||||||
"tiktoken": "^1.0.16",
|
"tiktoken": "^1.0.16",
|
||||||
|
1
public/global.d.ts
vendored
1
public/global.d.ts
vendored
@ -1,7 +1,6 @@
|
|||||||
// Global namespace modules
|
// Global namespace modules
|
||||||
declare var droll;
|
declare var droll;
|
||||||
declare var Popper;
|
declare var Popper;
|
||||||
declare var showdown;
|
|
||||||
declare var showdownKatex;
|
declare var showdownKatex;
|
||||||
declare var ai;
|
declare var ai;
|
||||||
|
|
||||||
|
@ -6745,8 +6745,6 @@
|
|||||||
<script src="lib/jquery.transit.min.js"></script>
|
<script src="lib/jquery.transit.min.js"></script>
|
||||||
<script src="lib/jquery-cookie-1.4.1.min.js"></script>
|
<script src="lib/jquery-cookie-1.4.1.min.js"></script>
|
||||||
<script src="lib/jquery.ui.touch-punch.min.js"></script>
|
<script src="lib/jquery.ui.touch-punch.min.js"></script>
|
||||||
<script src="lib/showdown.min.js"></script>
|
|
||||||
<script src="lib/showdown-patch.js"></script>
|
|
||||||
<script src="lib/showdown-katex.min.js"></script>
|
<script src="lib/showdown-katex.min.js"></script>
|
||||||
<script src="lib/popper.js"></script>
|
<script src="lib/popper.js"></script>
|
||||||
<script src="lib/moment-with-locales.min.js"></script>
|
<script src="lib/moment-with-locales.min.js"></script>
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
"typeAcquisition": {
|
"typeAcquisition": {
|
||||||
"include": [
|
"include": [
|
||||||
"@popperjs/core",
|
"@popperjs/core",
|
||||||
"showdown",
|
|
||||||
"seedrandom",
|
"seedrandom",
|
||||||
"showdown-katex",
|
"showdown-katex",
|
||||||
"droll"
|
"droll"
|
||||||
|
@ -15,6 +15,7 @@ import * as pdfjsLib from 'pdfjs-dist/webpack.mjs';
|
|||||||
import DiffMatchPatch from 'diff-match-patch';
|
import DiffMatchPatch from 'diff-match-patch';
|
||||||
import { isProbablyReaderable, Readability } from '@mozilla/readability';
|
import { isProbablyReaderable, Readability } from '@mozilla/readability';
|
||||||
import SVGInject from '@iconfu/svg-inject';
|
import SVGInject from '@iconfu/svg-inject';
|
||||||
|
import showdown from 'showdown';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expose the libraries to the 'window' object.
|
* Expose the libraries to the 'window' object.
|
||||||
@ -53,6 +54,10 @@ export function initLibraryShims() {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
window.SVGInject = SVGInject;
|
window.SVGInject = SVGInject;
|
||||||
}
|
}
|
||||||
|
if (!('showdown' in window)) {
|
||||||
|
// @ts-ignore
|
||||||
|
window.showdown = showdown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -70,6 +75,7 @@ export default {
|
|||||||
Readability,
|
Readability,
|
||||||
isProbablyReaderable,
|
isProbablyReaderable,
|
||||||
SVGInject,
|
SVGInject,
|
||||||
|
showdown,
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@ -87,4 +93,5 @@ export {
|
|||||||
Readability,
|
Readability,
|
||||||
isProbablyReaderable,
|
isProbablyReaderable,
|
||||||
SVGInject,
|
SVGInject,
|
||||||
|
showdown,
|
||||||
};
|
};
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
showdown.subParser('unhashHTMLSpans', function (text, options, globals) {
|
|
||||||
'use strict';
|
|
||||||
text = globals.converter._dispatch('unhashHTMLSpans.before', text, options, globals);
|
|
||||||
|
|
||||||
for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
|
|
||||||
var repText = globals.gHtmlSpans[i],
|
|
||||||
// limiter to prevent infinite loop (assume 10 as limit for recurse)
|
|
||||||
limit = 0;
|
|
||||||
|
|
||||||
while (/¨C(\d+)C/.test(repText)) {
|
|
||||||
var num = RegExp.$1;
|
|
||||||
repText = repText.replace('¨C' + num + 'C', globals.gHtmlSpans[num]);
|
|
||||||
if (limit === 10000) {
|
|
||||||
console.error('maximum nesting of 10000 spans reached!!!');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
++limit;
|
|
||||||
}
|
|
||||||
text = text.replace('¨C' + i + 'C', repText);
|
|
||||||
}
|
|
||||||
|
|
||||||
text = globals.converter._dispatch('unhashHTMLSpans.after', text, options, globals);
|
|
||||||
return text;
|
|
||||||
});
|
|
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
showdown,
|
||||||
Fuse,
|
Fuse,
|
||||||
DOMPurify,
|
DOMPurify,
|
||||||
hljs,
|
hljs,
|
||||||
@ -259,6 +260,7 @@ import { AbortReason } from './scripts/util/AbortReason.js';
|
|||||||
import { initSystemPrompts } from './scripts/sysprompt.js';
|
import { initSystemPrompts } from './scripts/sysprompt.js';
|
||||||
import { registerExtensionSlashCommands as initExtensionSlashCommands } from './scripts/extensions-slashcommands.js';
|
import { registerExtensionSlashCommands as initExtensionSlashCommands } from './scripts/extensions-slashcommands.js';
|
||||||
import { ToolManager } from './scripts/tool-calling.js';
|
import { ToolManager } from './scripts/tool-calling.js';
|
||||||
|
import { addShowdownPatch } from './scripts/util/showdown-patch.js';
|
||||||
|
|
||||||
//exporting functions and vars for mods
|
//exporting functions and vars for mods
|
||||||
export {
|
export {
|
||||||
@ -502,6 +504,7 @@ console.debug('Character context menu initialized', characterContextMenu);
|
|||||||
|
|
||||||
// Markdown converter
|
// Markdown converter
|
||||||
export let mesForShowdownParse; //intended to be used as a context to compare showdown strings against
|
export let mesForShowdownParse; //intended to be used as a context to compare showdown strings against
|
||||||
|
/** @type {import('showdown').Converter} */
|
||||||
let converter;
|
let converter;
|
||||||
reloadMarkdownProcessor();
|
reloadMarkdownProcessor();
|
||||||
|
|
||||||
@ -952,6 +955,7 @@ async function firstLoadInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initLibraryShims();
|
initLibraryShims();
|
||||||
|
addShowdownPatch(showdown);
|
||||||
addSafariPatch();
|
addSafariPatch();
|
||||||
await getClientVersion();
|
await getClientVersion();
|
||||||
await readSecretState();
|
await readSecretState();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { DOMPurify } from '../../lib.js';
|
import { DOMPurify, showdown } from '../../lib.js';
|
||||||
import { sendSystemMessage, system_message_types } from '../../script.js';
|
import { sendSystemMessage, system_message_types } from '../../script.js';
|
||||||
import { callGenericPopup, POPUP_TYPE } from '../popup.js';
|
import { callGenericPopup, POPUP_TYPE } from '../popup.js';
|
||||||
import { escapeHtml } from '../utils.js';
|
import { escapeHtml } from '../utils.js';
|
||||||
|
30
public/scripts/util/showdown-patch.js
Normal file
30
public/scripts/util/showdown-patch.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Patches showdown to unrestrictedly unhash HTML spans.
|
||||||
|
* @param {import('showdown')} showdown The showdown object to patch
|
||||||
|
*/
|
||||||
|
export function addShowdownPatch(showdown) {
|
||||||
|
showdown.subParser('unhashHTMLSpans', function (text, options, globals) {
|
||||||
|
'use strict';
|
||||||
|
text = globals.converter._dispatch('unhashHTMLSpans.before', text, options, globals);
|
||||||
|
|
||||||
|
for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
|
||||||
|
var repText = globals.gHtmlSpans[i],
|
||||||
|
// limiter to prevent infinite loop (assume 10 as limit for recurse)
|
||||||
|
limit = 0;
|
||||||
|
|
||||||
|
while (/¨C(\d+)C/.test(repText)) {
|
||||||
|
var num = RegExp.$1;
|
||||||
|
repText = repText.replace('¨C' + num + 'C', globals.gHtmlSpans[num]);
|
||||||
|
if (limit === 10000) {
|
||||||
|
console.error('maximum nesting of 10000 spans reached!!!');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++limit;
|
||||||
|
}
|
||||||
|
text = text.replace('¨C' + i + 'C', repText);
|
||||||
|
}
|
||||||
|
|
||||||
|
text = globals.converter._dispatch('unhashHTMLSpans.after', text, options, globals);
|
||||||
|
return text;
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user