Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

[WIP] [NEW] [UPGRADE] Use showdown module to parse markdown

Open fliptrail opened this issue 5 years ago • 3 comments

Ref RocketChat/feature-requests#642 RocketChat/Rocket.Chat#13885 RocketChat/Rocket.Chat#13883

This is work in progress. This is a very crude PR in which no coding standards have been followed.

The current markdown parser is not good enough for all the needs. I suggest to use Showdown module to parse markdown to HTML.

I will add the documentation PR soon if, the community agrees to use showdown module.

Intro

Showdown is a Javascript Markdown to HTML converter, based on the original works by John Gruber.

Showdown was created by John Fraser as a direct port of the original parser written by markdown's creator, John Gruber. Although Showdown has evolved since its inception, in "vanilla mode", it tries to follow the original markdown spec (henceforth refereed as vanilla) as much as possible. There are, however, a few important differences, mainly due to inconsistencies in the original spec, which we addressed following the author's advice as stated in the markdown's "official" newsletter.

For more information: https://github.com/showdownjs/showdown

Features

  1. github - GFM (GitHub Flavored Markdown) is available
  2. Markdown Support for various elements can be chosen by choice, i.e. some markdown elements can be disabled on choice.
  3. Can be used on both client and server side. In fact it can be used as CLI also.
  4. Direct install and import via npm/ bower for easy development setup.
  5. Showdown allows additional functionality to be loaded via extensions. (sample extensions https://github.com/showdownjs/showdown/wiki/extensions)
  6. Can directly attach id attribute to the html element.

Markdown Support

  1. Paragraphs
  2. Headings (including atx style)
  3. Block quotes
  4. Bold/ italic/ strikethrough
  5. Code formatting
    1. Inline
    2. Multiline
  6. Lists
    1. Unordered lists
    2. Ordered lists
    3. TaskLists (GFM Style)
    4. List syntax
    5. Nested blocks
    6. Nested lists
    7. Nested code blocks
  7. Links
    1. Simple
    2. Inline
    3. Reference Style
  8. Images
    1. Inline
    2. Reference Style
    3. Image dimensions
    4. Base64 encoded images
  9. Tables
  10. HTML tags inside markdown
  11. Escaping Entities

What have I been able to set-up?

Screenshot from 2019-03-25 04-59-30 Screenshot from 2019-03-25 04-59-39 Screenshot from 2019-03-25 05-00-11 Screenshot from 2019-03-25 05-00-44

Additional yet essential information

  1. As you know, ShowdownJS is a free library and it will remain free forever.

  2. ShowdownJS v 2.0 is release under the MIT version. Previous versions are release under BSD. (as quoted from https://github.com/showdownjs/showdown/blob/master/README.md)

  3. Showdown has been tested successfully with:

Firefox 1.5 and 2.0 Chrome 12.0 Internet Explorer 6 and 7 Safari 2.0.4 Opera 8.54 and 9.10 Netscape 8.1.2 Konqueror 3.5.4 In theory, Showdown will work in any browser that supports ECMA 262 3rd Edition (JavaScript 1.5). The converter itself might even work in things that aren't web browsers, like Acrobat. No promises.

Concerns regarding XSS

A document on Markdown and XSS (https://michelf.ca/blog/2010/markdown-and-xss/ and https://github.com/showdownjs/showdown/wiki/Markdown's-XSS-Vulnerability-(and-how-to-mitigate-it))

fliptrail avatar Mar 24 '19 23:03 fliptrail

@engelgabriel What are you views? In ref to RocketChat/feature-requests#642

Also, a document on Markdown and XSS (https://michelf.ca/blog/2010/markdown-and-xss/ and https://github.com/showdownjs/showdown/wiki/Markdown's-XSS-Vulnerability-(and-how-to-mitigate-it))

fliptrail avatar May 04 '19 09:05 fliptrail

Should I move forward with it?

fliptrail avatar May 04 '19 09:05 fliptrail

@fliptrail @engelgabriel Rockat.Chat supports Marked markdown now. So, maybe this PR is obsolete.

xmedeko avatar Apr 21 '20 06:04 xmedeko