diff options
| author | rr- | 2016-09-10 11:11:07 +0200 |
|---|---|---|
| committer | rr- | 2016-09-10 11:36:02 +0200 |
| commit | 5b565e3b009eb581f06fffd8b7240379aa33eb95 (patch) | |
| tree | df1e871961237f15d8b75c57e370c4a8e300c28d /client/js/util | |
| parent | e05e0e5fd22cc9ffaccc58a511651719937ef26f (diff) | |
client/errors: show errors in inline Markdown
Diffstat (limited to 'client/js/util')
| -rw-r--r-- | client/js/util/markdown.js | 28 | ||||
| -rw-r--r-- | client/js/util/misc.js | 5 | ||||
| -rw-r--r-- | client/js/util/views.js | 6 |
3 files changed, 36 insertions, 3 deletions
diff --git a/client/js/util/markdown.js b/client/js/util/markdown.js index 3b79c47..7270fc0 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 256fae6..72fc7db 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 c25a505..0d3f71f 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) { |