-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make tag information accessible during runtime
- Loading branch information
Showing
5 changed files
with
195 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @typedef {{ | ||
attributes: { | ||
[attributeName: string]: string | boolean; | ||
}; | ||
tagName: string; | ||
innerHTML?: string | undefined; | ||
voidTag: boolean; | ||
meta: any | ||
} | ||
} HtmlTagObject | ||
*/ | ||
|
||
/** | ||
* Turn a tag definition into a html string | ||
* @param {HtmlTagObject} tagDefinition | ||
* A tag element according to the htmlWebpackPlugin object notation | ||
* | ||
* @param xhtml {boolean} | ||
* Wether the generated html should add closing slashes to be xhtml compliant | ||
*/ | ||
function htmlTagObjectToString(tagDefinition, xhtml) { | ||
const attributes = Object.keys(tagDefinition.attributes || {}) | ||
.filter(function(attributeName) { | ||
return tagDefinition.attributes[attributeName] !== false; | ||
}) | ||
.map(function(attributeName) { | ||
if (tagDefinition.attributes[attributeName] === true) { | ||
return xhtml | ||
? attributeName + '="' + attributeName + '"' | ||
: attributeName; | ||
} | ||
return ( | ||
attributeName + '="' + tagDefinition.attributes[attributeName] + '"' | ||
); | ||
}); | ||
return ( | ||
'<' + | ||
[tagDefinition.tagName].concat(attributes).join(' ') + | ||
(tagDefinition.voidTag && xhtml ? '/' : '') + | ||
'>' + | ||
(tagDefinition.innerHTML || '') + | ||
(tagDefinition.voidTag ? '' : '</' + tagDefinition.tagName + '>') | ||
); | ||
} | ||
|
||
module.exports = { htmlTagObjectToString }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters