Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
Allows non-array, non-string values to be node.class values.
Browse files Browse the repository at this point in the history
`node.class` is always an array, so if we're a string, we split on spaces, like
how classes are specified when creating HTML strings, or if we're a non-array,
non-string value, we wrap ourselves into single-element array.

Includes the following patch-level changes:
	- Moves the location of the `isBooleanAttribute` function.

This is a minor change.
  • Loading branch information
chrisdotcode committed Mar 22, 2016
1 parent 462d175 commit 7d6d6f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
14 changes: 7 additions & 7 deletions dist/lmth.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,14 @@ function parseAttributes(attributes) {
}
});

if (!Array.isArray(nodeAttributes.class)) {
// `node.class` is always an array, so if we're a string, we
// split on spaces, like how classes are specified when
// creating HTML strings, or if we're a non-array, non-string
// value, we wrap ourselves into single-element array.
if (isString(nodeAttributes.class)) {
nodeAttributes.class = nodeAttributes.class.split(' ');
} else if (!Array.isArray(nodeAttributes.class)) {
nodeAttributes.class = [nodeAttributes.class];
}

}
Expand Down Expand Up @@ -289,6 +295,11 @@ function htmlEscape(content) {
});
}

// https://github.com/kangax/html-minifier/issues/63#issuecomment-37763316
function isBooleanAttribute(attribute) {
return (/^(?:allowfullscreen|async|autofocus|autoplay|checked|compact|controls|declare|default|defaultchecked|defaultmuted|defaultselected|defer|disabled|draggable|enabled|formnovalidate|hidden|indeterminate|inert|ismap|itemscope|loop|multiple|muted|nohref|noresize|noshade|novalidate|nowrap|open|pauseonexit|readonly|required|reversed|scoped|seamless|selected|sortable|spellcheck|translate|truespeed|typemustmatch|visible)$/i).test(attribute);
}

/* Renders a singleton attribute key, or a key-value attribute pair,
* HTML-escaping the value. */
function renderAttribute(key, value) {
Expand All @@ -303,11 +314,6 @@ function renderAttribute(key, value) {
}
}

// https://github.com/kangax/html-minifier/issues/63#issuecomment-37763316
function isBooleanAttribute(attribute) {
return (/^(?:allowfullscreen|async|autofocus|autoplay|checked|compact|controls|declare|default|defaultchecked|defaultmuted|defaultselected|defer|disabled|draggable|enabled|formnovalidate|hidden|indeterminate|inert|ismap|itemscope|loop|multiple|muted|nohref|noresize|noshade|novalidate|nowrap|open|pauseonexit|readonly|required|reversed|scoped|seamless|selected|sortable|spellcheck|translate|truespeed|typemustmatch|visible)$/i).test(attribute);
}

function renderStyle(style) {
return Object.keys(style).reduce(function styler(styleString, property) {
return styleString + property + ':' + style[property] + ';';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lmth",
"version": "6.1.0",
"version": "6.2.0",
"description": "A \"type-safe\" HTML DSL for JavaScript environments.",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit 7d6d6f6

Please sign in to comment.