1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-23 18:53:36 +02:00

HtmlToMd: Fix LI tags that contains blocks

This commit is contained in:
Laurent Cozic 2018-05-14 23:13:17 +01:00
parent 2e32211a28
commit 3c95979d94
3 changed files with 22 additions and 5 deletions

View File

@ -34,7 +34,7 @@ describe('HtmlToMd', function() {
const htmlPath = basePath + '/' + htmlFilename;
const mdPath = basePath + '/' + filename(htmlFilename) + '.md';
// if (htmlFilename !== 'list2.html') continue;
// if (htmlFilename !== 'list4.html') continue;
const html = await shim.fsDriver().readFile(htmlPath);
const expectedMd = await shim.fsDriver().readFile(mdPath);

View File

@ -1,11 +1,11 @@
<ul>
<li>
<figure style="height:551px;">
<div style="height:551px;">
<div class="image" style="background-image:url('https://cdn.arstechnica.net/wp-content/uploads/2018/05/2018050719551800-9A1517382E5F6AE0CEFC2F883445C47F-980x551.jpg'); background-color:#000"></div>
<figcaption id="caption-1308165">
<div id="caption-1308165">
<span class="icon caption-arrow icon-drop-indicator"></span>
<div class="caption">The Kit won't work without a Joy-Con infrared camera looking in.</div>
</figcaption>
</figure>
</div>
</div>
</li>
</ul>

View File

@ -747,6 +747,11 @@ function enexXmlToMdArray(stream, resources, options = {}) {
warningsTags: [],
};
// In some cases white space should be ignored. For example, this:
// <ul>
// <li>item</li>
// <ul>
// The whitespace between <ul> and <li> should not appear in the markdown document
const ignoreWhiteSpace = () => {
return state.ignoreWhiteSpace.length ? state.ignoreWhiteSpace[state.ignoreWhiteSpace.length-1] : false;
}
@ -1051,6 +1056,18 @@ function enexXmlToMdArray(stream, resources, options = {}) {
state.lists.pop();
} else if (n === 'li') {
state.ignoreWhiteSpace.pop();
// Once the LI tag is closed, go back to tokens that were added and remove and newline or block delimiter
// since the LI needs to be one line only to work.
for (let i = section.lines.length - 1; i >= 0; i--) {
const line = section.lines[i];
if ([BLOCK_OPEN, BLOCK_CLOSE, NEWLINE, NEWLINE_MERGED, SPACE].indexOf(line) >= 0 || !line) {
section.lines.splice(i, 1);
} else if (line === '- ') {
break;
}
}
section.lines.push(BLOCK_CLOSE);
} else if (isStrongTag(n)) {
section.lines.push("**");