Commit 0993a52a authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Replaced Maruku with RDiscount.

RDiscount is way faster and it doesn't throw errors for malformed
HTML like Maruku - so we can treat all the comments as Markdown,
plus we can mix HTML and Markdown.

Actually RDiscount doesn't throw any errors at all, whatever we
feed it.  If it doesn't recognize text as correct Markdown, it
doesn't complain - it just leaves it as is, which is perfect for
us.

There are some minor issues still with it:

- <pre><code>-s getting nested when parsing Ext source.
- Even one-liners are wrapped inside <p>...</p>.

But these are pretty easily solvable.
parent b6d5d7e9
Loading
Loading
Loading
Loading
+3 −15
Original line number Diff line number Diff line
require 'maruku'
require 'rdiscount'

module JsDuck

@@ -46,21 +46,9 @@ module JsDuck
    end

    # Formats doc-comment for placement into HTML.
    # Renders it with Markdown-formatter if possible,
    # and replaces @link-s.
    # Renders it with Markdown-formatter and replaces @link-s.
    def format(input)
      # When comment doesn't contain HTML, treat it as
      # Markdown-formatted text.
      unless input =~ /<[a-z]/
        begin
          input = "<div class='markdown'>" + Maruku.new(input, {:on_error => :raise}).to_html + "</div>"
        rescue MaRuKu::Exception
          # When Maruku fails because of Markdown syntax error, assume
          # the author didn't intend to write doc-comment in Markdown
          # at all.
        end
      end
      return replace(input)
      replace("<div class='markdown'>" + RDiscount.new(input).to_html + "</div>")
    end

  end