function exprToHtml(expr, ctx) {
return formatExpr(expr, name => {
const targetNode = ctx[name];
const targetLib = defaultCtx[name];
if (targetNode) {
const bg = targetNode instanceof Fun ? '#eee' : '#fea';
return `<span style="display: inline-block; border-radius: 3px; border: 1px solid lightgray; padding: 0 5px; background: ${bg}; margin: 3px 0; font-family: sans-serif">${targetNode.meta.title}</span>`;
} else if (targetLib) {
const bg = (targetLib.type === types.polymorphic || targetLib.type === types.function) ? '#eee' : '#fea';
if (/^[a-z_]+$/gi.test(name)) {
return `<span style="display: inline-block; border-radius: 3px; border: 1px solid lightgray; padding: 0 5px; background: ${bg}; margin: 3px 0">${targetLib.value ? targetLib.value[0].name : name}</span>`;
} else {
return targetLib.value ? targetLib.value[0].name : name;
}
} else {
throw new Error(`Name ${expr[1]} not found in context`);
}
})
}