Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// remove article body-enclosing div (class "threed-sidebar-article-body"), then re-parent children
const bodyDiv = DomUtils.findOne(elem =>
elem.attribs && elem.attribs.class && elem.attribs.class.indexOf("threed-sidebar-article-body") >= 0,
contentDiv.children, true);
if (bodyDiv) {
const parent: any = bodyDiv.parent;
bodyDiv.children.forEach(child => DomUtils.appendChild(parent, child));
DomUtils.removeElement(bodyDiv);
}
const title = DomUtils.findOne(elem => elem.name === "h1",
contentDiv.children, true);
const titleText = title && DomUtils.getText(title);
article.title = titleText || `Article No. ${index + 1}`;
let imageIndex = 0;
const imageUrls: Dictionary = {};
DomUtils.findOne(elem => {
// download images
if (elem.name === "img" && elem.attribs && elem.attribs.src) {
const src = elem.attribs.src;
const imageUrl = src.startsWith("http") ? src : this.parameters.drupalBaseUrl + src;
const imageName = filenamify(decodeURIComponent(src.split("/").pop()));
const imageFileName = `article-${articleIndex}-${imageName}`;
const imageAssetPath = `${this.articlesDir}/${imageFileName}`;
this.result.files[`scene_${imageAssetPath}`] = imageAssetPath;
elem.attribs.src = imageFileName; // relative to location of html file
// remove article body-enclosing div (class "threed-sidebar-article-body"), then re-parent children
const bodyDiv = DomUtils.findOne(elem =>
elem.attribs && elem.attribs.class && elem.attribs.class.indexOf("threed-sidebar-article-body") >= 0,
contentDiv.children, true);
if (bodyDiv) {
const parent: any = bodyDiv.parent;
bodyDiv.children.forEach(child => DomUtils.appendChild(parent, child));
DomUtils.removeElement(bodyDiv);
}
const title = DomUtils.findOne(elem => elem.name === "h1",
contentDiv.children, true);
const titleText = title && DomUtils.getText(title);
article.title = titleText || `Article No. ${index + 1}`;
let imageIndex = 0;
const imageUrls: Dictionary = {};
DomUtils.findOne(elem => {
// download images
if (elem.name === "img" && elem.attribs && elem.attribs.src) {
const src = elem.attribs.src;
const imageUrl = src.startsWith("http") ? src : context.drupalBaseUrl + src;
const imageName = filenamify(decodeURIComponent(src.split("/").pop()));
const imageFileName = `article-${articleIndex}-${imageName}`;
const imageAssetPath = `${context.articleDir}/${imageFileName}`;
context.files[imageAssetPath] = imageAssetPath;
elem.attribs.src = imageFileName; // relative to location of html file
max_depth: 6
}, options);
const headingsSelector = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].slice(options.min_depth - 1, options.max_depth).join(',');
const dom = parseHtml(str);
const headings = DomUtils.find(el => headingsSelector.includes(el.tagName), dom, true);
const result = [];
if (!headings.length) return result;
for (const el of headings) {
const level = +el.name[1];
const id = getId(el);
const text = escapeHTML(DomUtils.getText(el));
result.push({ text, id, level });
}
return result;
}