Commit ced226d7 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Treating some comments as Markdown using Maruku.

Expanded DocLinks to also perform Markdown formatting - but only
when doc-comment doesn't already contain HTML.  Event then we
might get error when parsing it as Markdown - in that case we
silence down the error and continue without rendering it as
Markdown.
parent f3cc42ec
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
require 'maruku'

module JsDuck

  # Detects {@link ...} tags in text and replaces them with HTML links
@@ -42,6 +44,25 @@ module JsDuck
        "<a" + href + ext_cls + ext_member + ">" + text + "</a>"
      end
    end

    # Formats doc-comment for placement into HTML.
    # Renders it with Markdown-formatter if possible,
    # 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 = Maruku.new(input, {:on_error => :raise}).to_html
        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)
    end

  end

end
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ module JsDuck
    end

    def render_single(param)
      doc = @links.replace(param[:doc])
      doc = @links.format(param[:doc])
      return [
        "<li>",
        "<code>#{param[:name]}</code> : #{param[:type]}",
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ module JsDuck
    end

    def description
      "<div class='description'>#{@links.replace(@cls[:doc])}</div>"
      "<div class='description'>#{@links.format(@cls[:doc])}</div>"
    end
  end

+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ module JsDuck
    end

    def primary_doc(item)
      @links.replace(item[:doc])
      @links.format(item[:doc])
    end

    # Override to append extra documentation to the doc found in item[:doc]