Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function render (obj, def, html) {
var i, nodes, handler, parser, element, elementPrototype
// If given bindings with a root node, pick only the binding keys.
if (Array.isArray(def)) def = def[1]
// Generating the render function is processing intensive. Skip if possible.
if (renderFnKey in def) return def[renderFnKey](obj)
// Callback API looks weird. This is actually synchronous, not asynchronous.
handler = new htmlParser.DomHandler(function (error, result) {
if (error) throw error
nodes = result
}, handlerOptions)
parser = new htmlParser.Parser(handler)
parser.write(html)
parser.end()
for (i = nodes.length; i--;)
if (nodes[i].type === 'tag') {
element = nodes[i]
break
}
if (!element) throw new Error('No element found!')
return new Promise(resolve => {
const handler = new HtmlParser.DomHandler((err, dom) => {
if (err) console.log(err);
else {
let tags = self.parseTags(dom);
resolve(tags);
}
});
const parser = new HtmlParser.Parser(handler);
parser.write(ctx.content);
parser.end();
});
},
this.gDrive.files.export({ fileId, mimeType }, (err, response) => {
if (err) {
return callback(err)
}
const docHtml = response.data
const handler = new htmlparser.DomHandler((error, dom) => {
if (error) {
console.error('(DomHandler)', error)
}
const tagHandlers = {
_base: (tag) => {
let str = ''
tag.children.forEach(function (child) {
const transform = tagHandlers[child.name || child.type]
if (transform) {
str += transform(child)
}
})
return str
},
text: (textTag) => {
return textTag.data
module.exports = function parseHTML (source) {
var handler = new htmlparser2.DomHandler()
var parser = new htmlparser2.Parser(handler, { lowerCaseTags: false, lowerCaseAttributeNames: false, xmlMode: true })
parser.write(source)
parser.done()
trimWhitespace(handler.dom)
if (handler.dom.length === 0) {
assert(false, 'rel: no DOM elements returned!')
}
assert.strictEqual(handler.dom[0].type, 'tag',
'rel: you need to pass HTML elements into rel`...`!'
)
assert.strictEqual(handler.dom.length, 1,
'rel: like with JSX, you can only create a single element. Try returning an array of rel`...` strings instead!')
return handler.dom[0]
}
this.getPreview = function(html, callback){
switch(this.previewStyle) {
case 'short':
var handler = new htmlparser.DomHandler(function(err, dom) {
if (err) {
throw err;
} else {
callback(select(dom, 'p')[0].children[0].data);
}
});
var parse = new htmlparser.Parser(handler);
parse.write(html);
parse.done();
break;
}
};
export function getDomObject(html) {
const handler = new htmlparser.DomHandler();
const parser = new htmlparser.Parser(handler, {
xmlMode: true
});
parser.parseComplete(html);
return handler.dom;
}
function getDomObject(html) {
const handler = new htmlparser.DomHandler();
const parser = new htmlparser.Parser(handler, {
xmlMode: true
});
parser.parseComplete(html);
return handler.dom;
}
function parseDOMStreaming(elemCb) {
const handler = new htmlparser.DomHandler(
() => {
logger.debug("done parsing dom")
},
undefined,
elem => {
logger.debug("got an element!", elem.attribs)
elemCb(elem)
}
)
return new WritableParser(handler)
}
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data) {
let handler = new htmlparser.DomHandler(function (error, dom) {
if (error) {
callback(error,null,null);
}
else {
//Path to table responsive is children[3].children[7].children[1].children[3].children[9].children[7].children[3].children[3]
//Path to table is dom[4].children[3].children[7].children[1].children[3].children[9].children[7].children[3].children[3].children[1]
//Path to table head is dom[4].children[3].children[7].children[1].children[3].children[9].children[7].children[3].children[3].children[1].children[1].name);
//Path to table body is dom[4].children[3].children[7].children[1].children[3].children[9].children[7].children[3].children[3].children[1].children[3].name);
//Table body holds tr. Each tr corresponds to one master thesis
let tableBody = dom[4].children[3].children[7].children[1].children[3].children[9].children[7].children[3].children[3].children[1].children[3];
tableBody.children.forEach((element)=> {
if (element.type === "tag" && element.name === "tr") {