1

我有一堆降价文件作为我的旧应用程序文档,但现在新文档是通过我的应用程序中的 Trix 编辑器添加的。

我尝试使用 redcarpet gem 将 markdown 文件转换为 HTML 格式:

  def parsed_body
    renderer = Redcarpet::Render::HTML
    markdown = Redcarpet::Markdown.new(renderer, autolink: true, tables: true)
    markdown.render body
  end

但这里的问题是解析的文本与通过 Trix 编辑器添加的文章正文中存储的操作文本非常不同。

我的旧文档具有 CommonMark 降价格式。

article.desc.body.to_trix_html

通过 trix 编辑器添加的文章有正文:

"<div><br>A customer can add nitrochat on any page of your website/application that you’d like. They provide a quick and simple way for customers to flip through your knowledge base or reach out to your team.<br><br>Follow the steps to add nitrochat to your website:<br>1. Login using your admin account.<br>2. Go to `Chat -&gt; Installation`.<br>3. Select the **Active status** button.<br>4. In **Code snippet** section, copy and insert the following script before the closing body tag (`&lt;/body&gt;`) of your website to display the NitroChat in your website.<br><br>**Note:** If you make the NitroChat invisible(by making Active status disabled), you can still open it via JavaScript code using the NitroChat.contextualHelp.openWidget() API.<br>![Chat installation page](https://p50.f0.n0.cdn.getcloudapp.com/items/yAuYw5Kk/Image%202020-07-24%20at%203.33.00%20PM.png?v=2b5a14a907b96de94905d1de24bc9792)<br><br></div>"

article.desc.body.to_trix_html 解析MD文件后添加的文章有正文:

"<p>A customer can add nitrochat on any page of your website/application that you’d like. They provide a quick and simple way for customers to flip through your knowledge base or reach out to your team.</p>\n\n<p>Follow the steps to add nitrochat to your website:</p>\n\n<ol>\n<li>Login using your admin account.</li>\n<li>Go to <code>Chat -&gt; Installation</code>.</li>\n<li>Select the <strong>Active status</strong> button.</li>\n<li>In <strong>Code snippet</strong> section, copy and insert the following script before the closing body tag (<code>&lt;/body&gt;</code>) of your website to display the NitroChat in your website.</li>\n</ol>\n\n<p><strong>Note:</strong> If you make the NitroChat invisible(by making Active status disabled), you can still open it via JavaScript code using the NitroChat.contextualHelp.openWidget() API.<br>\n<img src=\"https://p50.f0.n0.cdn.getcloudapp.com/items/yAuYw5Kk/Image%202020-07-24%20at%203.33.00%20PM.png?v=2b5a14a907b96de94905d1de24bc9792\" alt=\"Chat installation page\"></p>"
4

0 回答 0