course-renderer
Version:
Manages CA School Courses file system storage and HTML conversion
32 lines (31 loc) • 972 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const cheerio = require("cheerio");
function anchor(tokens) {
return _anchor(tokens);
}
exports.anchor = anchor;
function _anchor(tokens) {
tokens.forEach((token) => {
if (token.content) {
const ch = cheerio.load(token.content);
ch.root().find('a').each((idx, ele) => {
ch(ele).attr('target', '_blank');
});
token.content = ch.html();
}
if (token.choices) {
token.choices = token.choices.map((ele) => {
const choiceCH = cheerio.load(ele);
choiceCH.root().find('a').each((idx, ele) => {
choiceCH(ele).attr('target', '_blank');
});
return choiceCH.html();
});
}
if (token.children instanceof Array) {
_anchor(token.children);
}
});
return tokens;
}