From 66c9ef99816708cb1ffedd3ec37e5622bf823c20 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 13 Jun 2024 11:52:30 +0100 Subject: Support style mapping for highlights --- test/document-to-html.tests.js | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'test/document-to-html.tests.js') 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, "Hello."); + }); +}); + +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, '

YellowRed

'); + }); +}); + + 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({ -- cgit v1.2.3