Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
).join("");
}
throw Error(
`Unknown templateUsages type ${typeof templateUsages} from aCode.variables[${key}]. aCode = ${JSON.stringify(
aCode
)}. templateUsages: ${JSON.stringify(templateUsages)}`
);
};
// When there are attribute variable placeholders side-by-side
// then add a space.
// FIXME: Use a bloody HTML parser for all this code
html = html.replace(/\}\}\{\{/g, "}} {{");
html = await stringReplaceAsync(
html,
/{{(.*?)}}/gi,
async (match, middle) => {
const dynamicKey: DynamicKey = parseDynamicKey(middle);
validateDynamicKey(dynamicKey);
return draw(dynamicKey, true, dynamicKey.type as EnumOption[]);
}
);
// Some attributes will be valueless eg disabled="" which is considered
// false so we shouldn't render the attribute at all.
html = html.replace(/[a-zA-Z][a-zA-Z0-9-]+?="\s*"/gi, "");
// and certain boolean attributes should be converted to valueless
html = html.replace(/([a-zA-Z][a-zA-Z0-9-]+?)="true"/gi, (match, p1) => {
if (match.includes("value=")) {
// TODO: compare against HTML5 boolean attributes
if (!key) throw Error(`Couldn't find key in "${match}"`);
const value = (aCode as TemplateUsageElement).variables[key];
if (!!value) {
const response = match
.substring(match.indexOf(">") + 1)
.replace("", "");
return response;
} else {
return "";
}
}
);
html = await stringReplaceAsync(
html,
//gi,
async match => {
// self-closing
const key = getAttr(match, "key");
if (!key) throw Error(`Couldn't find key in "${match}"`);
return await renderByVariableElementKey(key);
}
);
html = await stringReplaceAsync(
html,
/([\s\S]*?)<\/mt-variable>/gi,
async (match, defaultValue) => {
// expanded placeholder
const key = getAttr(match, "key");
}
);
// Some attributes will be valueless eg disabled="" which is considered
// false so we shouldn't render the attribute at all.
html = html.replace(/[a-zA-Z][a-zA-Z0-9-]+?="\s*"/gi, "");
// and certain boolean attributes should be converted to valueless
html = html.replace(/([a-zA-Z][a-zA-Z0-9-]+?)="true"/gi, (match, p1) => {
if (match.includes("value=")) {
// TODO: compare against HTML5 boolean attributes
return match;
}
return p1;
});
html = await stringReplaceAsync(
html,
//gi,
async match => {
// FIXME: obviously regexes and HTML don't mix well
// so if nested this will break. Replace with proper parser.
const key = getAttr(match, "key");
if (!key) throw Error(`Couldn't find key in "${match}"`);
const value = (aCode as TemplateUsageElement).variables[key];
if (!!value) {
const response = match
.substring(match.indexOf(">") + 1)
.replace("", "");
return response;
} else {
export async function wikiTextToHTML(wikitext, slug) {
let html = InstaView.convert(wikitext);
html = await stringReplaceAsync(html, /ARTICLENAMEGOESHERE(.*?)(['"])/g, async (all, article, quote) => {
let wiki;
if(article.indexOf(":") == -1) {
// Local link
wiki = slug;
} else {
// Interwiki
article = article.replace(/^:/, "");
wiki = article.substr(0, article.indexOf(":"));
article = article.substr(article.indexOf(":") + 1);
wiki = toSlug(wiki.replace("/", "MYAWESOMECONSTANT")).replace(toSlug("MYAWESOMECONSTANT"), "/");
}
article = toSlug(article);
}
}
);
html = await stringReplaceAsync(
html,
//gi,
async match => {
// self-closing
const key = getAttr(match, "key");
if (!key) throw Error(`Couldn't find key in "${match}"`);
return await renderByVariableElementKey(key);
}
);
html = await stringReplaceAsync(
html,
/([\s\S]*?)<\/mt-variable>/gi,
async (match, defaultValue) => {
// expanded placeholder
const key = getAttr(match, "key");
if (!key) throw Error(`Couldn't find key in "${match}"`);
return await renderByVariableElementKey(key, defaultValue);
}
);
return html;
};
return async source => stringReplaceAsync(await source, clauseRegexp, replacer)
}
return async (source) => {
const result = await stringReplaceAsync(await source, pluralRegexp, replacer)
return result.includes(moduleNamespace)
? `const ${moduleNamespace} = ${stringify((await dictionary()).methods)};\n`.concat(result)
: result
}
}