diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-06-17 14:33:43 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-06-17 14:33:43 +0100 |
| commit | 17577bdd715c65e71d81f762b54b8c27f60f4535 (patch) | |
| tree | 5389d7741881b2d198daf450f915fa9b3527f7e7 /lib | |
| parent | dc31bacddd43e100a2793c76e26d35568262d89a (diff) | |
Support underlines in style map
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/document-matchers.js | 1 | ||||
| -rw-r--r-- | lib/document-to-html.js | 15 | ||||
| -rw-r--r-- | lib/html-generator.js | 5 | ||||
| -rw-r--r-- | lib/style-reader.js | 9 |
4 files changed, 27 insertions, 3 deletions
diff --git a/lib/document-matchers.js b/lib/document-matchers.js index 9b01dfd..a4d59be 100644 --- a/lib/document-matchers.js +++ b/lib/document-matchers.js @@ -1,5 +1,6 @@ exports.paragraph = paragraph; exports.run = run; +exports.underline = new Matcher("underline"); function paragraph(options) { diff --git a/lib/document-to-html.js b/lib/document-to-html.js index 220ae2b..264f7c9 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -122,8 +122,8 @@ function DocumentConversion(options) { if (run.verticalAlignment === documents.verticalAlignment.subscript) { runHtml.open(htmlPaths.element("sub")); } - if (run.isUnderline && options.convertUnderline) { - options.convertUnderline(runHtml); + if (run.isUnderline) { + convertUnderline(runHtml); } convertElements(run.children, runHtml, messages, function(err) { if (err) { @@ -136,6 +136,17 @@ function DocumentConversion(options) { }); } + function convertUnderline(runHtml) { + (options.convertUnderline || defaultConvertUnderline)(runHtml); + } + + function defaultConvertUnderline(runHtml) { + var style = findStyle({type: "underline"}); + if (style) { + runHtml.appendPath(style.to); + } + } + function findStyle(element) { for (var i = 0; i < styleMap.length; i++) { if (styleMap[i].from.matches(element)) { diff --git a/lib/html-generator.js b/lib/html-generator.js index a071a5e..a20a714 100644 --- a/lib/html-generator.js +++ b/lib/html-generator.js @@ -43,6 +43,10 @@ function HtmlGenerator(options) { } } + function appendPath(style) { + style.forEach(open); + } + function stylePartMatchesStackElement(stylePart, stackElement) { return stackElement && stylePart.matchesElement(stackElement); } @@ -86,6 +90,7 @@ function HtmlGenerator(options) { return { satisfyPath: satisfyPath, + appendPath: appendPath, text: text, open: open, close: close, diff --git a/lib/style-reader.js b/lib/style-reader.js index ef379b6..811e06e 100644 --- a/lib/style-reader.js +++ b/lib/style-reader.js @@ -109,7 +109,7 @@ function documentMatcherRule() { ); var matcherSuffixes = lop.rules.zeroOrMore(matcherSuffix); - return sequence( + var paragraphOrRun = sequence( sequence.capture(elementTypeRule), sequence.capture(matcherSuffixes) ).map(function(createMatcher, suffixes) { @@ -119,6 +119,13 @@ function documentMatcherRule() { }); return createMatcher(matcherOptions); }); + + var underline = identifierToConstant("u", documentMatchers.underline); + + return lop.rules.firstOf("element type", + paragraphOrRun, + underline + ); } function readHtmlPath(string) { |
