Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
newBase = combinedBases[bases[0]];
const { children } = element;
if (children) {
const currentBase = calculateNewBaseUrls(element.attribs[ATTRIB_CWF], this.rootPath, this.baseUrlMap);
if (currentBase) {
if (currentBase.relative !== newBase) {
cheerio.prototype.options.xmlMode = false;
const newBaseUrl = `{{hostBaseUrl}}/${newBase}`;
const rendered = nunjucks.renderString(cheerio.html(children), {
// This is to prevent the nunjuck call from converting {{hostBaseUrl}} to an empty string
// and let the hostBaseUrl value be injected later.
hostBaseUrl: '{{hostBaseUrl}}',
baseUrl: newBaseUrl,
}, { path: filePath });
element.children = cheerio.parseHTML(rendered, true);
cheerio.prototype.options.xmlMode = true;
}
}
}
}
delete element.attribs[ATTRIB_INCLUDE_PATH];
}
delete element.attribs[ATTRIB_CWF];
return element;
};
import cheerio from 'cheerio'
// This is a hack to cheerio to solve the unwanted encode issue.
// https://github.com/cheeriojs/cheerio/issues/866#issuecomment-275699121
// We don't want cheerio to encode our vue template, as it will add encoded entities into Vue props.
// NOTE: Any HTML encoded entities in original HTML will be kept as it is.
const cheerioHtml = cheerio.prototype.html
cheerio.prototype.html = function wrappedHtml () {
var result = cheerioHtml.apply(this, arguments)
if (typeof result === 'string') {
result = result.replace(/&#x([0-9a-f]{1,6});/ig, function (entity, code) {
code = parseInt(code, 16)
// don't unescape ascii characters, assuming that all ascii characters
// are encoded for a good reason
if (code < 0x80) return entity
return String.fromCodePoint(code)
})
}
return result
var _ = require("underscore");
// Using Cheerio instead of jQuery, because Cheerio emulates a loosely
// compatible API that we further augment to ensure unit tests pass. It is
// also much faster than jsdom.
var $ = require("cheerio");
// Add cheerio hooks
Backbone.View.prototype._createElement = function(tagName) {
var tag = "<" + tagName + ">" + "";
return $.load(tag).root()[0].children[0];
};
// This is to avoid unwanted errors thrown when using
// `Backbone.View#setElement`.
$.prototype.unbind = $.prototype.off = function() { return this; };
// Since jQuery is not being used and LayoutManager depends on a Promise
// implementation close to jQuery, we use `underscore.deferred` here which
// matches jQuery's Deferred API exactly. This is mixed into Cheerio to make
// it more seamless.
_.extend($, require("underscore.deferred"));
// Get Backbone and _ into the global scope.
_.defaults(global, { Backbone: Backbone, _: _ });
// Set the Backbone DOM library to be Cheerio.
Backbone.$ = $;
// Include the LayoutManager source, without eval.
require("../backbone.layoutmanager");
return element.map(el => self._parse(el, context, config));
}
if (isText(element)) {
return element;
}
if (element.name) {
element.name = element.name.toLowerCase();
}
switch (element.name) {
case 'md':
element.name = 'span';
cheerio.prototype.options.xmlMode = false;
element.children = cheerio.parseHTML(md.renderInline(cheerio.html(element.children)), true);
cheerio.prototype.options.xmlMode = true;
break;
case 'markdown':
element.name = 'div';
cheerio.prototype.options.xmlMode = false;
element.children = cheerio.parseHTML(md.render(cheerio.html(element.children)), true);
cheerio.prototype.options.xmlMode = true;
break;
case 'panel': {
if (!_.hasIn(element.attribs, 'src')) { // dynamic panel
break;
}
const fileExists = utils.fileExists(element.attribs.src)
|| utils.fileExists(calculateBoilerplateFilePath(element.attribs.boilerplate,
element.attribs.src, config));
if (fileExists) {
const { src, fragment } = element.attribs;
if (!relative.cheerio) {
relative = this._$(relative);
}
relative.prepend(this);
return this;
};
Cheerio.prototype.replaceAll = function(relative) {
if (!relative.cheerio) {
relative = this._$(relative);
}
relative.replaceWith(this);
return this;
};
Cheerio.prototype.bind = Cheerio.prototype.unbind =
Cheerio.prototype.on = Cheerio.prototype.off =
Cheerio.prototype.live = Cheerio.prototype.die =
Cheerio.prototype.delegate = Cheerio.prototype.undelegate =
Cheerio.prototype.one = function() {
return this;
};
Cheerio.prototype.forEach = function(callback, scope) {
var elements = this;
elements.each(function(index) {
callback.call(scope || elements, this, index);
});
return this;
};
Cheerio.prototype.detach = Cheerio.prototype.remove;
relative.prepend(this);
return this;
};
Cheerio.prototype.replaceAll = function(relative) {
if (!relative.cheerio) {
relative = this._$(relative);
}
relative.replaceWith(this);
return this;
};
Cheerio.prototype.bind = Cheerio.prototype.unbind =
Cheerio.prototype.on = Cheerio.prototype.off =
Cheerio.prototype.live = Cheerio.prototype.die =
Cheerio.prototype.delegate = Cheerio.prototype.undelegate =
Cheerio.prototype.one = function() {
return this;
};
Cheerio.prototype.forEach = function(callback, scope) {
var elements = this;
elements.each(function(index) {
callback.call(scope || elements, this, index);
});
return this;
};
Cheerio.prototype.detach = Cheerio.prototype.remove;
Cheerio.prototype.toggle = function(toggle) {
if (toggle === undefined) {
toggle = this.css('display') === 'none';
var _ = require('lodash'),
Cheerio = require('cheerio');
Cheerio.prototype.appendTo = function(relative) {
if (!relative.cheerio) {
relative = this._$(relative);
}
relative.append(this);
return this;
};
Cheerio.prototype.insertAfter = function(relative) {
if (!relative.cheerio) {
relative = this._$(relative);
}
relative.after(this);
return this;
};
Cheerio.prototype.insertBefore = function(relative) {
if (!relative.cheerio) {
relative = this._$(relative);
this[toggle ? 'show' : 'hide']();
return this;
};
Cheerio.prototype.show = function() {
this.css('display', '');
return this;
};
Cheerio.prototype.hide = function() {
this.css('display', 'none');
return this;
};
Cheerio.prototype.focus = function() {
this.attr('autofocus', 'autofocus');
return this;
};
Cheerio.prototype.blur = function() {
this.removeAttr('autofocus');
return this;
};
Cheerio.prototype.animate = function(properties) {
this.css(properties);
var callback = arguments[arguments.length-1];
if (callback && callback.callback) {
callback = callback.callback;
}
if (callback.call) {
var el = this;
setImmediate(function() {
callback.call(el);
grunt.option('debug',_.includes(process.argv,'--debug'));
grunt.option('stack',_.includes(process.argv,'--stack'));
cheerio.prototype.odd = function() {
var odds = [];
this.each(function(index, item) {
if (index % 2 == 1) {
odds.push(item);
}
});
return cheerio(odds);
};
cheerio.prototype.even = function() {
var evens = [];
this.each(function(index, item) {
if (index % 2 == 0) {
evens.push(item);
}
});
return cheerio(evens);
};
cheerio.prototype.unwrap = function(){
this.parent().each(function(){
var $this = cheerio(this);
$this.replaceWith($this.children());
});
return this;
Cheerio.prototype.on = Cheerio.prototype.off =
Cheerio.prototype.live = Cheerio.prototype.die =
Cheerio.prototype.delegate = Cheerio.prototype.undelegate =
Cheerio.prototype.one = function() {
return this;
};
Cheerio.prototype.forEach = function(callback, scope) {
var elements = this;
elements.each(function(index) {
callback.call(scope || elements, this, index);
});
return this;
};
Cheerio.prototype.detach = Cheerio.prototype.remove;
Cheerio.prototype.toggle = function(toggle) {
if (toggle === undefined) {
toggle = this.css('display') === 'none';
}
this[toggle ? 'show' : 'hide']();
return this;
};
Cheerio.prototype.show = function() {
this.css('display', '');
return this;
};
Cheerio.prototype.hide = function() {
this.css('display', 'none');
return this;