aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-11-28 21:08:40 +0000
committerMichael Williamson <mike@zwobble.org>2016-11-28 21:08:40 +0000
commita12b966752ba7ae880f7d6348a42cc986e891a82 (patch)
treeab244d36ea978f5b75021c9c6b49b53376f33aef /lib
parent481d5860686b6b02b5536d7455b88baf7325ecfd (diff)
Map breaks with style maps
Diffstat (limited to 'lib')
-rw-r--r--lib/document-to-html.js25
-rw-r--r--lib/html/ast.js28
-rw-r--r--lib/styles/document-matchers.js6
3 files changed, 37 insertions, 22 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js
index a51afd0..3a30ed2 100644
--- a/lib/document-to-html.js
+++ b/lib/document-to-html.js
@@ -283,6 +283,23 @@ function DocumentConversion(options, comments) {
];
}
+ function convertBreak(element, messages) {
+ return htmlPathForBreak(element).wrap(function() {
+ return [];
+ });
+ }
+
+ function htmlPathForBreak(element) {
+ var style = findStyle(element);
+ if (style) {
+ return style.to;
+ } else if (element.breakType === "line") {
+ return htmlPaths.topLevelElement("br");
+ } else {
+ return htmlPaths.empty;
+ }
+ }
+
function wrapChildrenInFreshElement(element, wrapElementName, messages) {
var children = convertElements(element.children, messages);
return [
@@ -349,13 +366,7 @@ function DocumentConversion(options, comments) {
"table": convertTable,
"tableRow": convertTableRow,
"tableCell": convertTableCell,
- "break": function(element, messages) {
- if (element.breakType === "line") {
- return [Html.freshElement("br")];
- } else {
- return [];
- }
- }
+ "break": convertBreak
};
return {
convertToHtml: convertToHtml
diff --git a/lib/html/ast.js b/lib/html/ast.js
index c949550..34b9a3d 100644
--- a/lib/html/ast.js
+++ b/lib/html/ast.js
@@ -8,12 +8,8 @@ function nonFreshElement(tagName, attributes, children) {
}
function freshElement(tagName, attributes, children) {
- if (isVoidElement(tagName, children)) {
- return selfClosingElement(tagName, attributes);
- } else {
- var tag = htmlPaths.element(tagName, attributes, {fresh: true});
- return elementWithTag(tag, children);
- }
+ var tag = htmlPaths.element(tagName, attributes, {fresh: true});
+ return elementWithTag(tag, children);
}
var voidTagNames = {
@@ -22,16 +18,20 @@ var voidTagNames = {
"img": true
};
-function isVoidElement(tagName, children) {
- return (!children || children.length === 0) && voidTagNames[tagName];
+function elementWithTag(tag, children) {
+ if (isVoidElement(tag.tagName, children)) {
+ return selfClosingElement(tag.tagName, tag.attributes);
+ } else {
+ return {
+ type: "element",
+ tag: tag,
+ children: children || []
+ };
+ }
}
-function elementWithTag(tag, children) {
- return {
- type: "element",
- tag: tag,
- children: children || []
- };
+function isVoidElement(tagName, children) {
+ return (!children || children.length === 0) && voidTagNames[tagName];
}
function selfClosingElement(tagName, attributes) {
diff --git a/lib/styles/document-matchers.js b/lib/styles/document-matchers.js
index 3f7fbdd..afc0a7d 100644
--- a/lib/styles/document-matchers.js
+++ b/lib/styles/document-matchers.js
@@ -5,6 +5,9 @@ exports.italic = new Matcher("italic");
exports.underline = new Matcher("underline");
exports.strikethrough = new Matcher("strikethrough");
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.equalTo = equalTo;
exports.startsWith = startsWith;
@@ -32,7 +35,8 @@ Matcher.prototype.matches = function(element) {
return element.type === this._elementType &&
(this._styleId === undefined || element.styleId === this._styleId) &&
(this._styleName === undefined || (element.styleName && this._styleName.operator(this._styleName.operand, element.styleName))) &&
- (this._listIndex === undefined || isList(element, this._listIndex, this._listIsOrdered));
+ (this._listIndex === undefined || isList(element, this._listIndex, this._listIsOrdered)) &&
+ (this._breakType === undefined || this._breakType === element.breakType);
};
function isList(element, levelIndex, isOrdered) {