All: Convert new lines in tables to BR tag, and added support for HTML tags in Markdown viewers

pull/235/head
Laurent Cozic 2018-02-17 19:28:24 +00:00
parent 90bcd7c977
commit eca500880d
2 changed files with 8 additions and 6 deletions

View File

@ -208,6 +208,8 @@ class MdToHtml {
openTag = null; openTag = null;
} else if (isInlineCode) { } else if (isInlineCode) {
openTag = null; openTag = null;
} else if (tag && t.type.indexOf('html_inline') >= 0) {
openTag = null;
} else if (tag && t.type.indexOf('_open') >= 0) { } else if (tag && t.type.indexOf('_open') >= 0) {
openTag = tag; openTag = tag;
} else if (tag && t.type.indexOf('_close') >= 0) { } else if (tag && t.type.indexOf('_close') >= 0) {
@ -266,6 +268,8 @@ class MdToHtml {
if (t.type === 'image') { if (t.type === 'image') {
if (tokenContent) attrs.push(['title', tokenContent]); if (tokenContent) attrs.push(['title', tokenContent]);
output.push(this.renderImage_(attrs, options)); output.push(this.renderImage_(attrs, options));
} else if (t.type === 'html_inline') {
output.push(t.content);
} else if (t.type === 'softbreak') { } else if (t.type === 'softbreak') {
output.push('<br/>'); output.push('<br/>');
} else if (t.type === 'hr') { } else if (t.type === 'hr') {
@ -351,6 +355,7 @@ class MdToHtml {
const md = new MarkdownIt({ const md = new MarkdownIt({
breaks: true, breaks: true,
linkify: true, linkify: true,
html: true,
}); });
// This is currently used only so that the $expression$ and $$\nexpression\n$$ blocks are translated // This is currently used only so that the $expression$ and $$\nexpression\n$$ blocks are translated

View File

@ -617,10 +617,6 @@ function enexXmlToMdArray(stream, resources) {
}); });
} }
function removeTableCellNewLines(cellText) {
return cellText.replace(/\n+/g, " ");
}
function tableHasSubTables(table) { function tableHasSubTables(table) {
for (let trIndex = 0; trIndex < table.lines.length; trIndex++) { for (let trIndex = 0; trIndex < table.lines.length; trIndex++) {
const tr = table.lines[trIndex]; const tr = table.lines[trIndex];
@ -689,8 +685,9 @@ function drawTable(table) {
line.push(BLOCK_CLOSE); line.push(BLOCK_CLOSE);
} else { // Regular table rendering } else { // Regular table rendering
// A cell in a Markdown table cannot have new lines so remove them // A cell in a Markdown table cannot have actual new lines so replace
const cellText = removeTableCellNewLines(processMdArrayNewLines(td.lines)); // them with <br>, which are supported by the markdown renderers.
const cellText = processMdArrayNewLines(td.lines).replace(/\n+/g, "<br>");
const width = Math.max(cellText.length, 3); const width = Math.max(cellText.length, 3);
line.push(stringPadding(cellText, width, ' ', stringPadding.RIGHT)); line.push(stringPadding(cellText, width, ' ', stringPadding.RIGHT));