Skip to content

Commit

Permalink
Fix to work with text formating
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmartyrk committed Dec 17, 2020
1 parent 89d03f3 commit cadd9eb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ const _analyzeLine = (alineAttrs, apool) => {
exports.getLineHTMLForExport = async (hookName, context) => {
const header = _analyzeLine(context.attribLine, context.apool);
if (header) {
context.lineContent = `<${header}>${context.lineContent.substring(1)}</${header}>`;
if (context.text.indexOf('*') === 0) {
context.lineContent = context.lineContent.replace('*', '');
}
const paragraph = context.lineContent.match(/<p([^>]+)?>/);
if (paragraph) {
context.lineContent = context.lineContent.replace('<p', `<${header} `);
context.lineContent = context.lineContent.replace('</p>', `</${header}>`);
} else {
context.lineContent = `<${header}>${context.lineContent}</${header}>`;
}
return context.lineContent;
}
};
34 changes: 34 additions & 0 deletions static/tests/backend/specs/exportHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,38 @@ describe('ep_headings2 - export headings to HTML', function () {
.end(done);
});
});

context('when pad text has multiple Headings and align tags', function () {
before(async function () {
html = () => buildHTML('<h1><left>Hello world</left></h1><br/><h2><center>Foo</center></h2>');
});

it('returns ok', function (done) {
api.get(getHTMLEndPointFor(padID))
.expect('Content-Type', /json/)
.expect(200, done);
});

it('returns HTML with Multiple Headings HTML tags', function (done) {
try {
require.resolve('ep_align'); // eslint-disable-line
api.get(getHTMLEndPointFor(padID))
.expect((res) => {
const html = res.body.data.html;
if (html.indexOf('<h1 style="text-align:left">Hello world</h1>') === -1) {
throw new Error('No H1 tag detected');
}
if (html.indexOf('<h2 style="text-align:center">Foo</h2>') === -1) {
throw new Error('No H2 tag detected');
}
})
.end(done);
} catch (e) {
if (e.message.indexOf('Cannot find module') === -1) {
throw new Error(e.message);
}
done();
}
});
});
});

0 comments on commit cadd9eb

Please sign in to comment.