unvendor: Replace showdown

7b0f7306c0e5105c135fb47fba16b0e6825300f5

Cohee <18619528+Cohee1207@users.noreply.github.com>

10 files changed, +45 -6Showing whitespace changes
.eslintrc.cjs+0 -1
@@ -53,7 +53,6 @@ module.exports = {
5353 droll: 'readonly',
5454 moment: 'readonly',
5555 Popper: 'readonly',
56- showdown: 'readonly',
5756 showdownKatex: 'readonly',
5857 toastr: 'readonly',
5958 isProbablyReaderable: 'readonly',
package-lock.json+26 -0
@@ -56,6 +56,7 @@
5656 "rate-limiter-flexible": "^5.0.0",
5757 "response-time": "^2.3.2",
5858 "sanitize-filename": "^1.6.3",
59+ "showdown": "^2.1.0",
5960 "sillytavern-transformers": "2.14.6",
6061 "simple-git": "^3.19.1",
6162 "tiktoken": "^1.0.16",
@@ -7137,6 +7138,31 @@
71377138 "node": ">=8"
71387139 }
71397140 },
7141+ "node_modules/showdown": {
7142+ "version": "2.1.0",
7143+ "resolved": "https://registry.npmjs.org/showdown/-/showdown-2.1.0.tgz",
7144+ "integrity": "sha512-/6NVYu4U819R2pUIk79n67SYgJHWCce0a5xTP979WbNp0FL9MN1I1QK662IDU1b6JzKTvmhgI7T7JYIxBi3kMQ==",
7145+ "license": "MIT",
7146+ "dependencies": {
7147+ "commander": "^9.0.0"
7148+ },
7149+ "bin": {
7150+ "showdown": "bin/showdown.js"
7151+ },
7152+ "funding": {
7153+ "type": "individual",
7154+ "url": "https://www.paypal.me/tiviesantos"
7155+ }
7156+ },
7157+ "node_modules/showdown/node_modules/commander": {
7158+ "version": "9.5.0",
7159+ "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz",
7160+ "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==",
7161+ "license": "MIT",
7162+ "engines": {
7163+ "node": "^12.20.0 || >=14"
7164+ }
7165+ },
71407166 "node_modules/side-channel": {
71417167 "version": "1.0.6",
71427168 "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz",
package.json+1 -0
@@ -46,6 +46,7 @@
4646 "rate-limiter-flexible": "^5.0.0",
4747 "response-time": "^2.3.2",
4848 "sanitize-filename": "^1.6.3",
49+ "showdown": "^2.1.0",
4950 "sillytavern-transformers": "2.14.6",
5051 "simple-git": "^3.19.1",
5152 "tiktoken": "^1.0.16",
public/global.d.ts+0 -1
@@ -1,7 +1,6 @@
11// Global namespace modules
22declare var droll;
33declare var Popper;
4-declare var showdown;
54declare var showdownKatex;
65declare var ai;
76
public/index.html+0 -2
@@ -6745,8 +6745,6 @@
67456745 <script src="lib/jquery.transit.min.js"></script>
67466746 <script src="lib/jquery-cookie-1.4.1.min.js"></script>
67476747 <script src="lib/jquery.ui.touch-punch.min.js"></script>
6748- <script src="lib/showdown.min.js"></script>
6749- <script src="lib/showdown-patch.js"></script>
67506748 <script src="lib/showdown-katex.min.js"></script>
67516749 <script src="lib/popper.js"></script>
67526750 <script src="lib/moment-with-locales.min.js"></script>
public/jsconfig.json+0 -1
@@ -18,7 +18,6 @@
1818 "typeAcquisition": {
1919 "include": [
2020 "@popperjs/core",
21- "showdown",
2221 "seedrandom",
2322 "showdown-katex",
2423 "droll"
public/lib.js+7 -0
@@ -15,6 +15,7 @@ import * as pdfjsLib from 'pdfjs-dist/webpack.mjs';
1515import DiffMatchPatch from 'diff-match-patch';
1616import { isProbablyReaderable, Readability } from '@mozilla/readability';
1717import SVGInject from '@iconfu/svg-inject';
18+import showdown from 'showdown';
1819
1920/**
2021 * Expose the libraries to the 'window' object.
@@ -53,6 +54,10 @@ export function initLibraryShims() {
5354 // @ts-ignore
5455 window.SVGInject = SVGInject;
5556 }
57+ if (!('showdown' in window)) {
58+ // @ts-ignore
59+ window.showdown = showdown;
60+ }
5661}
5762
5863export default {
@@ -70,6 +75,7 @@ export default {
7075 Readability,
7176 isProbablyReaderable,
7277 SVGInject,
78+ showdown,
7379};
7480
7581export {
@@ -87,4 +93,5 @@ export {
8793 Readability,
8894 isProbablyReaderable,
8995 SVGInject,
96+ showdown,
9097};
public/script.js+4 -0
@@ -1,4 +1,5 @@
11import {
2+ showdown,
23 Fuse,
34 DOMPurify,
45 hljs,
@@ -259,6 +260,7 @@ import { AbortReason } from './scripts/util/AbortReason.js';
259260import { initSystemPrompts } from './scripts/sysprompt.js';
260261import { registerExtensionSlashCommands as initExtensionSlashCommands } from './scripts/extensions-slashcommands.js';
261262import { ToolManager } from './scripts/tool-calling.js';
263+import { addShowdownPatch } from './scripts/util/showdown-patch.js';
262264
263265//exporting functions and vars for mods
264266export {
@@ -502,6 +504,7 @@ console.debug('Character context menu initialized', characterContextMenu);
502504
503505// Markdown converter
504506export let mesForShowdownParse; //intended to be used as a context to compare showdown strings against
507+/** @type {import('showdown').Converter} */
505508let converter;
506509reloadMarkdownProcessor();
507510
@@ -952,6 +955,7 @@ async function firstLoadInit() {
952955 }
953956
954957 initLibraryShims();
958+ addShowdownPatch(showdown);
955959 addSafariPatch();
956960 await getClientVersion();
957961 await readSecretState();
public/scripts/slash-commands/SlashCommandReturnHelper.js+1 -1
@@ -1,4 +1,4 @@
11import { DOMPurify, showdown } from '../../lib.js';
22import { sendSystemMessage, system_message_types } from '../../script.js';
33import { callGenericPopup, POPUP_TYPE } from '../popup.js';
44import { escapeHtml } from '../utils.js';
public/lib/showdown-patch.js → public/scripts/util/showdown-patch.js+6 -0
@@ -1,3 +1,8 @@
1+/**
2+ * Patches showdown to unrestrictedly unhash HTML spans.
3+ * @param {import('showdown')} showdown The showdown object to patch
4+ */
5+export function addShowdownPatch(showdown) {
16 showdown.subParser('unhashHTMLSpans', function (text, options, globals) {
27 'use strict';
38 text = globals.converter._dispatch('unhashHTMLSpans.before', text, options, globals);
@@ -22,3 +27,4 @@ showdown.subParser('unhashHTMLSpans', function (text, options, globals) {
2227 text = globals.converter._dispatch('unhashHTMLSpans.after', text, options, globals);
2328 return text;
2429 });
30+}