docsifyjs / docsifyjs/docsify

async compiler

未关闭
#1,433 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
help wanted needs discussion pr welcome
主要语言
JavaScript
星标
31.5k
派生
5.8k
平均合并
9 天 8 小时
30 天内合并 PR
2

描述

## Feature request

#### What problem does this feature solve?

Returning a promise from the function passed to `vm.config.renderer.code` doesn't work as one would expect.

I wanted to use an async method (`crypto.subtle.digest` in my mermaid plugin:

```js
hook.mounted(function() {
const renderer = vm.config.markdown.renderer
const original = renderer.code || renderer.origin.code

renderer.code = renderer.origin.code = async function(code, lang) {
if (lang === 'mermaid') {
const sha256 = Array.from(new Uint8Array(await window.crypto.subtle.digest('SHA-256', new TextEncoder().encode(code)))).map(b => b.toString(16).padStart(2, '0')).join('')
const mermaidId = `mermaid-svg-${sha256}`
return `${mermaid.render(mermaidId, code)}`
}
else return original.apply(this, arguments)
}
})
```

But all my code fences are now being replaced, in the HTML document, with:

```html
[object Promise]
```

#### What does the proposed API look like?

No change, but the compiler should be promise-aware (so that when the result of calling a function is a promise, it awaits it).

#### How should this be implemented in your opinion?

I'm not sure how the compiler works at the moment.

#### Are you willing to work on this yourself?

If time allows, which is probably negative :-/

贡献指南

打开贡献指南

调研方向

首先跟踪编译器如何调用 `vm.config.renderer.code`,以及其返回值如何变成 HTML,尤其是在 `renderer.code` 返回 promise 时。完成标准是等待异步 renderer 结果,同时保持现有的同步代码围栏渲染不变;该 issue 未指定要运行的文件或测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
web-dev
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。