简体   繁体   English

Monaco Editor (TypeScript):用更多按钮/链接/动作装饰 JSDoc 或 TSDoc

[英]Monaco Editor (TypeScript): Decorate JSDoc or TSDoc with further buttons/links/actions

I'm using Microsoft Monaco Editor for TypeScript language.我正在为 TypeScript 语言使用 Microsoft Monaco Editor。 The TypeScript classes and functions have JSDoc. TypeScript 类和函数有 JSDoc。 I'd like to add buttons/links/etc.我想添加按钮/链接/等。 to the existing JSDoc in order to invoke a JavaScript function when the user clicks on them in the code completion.到现有的 JSDoc,以便在用户在代码完成中单击它们时调用 JavaScript function。

It seems that I cannot simply put HTML with JavaScript into the existing JSDoc.看来我不能简单地将 HTML 和 JavaScript 放入现有的 JSDoc 中。 Is it possible to attach any buttons to the JSDoc displayed by the code completion, belatedly?是否可以将任何按钮附加到代码完成显示的 JSDoc,迟到? I want to add them to the already existing JSDoc.我想将它们添加到已经存在的 JSDoc 中。

https://microsoft.github.io/monaco-editor/playground.html https://microsoft.github.io/monaco-editor/playground.html

const editor = monaco.editor.create(document.getElementById("container"), {
    value: "/** This is the basic JSDoc <span onclick='alert()'>my button</span>*/" +
           "function hello(param: number): string {\n\talert('Hello world!');\nreturn '';\n}",
    language: "typescript"
});

monaco.languages.registerCompletionItemProvider('javascript', {
    resolveCompletionItem: function(item, token) {
        alert(item);
    }
});

This is not possible.这是不可能的。 The API for completion items only accepts markdown text (or plain text), not HTML.完成项目的 API 仅接受 markdown 文本(或纯文本),不接受 HTML。

While I agree with the original answer saying that this isn't possible because the API will never render HTML, you could still go a long way decorating with plain Markdown. While I agree with the original answer saying that this isn't possible because the API will never render HTML, you could still go a long way decorating with plain Markdown. And intercepting undesirable API behaviors is pretty much the whole reason why the Proxy object exists.拦截不良 API 行为几乎是代理 object 存在的全部原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM