Desktop: WYSIWYG: Fixed inserting date time and other content inside header

pull/3458/head
Laurent Cozic 2020-07-04 12:17:30 +01:00
parent 9c057071b5
commit 77a03599de
5 changed files with 18 additions and 5 deletions

View File

@ -140,7 +140,7 @@ describe('MdToHtml', function() {
// The style is instead in the cssStrings property.
const result = await mdToHtml.render('just **testing**', null, { bodyOnly: true });
expect(result.cssStrings.length).toBe(1);
expect(result.html.trim()).toBe('<p>just <strong>testing</strong></p>');
expect(result.html.trim()).toBe('just <strong>testing</strong>');
}));
it('should split HTML and CSS', asyncTest(async () => {

View File

@ -1 +1 @@
<p><a href="#" class="jop-noMdConv">Testing <strong>inline</strong> text</a></p>
<a href="#" class="jop-noMdConv">Testing <strong>inline</strong> text</a>

View File

@ -1 +1 @@
<p>Should be <span style="color: red;" class="jop-noMdConv">red</span>.</p>
Should be <span style="color: red;" class="jop-noMdConv">red</span>.

View File

@ -1 +1 @@
<p><mark class="jop-noMdConv">bla</mark></p>
<mark class="jop-noMdConv">bla</mark>

View File

@ -166,6 +166,14 @@ class MdToHtml {
return output;
}
removeMarkdownItWrappingParagraph_(html) {
// <p></p>\n
if (html.length < 8) return html;
if (html.substr(0, 3) !== '<p>') return html;
if (html.slice(-5) !== '</p>\n') return html;
return html.substring(3, html.length - 5);
}
// "style" here is really the theme, as returned by themeStyle()
async render(body, theme = null, options = null) {
options = Object.assign({}, {
@ -305,7 +313,12 @@ class MdToHtml {
if (options.userCss) cssStrings.push(options.userCss);
if (options.bodyOnly) {
output.html = renderedBody;
// Markdown-it wraps any content in <p></p> by default. There's a function to parse without
// adding these tags (https://github.com/markdown-it/markdown-it/issues/540#issuecomment-471123983)
// however when using it, it seems the loaded plugins are not used. In my tests, just changing
// render() to renderInline() means the checkboxes would not longer be rendered. So instead
// of using this function, we manually remove the <p></p> tags.
output.html = this.removeMarkdownItWrappingParagraph_(renderedBody);
output.cssStrings = cssStrings;
} else {
const styleHtml = `<style>${cssStrings.join('\n')}</style>`;