-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jeff Escalante
committed
May 8, 2019
1 parent
9277b2d
commit faf627f
Showing
5 changed files
with
6,122 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ coverage | |
.nyc_output | ||
.travis.yml | ||
contributing.md | ||
.prettierrc |
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,4 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true | ||
} |
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 |
---|---|---|
@@ -1,44 +1,165 @@ | ||
const {modifyNodes} = require('reshape-plugin-util') | ||
const { modifyNodes } = require('reshape-plugin-util') | ||
|
||
module.exports = function reshapeCustomElements (options = {}) { | ||
module.exports = function reshapeCustomElements(options = {}) { | ||
const defaultTag = options.defaultTag || 'div' | ||
const skipTags = options.skipTags || [] | ||
|
||
return function (tree) { | ||
return modifyNodes(tree, (node) => { | ||
return (node.type === 'tag' && (htmlTags.indexOf(node.name) < 0 || skipTags.indexOf(node.name) > -1)) | ||
}, (node) => { | ||
// look for a class attribute | ||
if (!node.attrs) { node.attrs = {} } | ||
if (!node.attrs.class) { node.attrs.class = [] } | ||
return function(tree) { | ||
return modifyNodes( | ||
tree, | ||
node => { | ||
return ( | ||
node.type === 'tag' && | ||
(htmlTags.indexOf(node.name) < 0 || skipTags.indexOf(node.name) > -1) | ||
) | ||
}, | ||
node => { | ||
// look for a class attribute | ||
if (!node.attrs) { | ||
node.attrs = {} | ||
} | ||
if (!node.attrs.class) { | ||
node.attrs.class = [] | ||
} | ||
|
||
// if there's already the same class, return | ||
if (node.attrs.class.find((n) => n.content === node.name)) { | ||
node.name = defaultTag | ||
return node | ||
} | ||
// if there's already the same class, return | ||
if (node.attrs.class.find(n => n.content === node.name)) { | ||
node.name = defaultTag | ||
return node | ||
} | ||
|
||
// if there is already a class, add a space | ||
if (node.attrs.class.length > 0) { | ||
// if there is already a class, add a space | ||
if (node.attrs.class.length > 0) { | ||
node.attrs.class.push({ | ||
type: 'text', | ||
content: ' ', | ||
location: node.location | ||
}) | ||
} | ||
|
||
// push the new class name | ||
node.attrs.class.push({ | ||
type: 'text', | ||
content: ' ', | ||
content: node.name, | ||
location: node.location | ||
}) | ||
} | ||
|
||
// push the new class name | ||
node.attrs.class.push({ | ||
type: 'text', | ||
content: node.name, | ||
location: node.location | ||
}) | ||
|
||
// set the name to the default and return | ||
node.name = defaultTag | ||
return node | ||
}) | ||
// set the name to the default and return | ||
node.name = defaultTag | ||
return node | ||
} | ||
) | ||
} | ||
} | ||
|
||
const htmlTags = ['a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'keygen', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'menu', 'menuitem', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr'] | ||
const htmlTags = [ | ||
'a', | ||
'abbr', | ||
'address', | ||
'area', | ||
'article', | ||
'aside', | ||
'audio', | ||
'b', | ||
'base', | ||
'bdi', | ||
'bdo', | ||
'blockquote', | ||
'body', | ||
'br', | ||
'button', | ||
'canvas', | ||
'caption', | ||
'cite', | ||
'code', | ||
'col', | ||
'colgroup', | ||
'datalist', | ||
'dd', | ||
'del', | ||
'details', | ||
'dfn', | ||
'dialog', | ||
'div', | ||
'dl', | ||
'dt', | ||
'em', | ||
'embed', | ||
'fieldset', | ||
'figcaption', | ||
'figure', | ||
'footer', | ||
'form', | ||
'h1', | ||
'h2', | ||
'h3', | ||
'h4', | ||
'h5', | ||
'h6', | ||
'head', | ||
'header', | ||
'hr', | ||
'html', | ||
'i', | ||
'iframe', | ||
'img', | ||
'input', | ||
'ins', | ||
'kbd', | ||
'keygen', | ||
'label', | ||
'legend', | ||
'li', | ||
'link', | ||
'main', | ||
'map', | ||
'mark', | ||
'menu', | ||
'menuitem', | ||
'meta', | ||
'meter', | ||
'nav', | ||
'noscript', | ||
'object', | ||
'ol', | ||
'optgroup', | ||
'option', | ||
'output', | ||
'p', | ||
'param', | ||
'pre', | ||
'progress', | ||
'q', | ||
'rp', | ||
'rt', | ||
'ruby', | ||
's', | ||
'samp', | ||
'script', | ||
'section', | ||
'select', | ||
'small', | ||
'source', | ||
'span', | ||
'strong', | ||
'style', | ||
'sub', | ||
'summary', | ||
'sup', | ||
'table', | ||
'tbody', | ||
'td', | ||
'textarea', | ||
'tfoot', | ||
'th', | ||
'thead', | ||
'time', | ||
'title', | ||
'tr', | ||
'track', | ||
'u', | ||
'ul', | ||
'var', | ||
'video', | ||
'wbr' | ||
] |
Oops, something went wrong.