aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/markup/html2markdown.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web_src/js/markup/html2markdown.ts')
-rw-r--r--web_src/js/markup/html2markdown.ts14
1 files changed, 8 insertions, 6 deletions
diff --git a/web_src/js/markup/html2markdown.ts b/web_src/js/markup/html2markdown.ts
index fc2083e86d..5866d0d259 100644
--- a/web_src/js/markup/html2markdown.ts
+++ b/web_src/js/markup/html2markdown.ts
@@ -1,7 +1,9 @@
-import {htmlEscape} from 'escape-goat';
+import {html, htmlRaw} from '../utils/html.ts';
+
+type Processor = (el: HTMLElement) => string | HTMLElement | void;
type Processors = {
- [tagName: string]: (el: HTMLElement) => string | HTMLElement | void;
+ [tagName: string]: Processor;
}
type ProcessorContext = {
@@ -11,7 +13,7 @@ type ProcessorContext = {
}
function prepareProcessors(ctx:ProcessorContext): Processors {
- const processors = {
+ const processors: Processors = {
H1(el: HTMLElement) {
const level = parseInt(el.tagName.slice(1));
el.textContent = `${'#'.repeat(level)} ${el.textContent.trim()}`;
@@ -36,10 +38,10 @@ function prepareProcessors(ctx:ProcessorContext): Processors {
IMG(el: HTMLElement) {
const alt = el.getAttribute('alt') || 'image';
const src = el.getAttribute('src');
- const widthAttr = el.hasAttribute('width') ? ` width="${htmlEscape(el.getAttribute('width') || '')}"` : '';
- const heightAttr = el.hasAttribute('height') ? ` height="${htmlEscape(el.getAttribute('height') || '')}"` : '';
+ const widthAttr = el.hasAttribute('width') ? htmlRaw` width="${el.getAttribute('width') || ''}"` : '';
+ const heightAttr = el.hasAttribute('height') ? htmlRaw` height="${el.getAttribute('height') || ''}"` : '';
if (widthAttr || heightAttr) {
- return `<img alt="${htmlEscape(alt)}"${widthAttr}${heightAttr} src="${htmlEscape(src)}">`;
+ return html`<img alt="${alt}"${widthAttr}${heightAttr} src="${src}">`;
}
return `![${alt}](${src})`;
},