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