3

I have a bunch of markdown files as my old app documentation, but now the new documents are added via the Trix editor in my app.

I tried converting the markdown file to HTML format using the redcarpet gem by doing:

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

but the issue here is the parsed text is very different from the action-text stored in the body of articles added via Trix editor.

My old docs have the CommonMark markdown format.

article.desc.body.to_trix_html

The article added via trix editor has the body:

"<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 The article added after parsing the MD file has the body:

"<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>"
grafi33
  • 317
  • 2
  • 10
  • What is the input you're giving, what is the output you're expecting and what are you getting. "parsed text is very different" does not say much. – Siim Liiser Jul 29 '20 at 12:22
  • I've edited the initial question, @SiimLiiser thanks for pointing out. – grafi33 Jul 29 '20 at 12:32

0 Answers0