Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// common self closing svg elements
path: true,
circle: true,
ellipse: true,
line: true,
rect: true,
use: true,
stop: true,
polyline: true,
polygon: true
};
/*
* Since htmlparser2 doesn't expose its states, run some tests to grep them
*/
const testParser = new Parser({});
testParser.write('<div></div>
ATTRIBUTE_STATES[IN_ATTRIBUTE_VALUE_NQ] = true;
ATTRIBUTE_STATES[IN_COMMENT] = true;
/**
* Extend Parser to override some built-ins
*
* @param {[type]} cbs [description]
* @param {[type]} opts [description]
*/
function MustacheParser(cbs) {
Parser.call(this, cbs, {
decodeEntities: false,
recognizeSelfClosing: true
});
}
MustacheParser.prototype = new Parser();
MustacheParser.prototype.constructor = MustacheParser;
// Runs when the '=' after an attribute name is encountered
MustacheParser.prototype.onattribname = function(name) {
if (name) {
stack.createObject({
type: 'attributename',
value: name
});
}
stack.createObject({
type: 'attributenameend'
});
};
// Runs when attribute value data has been encountered
const parseDatasets = (markdown) => {
const result = {};
const parser = new HtmlParser({
onopentag(name, attribs) {
if (name === 'dataset') {
result[attribs.name || 'default'] = conformValues(attribs);
}
if (name === 'query') {
result[attribs.name || 'default'] = { url: attribs.url, query: true };
}
}
}, { decodeEntities: true });
parser.parseComplete(markdown);
return result;
};
export default function(incrementalDom) {
const {
attr,
elementClose,
elementOpen,
elementOpenEnd,
elementOpenStart,
elementVoid,
text,
} = incrementalDom
const sanitizeName = name => name.replace(/[^-:\w]/g, '')
const iDOMParser = new Parser(
{
onopentag: name => elementOpenEnd(sanitizeName(name)),
onopentagname: name => elementOpenStart(sanitizeName(name)),
onattribute: (name, value) => {
const sanitizedName = sanitizeName(name)
if (sanitizedName !== '') attr(sanitizedName, value)
},
ontext: text,
onclosetag: name => elementClose(sanitizeName(name)),
},
{
decodeEntities: true,
lowerCaseAttributeNames: false,
lowerCaseTags: false,
}
)