summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-06-13 11:52:30 +0100
committerMichael Williamson <mike@zwobble.org>2024-06-13 11:52:30 +0100
commit66c9ef99816708cb1ffedd3ec37e5622bf823c20 (patch)
tree10e640bcda8b6ecd92a7486a9d700366cf40f239 /lib
parent700e395a3d2a0c9f6526fe7c69a92bd347fa1b88 (diff)
Support style mapping for highlights
Diffstat (limited to 'lib')
-rw-r--r--lib/document-to-html.js6
-rw-r--r--lib/style-reader.js18
-rw-r--r--lib/styles/document-matchers.js15
3 files changed, 39 insertions, 0 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js
index 32e8b03..bd845f6 100644
--- a/lib/document-to-html.js
+++ b/lib/document-to-html.js
@@ -127,6 +127,12 @@ function DocumentConversion(options, comments) {
return convertElements(run.children, messages, options);
};
var paths = [];
+ if (run.highlight !== null) {
+ var path = findHtmlPath({type: "highlight", color: run.highlight});
+ if (path) {
+ paths.push(path);
+ }
+ }
if (run.isSmallCaps) {
paths.push(findHtmlPathForRunProperty("smallCaps"));
}
diff --git a/lib/style-reader.js b/lib/style-reader.js
index 38202f9..6305c59 100644
--- a/lib/style-reader.js
+++ b/lib/style-reader.js
@@ -159,6 +159,23 @@ function documentMatcherRule() {
var strikethrough = identifierToConstant("strike", documentMatchers.strikethrough);
var allCaps = identifierToConstant("all-caps", documentMatchers.allCaps);
var smallCaps = identifierToConstant("small-caps", documentMatchers.smallCaps);
+
+ var highlight = sequence(
+ lop.rules.token("identifier", "highlight"),
+ lop.rules.sequence.capture(lop.rules.optional(lop.rules.sequence(
+ lop.rules.tokenOfType("open-square-bracket"),
+ lop.rules.sequence.cut(),
+ lop.rules.token("identifier", "color"),
+ lop.rules.tokenOfType("equals"),
+ lop.rules.sequence.capture(stringRule),
+ lop.rules.tokenOfType("close-square-bracket")
+ ).head()))
+ ).map(function(color) {
+ return documentMatchers.highlight({
+ color: color.valueOrElse(undefined)
+ });
+ });
+
var commentReference = identifierToConstant("comment-reference", documentMatchers.commentReference);
var breakMatcher = sequence(
@@ -191,6 +208,7 @@ function documentMatcherRule() {
strikethrough,
allCaps,
smallCaps,
+ highlight,
commentReference,
breakMatcher
);
diff --git a/lib/styles/document-matchers.js b/lib/styles/document-matchers.js
index 005e2db..58c844a 100644
--- a/lib/styles/document-matchers.js
+++ b/lib/styles/document-matchers.js
@@ -7,6 +7,7 @@ exports.underline = new Matcher("underline");
exports.strikethrough = new Matcher("strikethrough");
exports.allCaps = new Matcher("allCaps");
exports.smallCaps = new Matcher("smallCaps");
+exports.highlight = highlight;
exports.commentReference = new Matcher("commentReference");
exports.lineBreak = new Matcher("break", {breakType: "line"});
exports.pageBreak = new Matcher("break", {breakType: "page"});
@@ -27,6 +28,10 @@ function table(options) {
return new Matcher("table", options);
}
+function highlight(options) {
+ return new HighlightMatcher(options);
+}
+
function Matcher(elementType, options) {
options = options || {};
this._elementType = elementType;
@@ -46,6 +51,16 @@ Matcher.prototype.matches = function(element) {
(this._breakType === undefined || this._breakType === element.breakType);
};
+function HighlightMatcher(options) {
+ options = options || {};
+ this._color = options.color;
+}
+
+HighlightMatcher.prototype.matches = function(element) {
+ return element.type === "highlight" &&
+ (this._color === undefined || element.color === this._color);
+};
+
function isList(element, levelIndex, isOrdered) {
return element.numbering &&
element.numbering.level == levelIndex &&