Skip to content

Commit

Permalink
Fix: matchers for specific break types match all break types
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilliamson committed Jun 13, 2024
1 parent 66c9ef9 commit 0546ccd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 13 additions & 3 deletions lib/styles/document-matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ 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"});
exports.columnBreak = new Matcher("break", {breakType: "column"});
exports.lineBreak = new BreakMatcher({breakType: "line"});
exports.pageBreak = new BreakMatcher({breakType: "page"});
exports.columnBreak = new BreakMatcher({breakType: "column"});
exports.equalTo = equalTo;
exports.startsWith = startsWith;

Expand Down Expand Up @@ -61,6 +61,16 @@ HighlightMatcher.prototype.matches = function(element) {
(this._color === undefined || element.color === this._color);
};

function BreakMatcher(options) {
options = options || {};
this._breakType = options.breakType;
}

BreakMatcher.prototype.matches = function(element) {
return element.type === "break" &&
(this._breakType === undefined || element.breakType === this._breakType);
};

function isList(element, levelIndex, isOrdered) {
return element.numbering &&
element.numbering.level == levelIndex &&
Expand Down
10 changes: 8 additions & 2 deletions test/document-to-html.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,18 @@ test('breaks can be mapped using style mappings', function() {
{
from: documentMatchers.pageBreak,
to: htmlPaths.topLevelElement("hr")
},
{
from: documentMatchers.lineBreak,
to: htmlPaths.topLevelElement("br", {class: "line-break"})
}
]
});

return converter.convertToHtml(documents.pageBreak).then(function(result) {
assert.equal(result.value, "<hr />");
var run = documents.run([documents.pageBreak, documents.lineBreak]);

return converter.convertToHtml(run).then(function(result) {
assert.equal(result.value, '<hr /><br class="line-break" />');
});
});

Expand Down

0 comments on commit 0546ccd

Please sign in to comment.