client/errors: show errors in inline Markdown

This commit is contained in:
rr- 2016-09-10 11:11:07 +02:00
parent e05e0e5fd2
commit 5b565e3b00
3 changed files with 36 additions and 3 deletions

View file

@ -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,
};

View file

@ -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,

View file

@ -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) {