diff --git a/client/js/util/markdown.js b/client/js/util/markdown.js index 3b79c473..7270fc0a 100644 --- a/client/js/util/markdown.js +++ b/client/js/util/markdown.js @@ -132,6 +132,34 @@ function formatMarkdown(text) { return text; } +function formatInlineMarkdown(text) { + const renderer = new marked.Renderer(); + const options = { + renderer: renderer, + breaks: true, + sanitize: true, + smartypants: true, + }; + let wrappers = [ + new TildeWrapper(), + new EntityPermalinkWrapper(), + new SearchPermalinkWrapper(), + new SpoilersWrapper(), + new SmallWrapper(), + new StrikeThroughWrapper(), + ]; + for (let wrapper of wrappers) { + text = wrapper.preprocess(text); + } + text = marked.inlineLexer(text, [], options); + wrappers.reverse(); + for (let wrapper of wrappers) { + text = wrapper.postprocess(text); + } + return text; +} + module.exports = { formatMarkdown: formatMarkdown, + formatInlineMarkdown: formatInlineMarkdown, }; diff --git a/client/js/util/misc.js b/client/js/util/misc.js index 256fae64..72fc7db4 100644 --- a/client/js/util/misc.js +++ b/client/js/util/misc.js @@ -95,6 +95,10 @@ function formatMarkdown(text) { return markdown.formatMarkdown(text); } +function formatInlineMarkdown(text) { + return markdown.formatInlineMarkdown(text); +} + function formatUrlParameters(dict) { let result = []; for (let key of Object.keys(dict)) { @@ -230,6 +234,7 @@ module.exports = arrayToObject([ formatRelativeTime, formatFileSize, formatMarkdown, + formatInlineMarkdown, unindent, enableExitConfirmation, disableExitConfirmation, diff --git a/client/js/util/views.js b/client/js/util/views.js index c25a505a..0d3f71fb 100644 --- a/client/js/util/views.js +++ b/client/js/util/views.js @@ -288,15 +288,15 @@ function showMessage(target, message, className) { } function showError(target, message) { - return showMessage(target, message, 'error'); + return showMessage(target, misc.formatInlineMarkdown(message), 'error'); } function showSuccess(target, message) { - return showMessage(target, message, 'success'); + return showMessage(target, misc.formatInlineMarkdown(message), 'success'); } function showInfo(target, message) { - return showMessage(target, message, 'info'); + return showMessage(target, misc.formatInlineMarkdown(message), 'info'); } function clearMessages(target) {