diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-06-13 11:52:30 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-06-13 11:52:30 +0100 |
| commit | 66c9ef99816708cb1ffedd3ec37e5622bf823c20 (patch) | |
| tree | 10e640bcda8b6ecd92a7486a9d700366cf40f239 /test/document-to-html.tests.js | |
| parent | 700e395a3d2a0c9f6526fe7c69a92bd347fa1b88 (diff) | |
Support style mapping for highlights
Diffstat (limited to 'test/document-to-html.tests.js')
| -rw-r--r-- | test/document-to-html.tests.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/document-to-html.tests.js b/test/document-to-html.tests.js index 4283e86..4587602 100644 --- a/test/document-to-html.tests.js +++ b/test/document-to-html.tests.js @@ -344,6 +344,52 @@ test('small caps runs can be configured with style mapping', function() { }); +test('highlighted runs are ignored by default', function() { + var run = runOfText("Hello.", {highlight: "yellow"}); + var converter = new DocumentConverter(); + return converter.convertToHtml(run).then(function(result) { + assert.equal(result.value, "Hello."); + }); +}); + +test('highlighted runs can be configured with style mapping for all highlights', function() { + var run = runOfText("Hello.", {highlight: "yellow"}); + var converter = new DocumentConverter({ + styleMap: [ + { + from: documentMatchers.highlight(null), + to: htmlPaths.elements([htmlPaths.element("mark")]) + } + ] + }); + return converter.convertToHtml(run).then(function(result) { + assert.equal(result.value, "<mark>Hello.</mark>"); + }); +}); + +test('highlighted runs can be configured with style mapping for specific highlight color', function() { + var paragraph = new documents.Paragraph([ + runOfText("Yellow", {highlight: "yellow"}), + runOfText("Red", {highlight: "red"}) + ]); + var converter = new DocumentConverter({ + styleMap: [ + { + from: documentMatchers.highlight({color: "yellow"}), + to: htmlPaths.elements([htmlPaths.element("mark", {"class": "yellow"})]) + }, + { + from: documentMatchers.highlight({color: undefined}), + to: htmlPaths.elements([htmlPaths.element("mark")]) + } + ] + }); + return converter.convertToHtml(paragraph).then(function(result) { + assert.equal(result.value, '<p><mark class="yellow">Yellow</mark><mark>Red</mark></p>'); + }); +}); + + test('run styles are converted to HTML if mapping exists', function() { var run = runOfText("Hello.", {styleId: "Heading1Char", styleName: "Heading 1 Char"}); var converter = new DocumentConverter({ |
