Skip to content

Commit

Permalink
Make style names in style mappings case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilliamson committed Apr 8, 2015
1 parent 16ab27a commit 76945ae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/document-matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

Expand Down
17 changes: 17 additions & 0 deletions tests/document-to-html.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down

0 comments on commit 76945ae

Please sign in to comment.