remove md-it dependency, added undefined check to attachments

This commit is contained in:
Michael Lively 2022-07-20 16:10:54 -07:00
parent ff31f6b577
commit 63142212a1
2 changed files with 9 additions and 8 deletions

View file

@ -87,7 +87,6 @@
"dependencies": {
"@enonic/fnv-plus": "^1.3.0",
"detect-indent": "^6.0.0",
"markdown-it": "^12.3.2",
"uuid": "^8.3.2"
},
"devDependencies": {

View file

@ -22,14 +22,16 @@ export async function activate(ctx: RendererContext<void>) {
md.renderer.rules.image = (tokens: MarkdownItToken[], idx: number, options, env, self) => {
const token = tokens[idx];
const src = token.attrGet('src');
const attachments: Record<string, Record<string, string>> = (env.outputItem.metadata as any).custom.attachments;
if (attachments) {
if (src) {
const [attachmentKey, attachmentVal] = Object.entries(attachments[src.replace('attachment:', '')])[0];
const b64Markdown = 'data:' + attachmentKey + ';base64,' + attachmentVal;
token.attrSet('src', b64Markdown);
}
// if (env.outputItem.metadata?.custom?.attachments) {
// const attachments: Record<string, Record<string, string>> = (env.outputItem.metadata as any).custom.attachments;
const attachments: Record<string, Record<string, string>> = env.outputItem.metadata?.custom?.attachments;
if (attachments && src) {
const [attachmentKey, attachmentVal] = Object.entries(attachments[src.replace('attachment:', '')])[0];
const b64Markdown = 'data:' + attachmentKey + ';base64,' + attachmentVal;
token.attrSet('src', b64Markdown);
}
// }
//
if (original) {
return original(tokens, idx, options, env, self);