Skip to content

Commit

Permalink
dep update, linting update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Escalante committed May 8, 2019
1 parent 9277b2d commit faf627f
Show file tree
Hide file tree
Showing 5 changed files with 6,122 additions and 38 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ coverage
.nyc_output
.travis.yml
contributing.md
.prettierrc
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"semi": false,
"singleQuote": true
}
181 changes: 151 additions & 30 deletions lib/index.js
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'
]
Loading

0 comments on commit faf627f

Please sign in to comment.