轻松记录您
灵感和创意

将HTML转换为Markdown

One of my biggest mistakes with this blog was not finding a WordPress plugin that would allow me to write my posts with Markdown; to this day I still need to write posts in “Visual” mode and then manually convert the post to HTML for “Text” mode.  One of these days I want to convert existing posts to Markdown and then enable a plugin that will convert Markdown to HTML. This painful process made me ask myself:  is there a way I can use Node.js JavaScript to convert HTML to Markdown?  There is, and it’s called Turndown by Dom Christie.

我在此博客中遇到的最大错误之一就是找不到WordPress插件,该插件可以让我用Markdown撰写帖子; 到目前为止,我仍然需要以“可视”模式编写帖子,然后将帖子手动转换为“文本”模式HTML。 这些天之一,我想将现有帖子转换为Markdown,然后启用一个将Markdown转换为HTML的插件。 这个痛苦的过程使我问自己:是否可以使用Node.js JavaScript将HTML转换为Markdown? 有,它被Dom Christie称为Turndown 。

Convert HTML to Markdown with Node.js 使用Node.js将HTML转换为Markdown

Start by installing Turndown:

首先安装Turndown:

yarn add turndown

Then use Turndown’s simple API to convert HTML to Markdown:

然后使用Turndown的简单API将HTML转换为Markdown

var TurndownService = require(‘turndown’);var turndownService = new TurndownService();var Markdown = turndownService.turndown(    TitleDavidWalsh.Name is awesome!);/*Title=====[DavidWalsh.Name](https://davidwalsh.name) is awesome!*/

You can use the interactive Turndown demo to experiment with its capabilities.  Turndown has a number of options and allows you to use filters to keep elements you believe could be at risk for improper conversion.

您可以使用交互式Turndown演示来试验其功能。 调节选项有很多选项 ,可让您使用过滤器来保留您认为可能存在转换不正确风险的元素。

Most developers look for a Markdown to HTML solution so it’s rate to find myself in a position to need to convert HTML to Markdown.  I look forward to migrating my site’s content to Markdown so that writing posts is much less stressful in the future!

大多数开发人员都希望将Markdown转换为HTML解决方案,因此很容易发现自己有能力将HTML转换为Markdown。 我期待着将我的网站内容迁移到Markdown,以便将来减少撰写帖子的压力!

未经允许不得转载:坚果云Markdown编辑器 » 将HTML转换为Markdown
分享到: 更多 (0)

坚果云Markdown轻松记录您 灵感和创意

坚果云Markdown下载坚果云Markdown介绍