mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
Merge bc7a4cf8c5
into ee7e9ef2a3
This commit is contained in:
@ -110,24 +110,22 @@ class StrikeThroughWrapper extends BaseMarkdownWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRenderer() {
|
function escapeHtml(unsafe) {
|
||||||
function sanitize(str) {
|
return unsafe
|
||||||
return str.replace(/&<"/g, (m) => {
|
.toString()
|
||||||
if (m === "&") {
|
.replace(/&/g, "&")
|
||||||
return "&";
|
.replace(/</g, "<")
|
||||||
}
|
.replace(/>/g, ">")
|
||||||
if (m === "<") {
|
.replace(/"/g, """)
|
||||||
return "<";
|
.replace(/'/g, "'");
|
||||||
}
|
}
|
||||||
return """;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
function createRenderer() {
|
||||||
const renderer = new marked.Renderer();
|
const renderer = new marked.Renderer();
|
||||||
renderer.image = (href, title, alt) => {
|
renderer.image = (href, title, alt) => {
|
||||||
let [_, url, width, height] =
|
let [_, url, width, height] =
|
||||||
/^(.+?)(?:\s=\s*(\d*)\s*x\s*(\d*)\s*)?$/.exec(href);
|
/^(.+?)(?:\s=\s*(\d*)\s*x\s*(\d*)\s*)?$/.exec(href);
|
||||||
let res = '<img src="' + sanitize(url) + '" alt="' + sanitize(alt);
|
let res = '<img src="' + escapeHtml(url) + '" alt="' + escapeHtml(alt);
|
||||||
if (width) {
|
if (width) {
|
||||||
res += '" width="' + width;
|
res += '" width="' + width;
|
||||||
}
|
}
|
||||||
@ -156,6 +154,7 @@ function formatMarkdown(text) {
|
|||||||
new SmallWrapper(),
|
new SmallWrapper(),
|
||||||
new StrikeThroughWrapper(),
|
new StrikeThroughWrapper(),
|
||||||
];
|
];
|
||||||
|
text = escapeHtml(text);
|
||||||
for (let wrapper of wrappers) {
|
for (let wrapper of wrappers) {
|
||||||
text = wrapper.preprocess(text);
|
text = wrapper.preprocess(text);
|
||||||
}
|
}
|
||||||
@ -182,6 +181,7 @@ function formatInlineMarkdown(text) {
|
|||||||
new SmallWrapper(),
|
new SmallWrapper(),
|
||||||
new StrikeThroughWrapper(),
|
new StrikeThroughWrapper(),
|
||||||
];
|
];
|
||||||
|
text = escapeHtml(text);
|
||||||
for (let wrapper of wrappers) {
|
for (let wrapper of wrappers) {
|
||||||
text = wrapper.preprocess(text);
|
text = wrapper.preprocess(text);
|
||||||
}
|
}
|
||||||
@ -196,4 +196,5 @@ function formatInlineMarkdown(text) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
formatMarkdown: formatMarkdown,
|
formatMarkdown: formatMarkdown,
|
||||||
formatInlineMarkdown: formatInlineMarkdown,
|
formatInlineMarkdown: formatInlineMarkdown,
|
||||||
|
escapeHtml: escapeHtml,
|
||||||
};
|
};
|
||||||
|
@ -156,16 +156,6 @@ function makeCssName(text, suffix) {
|
|||||||
return suffix + "-" + text.replace(/[^a-z0-9]/g, "_");
|
return suffix + "-" + text.replace(/[^a-z0-9]/g, "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapeHtml(unsafe) {
|
|
||||||
return unsafe
|
|
||||||
.toString()
|
|
||||||
.replace(/&/g, "&")
|
|
||||||
.replace(/</g, "<")
|
|
||||||
.replace(/>/g, ">")
|
|
||||||
.replace(/"/g, """)
|
|
||||||
.replace(/'/g, "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
function arraysDiffer(source1, source2, orderImportant) {
|
function arraysDiffer(source1, source2, orderImportant) {
|
||||||
source1 = [...source1];
|
source1 = [...source1];
|
||||||
source2 = [...source2];
|
source2 = [...source2];
|
||||||
@ -221,7 +211,7 @@ module.exports = {
|
|||||||
enableExitConfirmation: enableExitConfirmation,
|
enableExitConfirmation: enableExitConfirmation,
|
||||||
disableExitConfirmation: disableExitConfirmation,
|
disableExitConfirmation: disableExitConfirmation,
|
||||||
confirmPageExit: confirmPageExit,
|
confirmPageExit: confirmPageExit,
|
||||||
escapeHtml: escapeHtml,
|
escapeHtml: markdown.escapeHtml,
|
||||||
makeCssName: makeCssName,
|
makeCssName: makeCssName,
|
||||||
splitByWhitespace: splitByWhitespace,
|
splitByWhitespace: splitByWhitespace,
|
||||||
arraysDiffer: arraysDiffer,
|
arraysDiffer: arraysDiffer,
|
||||||
|
Reference in New Issue
Block a user