简体   繁体   English

如何扩展 VS Code 的 markdown-it 解析器以在其或 Marp 扩展的预览中使用 markdown-it-attrs 扩展并将其导出到 Powerpoint?

[英]How can I extend VS Code's markdown-it parser to use the markdown-it-attrs extension in its or Marp extension's preview & export it to Powerpoint?

In VS code, I would like to define custom css classes on markdown elements for outputting to a Powerpoint file that I could use for giving presentations to groups of people.在 VS 代码中,我想在 markdown 元素上定义自定义 css 类,以输出到 Powerpoint 文件,我可以使用该文件向一群人进行演示。 In HTML, I could add class="my-favorite-class" to an HTML element and then have.my-favorite-class in the CSS style sheet.在 HTML 中,我可以将 class="my-favorite-class" 添加到 HTML 元素,然后在 CSS 样式表中添加 .my-favorite-class。 The markdown-it parser can be extended with this functionality (see https://github.com/arve0/markdown-it-attrs ), and the author of that extension responded to an earlier post, "Can I define a class name on paragraph using Markdown?" markdown-it 解析器可以使用此功能进行扩展(参见https://github.com/arve0/markdown-it-attrs ),并且该扩展的作者回复了之前的帖子,“我可以定义一个 class 名称吗?使用 Markdown 的段落?” (see Can I define a class name on paragraph using Markdown? ), and he laid out how one would do this if one's environment were javascript. (请参阅我可以使用 Markdown 在段落上定义一个 class 名称吗? ),并且他列出了如果一个人的环境是 javascript 将如何做到这一点。

I have not used VS Code much, but if what he wrote there applies to VS Code, where would I put in VS Code what he wrote in his response?我使用 VS Code 的次数不多,但如果他在那里写的内容适用于 VS Code,我会把他在回复中写的内容放在 VS Code 的什么地方? If it does not apply, is there a way to get VS Code to recognize that markdown-it-attrs extension and convert the custom classes defined in curly brackets {} to be interpreted as CSS classes for the purpose of the VS code markdown preview and VS code Powerpoint markdown export?如果它不适用,有没有办法让 VS Code 识别 markdown-it-attrs 扩展并将大括号 {} 中定义的自定义类转换为 CSS 类,以便 VS 代码 markdown 预览和VS 代码 Powerpoint markdown 导出?

Also, if I were to use the Marp markdown plugin in VS code, would it be possible to get it to recognize the custom defined CSS classes?另外,如果我在 VS 代码中使用 Marp markdown 插件,是否可以让它识别自定义定义的 CSS 类? If one goes to https://marpit.marp.app/usage?id=extend-marpit-by-plugins there are directions for how to get the markdown-it-container extension to be recognized (in a node.js environment?), but how would one get that extension or the markdown-it-attrs extension to be recognize by the vanilla VS Code markdown preview or the Marp extension markdown preview in VS code, and also for Powerpoint export?如果去https://marpit.marp.app/usage?id=extend-marpit-by-plugins那里有关于如何识别 markdown-it-container 扩展的说明(在 node.js 环境中?),但是如何让 vanilla VS Code markdown 预览或 VS 代码中的 Marp 扩展 markdown 预览识别该扩展或 markdown-it-attrs 扩展,以及用于 Powerpoint 导出?

In this Stack Overflow post ( How to integrate markdown-it-emoji into VS Code ), Matt Bierner gave a VS Code Github link for issue 22916 ( How to integrate markdown-it-emoji into VS Code ).在这篇 Stack Overflow 帖子( 如何将 markdown-it-emoji 集成到 VS Code中)中,Matt Bierner 为问题 22916( 如何将 markdown-it-emoji 集成到 VS Code 中)提供了 VS Code Github 链接。 If one clicks on that link, Matt's July 17, 2017 post has 'The API has changed slightly since the initial proposal.如果点击该链接,Matt 在 2017 年 7 月 17 日发布的帖子会显示“API 自最初提案以来略有变化。 The most up to date documentation is now in a pre-release version the VS Code docs: https://github.com/Microsoft/vscode-docs/blob/vnext/docs/extensionAPI/api-markdown.md' , but if I click on that link, I get a 404. So that was a dead end for me.最新的文档现在是 VS Code 文档的预发布版本: https://github.com/Microsoft/vscode-docs/blob/vnext/docs/extensionAPI/api-markdown.md' ,但如果我点击那个链接,我得到一个 404。所以这对我来说是一个死胡同。 If I go back to his instructions for the emoji extension for VS code, one of his directions is to 'Install the VSIX from the extension repo', but I am not sure what he is referring to in the Github files available.如果我 go 回到他关于 VS 代码的表情符号扩展的说明,他的说明之一是“从扩展存储库安装 VSIX”,但我不确定他在 Github 可用文件中指的是什么。

In light of all this, I am at a loss as to how to get the markdown-it-attrs installed or set up such that VS code preview and the Marp extension for Markdown preview would both interpret the markdown-it-attrs method of adding custom CSS classes to markdown elements in the proper way, and also how to get VS Code and and Marp to export the preview into a Powerpoint file.鉴于这一切,我不知道如何安装或设置 markdown-it-attrs,以便 VS 代码预览和 Markdown 预览的 Marp 扩展都可以解释添加的 markdown-it-attrs 方法以正确的方式将 CSS 类自定义为 markdown 元素,以及如何获取 VS Code 和 Marp 以将预览导出到 Powerpoint 文件中。

With a background in web development (among other things), I would love to have this functionality to more easily develop presentations for the work that I will be doing in giving presentations to groups of people.凭借 web 开发(除其他事项外)的背景,我希望拥有此功能,以便更轻松地为我将在向人群进行演示时所做的工作开发演示文稿。 If I can get it work, I think it could be significantly easier than fiddling with Powerpoint or Keynote programs.如果我能让它工作,我认为它比摆弄 Powerpoint 或 Keynote 程序要容易得多。 Please help.请帮忙。

I installed npm on my Mac, and then installed the markdown-it-attrs (I think with the "npm install --save markdown-it-attrs" in Terminal. See https://www.npmjs.com/package/markdown-it-attrs ).我在我的 Mac 上安装了 npm,然后安装了 markdown-it-attrs(我想在终端中使用“npm install --save markdown-it-attrs”。参见https://www.npmjs.com/package/markdown -it-属性)。 Then I started VS Code, and I tried putting {.style-me} after # Header 2 and VS Code Preview did not treat that as adding a.style-me class. Neither did the Marp VS Code extension.然后我启动了 VS Code,我尝试将 {.style-me} 放在 # Header 2 之后,VS Code Preview 没有将其视为添加 a.style-me class。Marp VS Code 扩展也没有。 So I don't know what to do.所以我不知道该怎么办。

To use the markdown-it-attrs extension in VS Code, you would need to create a new markdown parser that uses markdown-it-attrs and then configure VS Code to use that parser.要在 VS Code 中使用 markdown-it-attrs 扩展,您需要创建一个使用 markdown-it-attrs 的新解析器 markdown,然后配置 VS Code 以使用该解析器。 This can be done by creating a new extension for VS Code that uses the markdown-it-attrs extension.这可以通过为使用 markdown-it-attrs 扩展的 VS Code 创建一个新扩展来完成。 However, this process is not straightforward and requires some knowledge of JavaScript and the VS Code extension API.然而,这个过程并不简单,需要一些 JavaScript 和 VS Code 扩展 API 的知识。

As for the Marp markdown plugin, it is not clear if it can be configured to recognize custom CSS classes defined with markdown-it-attrs, as the Marp plugin is a separate tool that uses its own markdown parser.至于 Marp markdown 插件,目前尚不清楚它是否可以配置为识别使用 markdown-it-attrs 定义的自定义 CSS 类,因为 Marp 插件是一个单独的工具,使用它自己的 markdown 解析器。

// vscode-markdown-it-attrs.js

const vscode = require('vscode');
const markdownIt = require('markdown-it');
const markdownItAttrs = require('markdown-it-attrs');

function activate(context) {
// Use markdown-it to parse markdown
const md = markdownIt({html: true,linkify: true, typographer: true
}).use(markdownItAttrs);

// Register a new markdown preview provider
vscode.workspace.registerTextDocumentContentProvider('markdown-it-attrs', {
provideTextDocumentContent: (uri) => {
  const document = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === uri.toString());
  if (document) {
    return md.render(document.getText());
  }
  return '';
}
});

// Register a new command to open the markdown-it-attrs preview
 vscode.commands.registerCommand('markdown-it-attrs.openPreview', (uri) => {
 vscode.commands.executeCommand('vscode.previewHtml', URI, 
 vscode.ViewColumn.Two, 'Markdown with Attrs').then((success) => {
}, (reason) => {
  vscode.window.showErrorMessage(reason);
});
});

// Add a context menu item to open the markdown-it-attrs preview
 vscode.window.registerContextMenuProvider({
  provideContextMenu: (menu) => {
   menu.items.push({
    command: 'markdown-it-attrs.openPreview',
    title: 'Open Markdown with Attrs Preview',
     group: '1_preview'
   });
  }
});

}

exports.activate = activate;

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

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