diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-04-08 18:15:13 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-04-08 18:15:13 +0100 |
| commit | 76945aec94b352d9f6b5307267f0b085996f4896 (patch) | |
| tree | 4610e468d6fe6763e57c015101922edf21735b3d | |
| parent | 16ab27a56d70e84e6c029cfdf77ea822a5a78da8 (diff) | |
Make style names in style mappings case insensitive
| -rw-r--r-- | NEWS | 9 | ||||
| -rw-r--r-- | lib/document-matchers.js | 2 | ||||
| -rw-r--r-- | tests/document-to-html.tests.js | 17 |
3 files changed, 27 insertions, 1 deletions
@@ -1,3 +1,12 @@ +# 0.3.18 + +* Make style names case-insensitive in style mappings. This should make style + mappings easier to write, especially since Microsoft Word sometimes represents + style names in the UI differently from in the style definition. For instance, + the style displayed in Word as "Heading 1" has a style name of "heading 1". + This hopefully shouldn't cause an issue for anyone, but if you were relying + on case-sensitivity, please do get in touch. + # 0.3.17 * Add support for hyperlinks to bookmarks in the same document. diff --git a/lib/document-matchers.js b/lib/document-matchers.js index bee2ac9..9b01dfd 100644 --- a/lib/document-matchers.js +++ b/lib/document-matchers.js @@ -24,7 +24,7 @@ function Matcher(elementType, options) { Matcher.prototype.matches = function(element) { return element.type === this._elementType && (this._styleId === undefined || element.styleId === this._styleId) && - (this._styleName === undefined || element.styleName === this._styleName) && + (this._styleName === undefined || (element.styleName && element.styleName.toUpperCase() === this._styleName.toUpperCase())) && (this._listIndex === undefined || isList(element, this._listIndex, this._listIsOrdered)); }; diff --git a/tests/document-to-html.tests.js b/tests/document-to-html.tests.js index 41b8129..5a271d0 100644 --- a/tests/document-to-html.tests.js +++ b/tests/document-to-html.tests.js @@ -78,6 +78,23 @@ describe('DocumentConverter', function() { }); }); + test('mappings for style names are case insensitive', function() { + var document = new documents.Document([ + paragraphOfText("Hello.", "Heading1", "heading 1"), + ]); + var converter = new DocumentConverter({ + styleMap: [ + { + from: documentMatchers.paragraph({styleName: "Heading 1"}), + to: htmlPaths.topLevelElement("h1") + } + ] + }); + return converter.convertToHtml(document).then(function(result) { + assert.equal(result.value, "<h1>Hello.</h1>"); + }); + }); + test('can use non-default HTML element for unstyled paragraphs', function() { var document = new documents.Document([ paragraphOfText("Hello.") |
