1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-12 22:57:38 +02:00

Many changes and improvements

This commit is contained in:
Laurent Cozic
2017-11-13 00:23:12 +00:00
parent 2cf5234e76
commit 7177ca21c9
9 changed files with 83 additions and 42 deletions

View File

@ -155,8 +155,10 @@ class MdToHtml {
renderTokens_(tokens, options) {
let output = [];
let previousToken = null;
for (let i = 0; i < tokens.length; i++) {
const t = tokens[i];
const nextToken = i < tokens.length ? tokens[i+1] : null;
let tag = t.tag;
let openTag = null;
@ -166,7 +168,12 @@ class MdToHtml {
// if (t.map) attrs.push(['data-map', t.map.join(':')]);
if (tag && t.type.indexOf('_open') >= 0) {
if (previousToken && previousToken.tag === 'li' && tag === 'p') {
// Markdown-it render list items as <li><p>Text<p></li> which makes it
// complicated to style and layout the HTML, so we remove this extra
// <p> here and below in closeTag.
openTag = null;
} else if (tag && t.type.indexOf('_open') >= 0) {
openTag = tag;
} else if (tag && t.type.indexOf('_close') >= 0) {
closeTag = tag;
@ -196,6 +203,10 @@ class MdToHtml {
if (t.type === 'image') {
if (t.content) attrs.push(['title', t.content]);
output.push(this.renderImage_(attrs, options));
} else if (t.type === 'softbreak') {
output.push('<br/>');
} else if (t.type === 'hr') {
output.push('<hr/>');
} else {
if (t.children) {
const parsedChildren = this.renderTokens_(t.children, options);
@ -207,7 +218,9 @@ class MdToHtml {
}
}
if (t.type === 'link_close') {
if (nextToken && nextToken.tag === 'li' && t.tag === 'p') {
closeTag = null;
} else if (t.type === 'link_close') {
closeTag = 'a';
} else if (tag && t.type.indexOf('inline') >= 0) {
closeTag = openTag;
@ -223,7 +236,9 @@ class MdToHtml {
} else {
output.push('</' + closeTag + '>');
}
}
}
previousToken = t;
}
return output.join('');
}
@ -235,7 +250,10 @@ class MdToHtml {
const cacheKey = this.makeContentKey(this.loadedResources_, body, style, options);
if (this.cachedContentKey_ === cacheKey) return this.cachedContent_;
const md = new MarkdownIt();
const md = new MarkdownIt({
breaks: true,
linkify: true,
});
const env = {};
// Hack to make checkboxes clickable. Ideally, checkboxes should be parsed properly in
@ -257,7 +275,7 @@ class MdToHtml {
const tokens = md.parse(body, env);
// console.info(body);
// console.info(tokens);
console.info(tokens);
let renderedBody = this.renderTokens_(tokens, options);
@ -304,7 +322,8 @@ class MdToHtml {
color: ` + style.htmlLinkColor + `
}
ul {
padding-left: 0;
padding-left: 1.3em;
}
a.checkbox {
font-size: 1.6em;
@ -321,7 +340,8 @@ class MdToHtml {
padding: .5em 1em .5em 1em;
}
hr {
border: 1px solid ` + style.htmlDividerColor + `;
border: none;
border-bottom: 1px solid ` + style.htmlDividerColor + `;
}
img {
width: auto;