microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.44k stars 28.62k forks source link

crash about markdown env.containingImages #117112

Closed qjebbs closed 3 years ago

qjebbs commented 3 years ago

Steps to Reproduce:

  1. vsocde markdown feature recently (1.53) add a lazy load image feature(?) by contributing a new plugin to markdwon-it
  2. the plugin requires env.containingImages, which is initialized in preview feature
  3. when I call markdownit.render other places without env.containingImages, it crashes

that's why this issue happens: https://github.com/qjebbs/vscode-markdown-extended/issues/98

and I temporarily fix it with: https://github.com/qjebbs/vscode-markdown-extended/commit/e68b60a1e08cb5602e7a7a6705e91d8094ea9fb5

But it's not elegant, could you pls add one line to initialize it?

// e.renderer.rules.image=(e,n,r,i,o)=>{const s=e[n];s.attrJoin("class","loading");const l=s.attrGet("src");if(l){i.containingImages.push({src:l});const e=a.hash(l);s.attrSet("id","image-hash-"+e)}return t?t(e,n,r,i,o):o.renderToken(e,n,r,i,o)}
e.renderer.rules.image = (e, n, r, i, o) => {
    const s = e[n];
    s.attrJoin("class", "loading");
    const l = s.attrGet("src");
    if (l) {
        // add this line
        if(!i.containingImages) i.containingImages=[];
        i.containingImages.push({
            src: l
        });
        const e = a.hash(l);
        s.attrSet("id", "image-hash-" + e)
    }
    return t ? t(e, n, r, i, o) : o.renderToken(e, n, r, i, o)
}
mjbvz commented 3 years ago

Is this a duplicate of #116987?

manuth commented 3 years ago

Yeah, it's the same issue - should be fixed by my most recent PR #117041

mjbvz commented 3 years ago

Thanks. Please test the next insiders build and let me know if the issue has not been fixed