unvendor: Replace showdown
| @@ -53,7 +53,6 @@ module.exports = { | ||
| 53 | 53 | droll: 'readonly', |
| 54 | 54 | moment: 'readonly', |
| 55 | 55 | Popper: 'readonly', |
| 56 | - showdown: 'readonly', | |
| 57 | 56 | showdownKatex: 'readonly', |
| 58 | 57 | toastr: 'readonly', |
| 59 | 58 | isProbablyReaderable: 'readonly', |
| @@ -56,6 +56,7 @@ | ||
| 56 | 56 | "rate-limiter-flexible": "^5.0.0", |
| 57 | 57 | "response-time": "^2.3.2", |
| 58 | 58 | "sanitize-filename": "^1.6.3", |
| 59 | + "showdown": "^2.1.0", | |
| 59 | 60 | "sillytavern-transformers": "2.14.6", |
| 60 | 61 | "simple-git": "^3.19.1", |
| 61 | 62 | "tiktoken": "^1.0.16", |
| @@ -7137,6 +7138,31 @@ | ||
| 7137 | 7138 | "node": ">=8" |
| 7138 | 7139 | } |
| 7139 | 7140 | }, |
| 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 | + }, | |
| 7140 | 7166 | "node_modules/side-channel": { |
| 7141 | 7167 | "version": "1.0.6", |
| 7142 | 7168 | "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", |
| @@ -46,6 +46,7 @@ | ||
| 46 | 46 | "rate-limiter-flexible": "^5.0.0", |
| 47 | 47 | "response-time": "^2.3.2", |
| 48 | 48 | "sanitize-filename": "^1.6.3", |
| 49 | + "showdown": "^2.1.0", | |
| 49 | 50 | "sillytavern-transformers": "2.14.6", |
| 50 | 51 | "simple-git": "^3.19.1", |
| 51 | 52 | "tiktoken": "^1.0.16", |
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | // Global namespace modules |
| 2 | 2 | declare var droll; |
| 3 | 3 | declare var Popper; |
| 4 | -declare var showdown; | |
| 5 | 4 | declare var showdownKatex; |
| 6 | 5 | declare var ai; |
| 7 | 6 | |
| @@ -6745,8 +6745,6 @@ | ||
| 6745 | 6745 | <script src="lib/jquery.transit.min.js"></script> |
| 6746 | 6746 | <script src="lib/jquery-cookie-1.4.1.min.js"></script> |
| 6747 | 6747 | <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> | |
| 6750 | 6748 | <script src="lib/showdown-katex.min.js"></script> |
| 6751 | 6749 | <script src="lib/popper.js"></script> |
| 6752 | 6750 | <script src="lib/moment-with-locales.min.js"></script> |
| @@ -18,7 +18,6 @@ | ||
| 18 | 18 | "typeAcquisition": { |
| 19 | 19 | "include": [ |
| 20 | 20 | "@popperjs/core", |
| 21 | - "showdown", | |
| 22 | 21 | "seedrandom", |
| 23 | 22 | "showdown-katex", |
| 24 | 23 | "droll" |
| @@ -15,6 +15,7 @@ import * as pdfjsLib from 'pdfjs-dist/webpack.mjs'; | ||
| 15 | 15 | import DiffMatchPatch from 'diff-match-patch'; |
| 16 | 16 | import { isProbablyReaderable, Readability } from '@mozilla/readability'; |
| 17 | 17 | import SVGInject from '@iconfu/svg-inject'; |
| 18 | +import showdown from 'showdown'; | |
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Expose the libraries to the 'window' object. |
| @@ -53,6 +54,10 @@ export function initLibraryShims() { | ||
| 53 | 54 | // @ts-ignore |
| 54 | 55 | window.SVGInject = SVGInject; |
| 55 | 56 | } |
| 57 | + if (!('showdown' in window)) { | |
| 58 | + // @ts-ignore | |
| 59 | + window.showdown = showdown; | |
| 60 | + } | |
| 56 | 61 | } |
| 57 | 62 | |
| 58 | 63 | export default { |
| @@ -70,6 +75,7 @@ export default { | ||
| 70 | 75 | Readability, |
| 71 | 76 | isProbablyReaderable, |
| 72 | 77 | SVGInject, |
| 78 | + showdown, | |
| 73 | 79 | }; |
| 74 | 80 | |
| 75 | 81 | export { |
| @@ -87,4 +93,5 @@ export { | ||
| 87 | 93 | Readability, |
| 88 | 94 | isProbablyReaderable, |
| 89 | 95 | SVGInject, |
| 96 | + showdown, | |
| 90 | 97 | }; |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | import { |
| 2 | + showdown, | |
| 2 | 3 | Fuse, |
| 3 | 4 | DOMPurify, |
| 4 | 5 | hljs, |
| @@ -259,6 +260,7 @@ import { AbortReason } from './scripts/util/AbortReason.js'; | ||
| 259 | 260 | import { initSystemPrompts } from './scripts/sysprompt.js'; |
| 260 | 261 | import { registerExtensionSlashCommands as initExtensionSlashCommands } from './scripts/extensions-slashcommands.js'; |
| 261 | 262 | import { ToolManager } from './scripts/tool-calling.js'; |
| 263 | +import { addShowdownPatch } from './scripts/util/showdown-patch.js'; | |
| 262 | 264 | |
| 263 | 265 | //exporting functions and vars for mods |
| 264 | 266 | export { |
| @@ -502,6 +504,7 @@ console.debug('Character context menu initialized', characterContextMenu); | ||
| 502 | 504 | |
| 503 | 505 | // Markdown converter |
| 504 | 506 | export let mesForShowdownParse; //intended to be used as a context to compare showdown strings against |
| 507 | +/** @type {import('showdown').Converter} */ | |
| 505 | 508 | let converter; |
| 506 | 509 | reloadMarkdownProcessor(); |
| 507 | 510 | |
| @@ -952,6 +955,7 @@ async function firstLoadInit() { | ||
| 952 | 955 | } |
| 953 | 956 | |
| 954 | 957 | initLibraryShims(); |
| 958 | + addShowdownPatch(showdown); | |
| 955 | 959 | addSafariPatch(); |
| 956 | 960 | await getClientVersion(); |
| 957 | 961 | await readSecretState(); |
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | import { DOMPurify, showdown } from '../../lib.js'; |
| 2 | 2 | import { sendSystemMessage, system_message_types } from '../../script.js'; |
| 3 | 3 | import { callGenericPopup, POPUP_TYPE } from '../popup.js'; |
| 4 | 4 | import { escapeHtml } from '../utils.js'; |
| @@ -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) { | |
| 1 | 6 | showdown.subParser('unhashHTMLSpans', function (text, options, globals) { |
| 2 | 7 | 'use strict'; |
| 3 | 8 | text = globals.converter._dispatch('unhashHTMLSpans.before', text, options, globals); |
| @@ -22,3 +27,4 @@ showdown.subParser('unhashHTMLSpans', function (text, options, globals) { | ||
| 22 | 27 | text = globals.converter._dispatch('unhashHTMLSpans.after', text, options, globals); |
| 23 | 28 | return text; |
| 24 | 29 | }); |
| 30 | +} | |