Loading lib/jsduck/doc_formatter.rb +8 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,14 @@ module JsDuck # Formats doc-comment for placement into HTML. # Renders it with Markdown-formatter and replaces @link-s. def format(input) # In ExtJS source "<pre>" is often at the end of paragraph, not # on its own line. But in that case RDiscount doesn't recognize # it as the beginning of <pre>-block and goes on parsing it as # normal Markdown, which often causes nested <pre>-blocks. # # To prevent this, we always add extra newline before <pre>. input.gsub!(/([^\n])<pre>/, "\1\n<pre>") replace(RDiscount.new(input).to_html) end Loading spec/doc_formatter_spec.rb +49 −26 Original line number Diff line number Diff line require "jsduck/doc_formatter" describe JsDuck::DocFormatter, "#replace" do describe JsDuck::DocFormatter do before do @formatter = JsDuck::DocFormatter.new("Context") end describe "#replace" do it "replaces {@link Ext.Msg} with link to class" do @formatter.replace("Look at {@link Ext.Msg}").should == 'Look at <a href="output/Ext.Msg.html" ext:cls="Ext.Msg">Ext.Msg</a>' Loading Loading @@ -36,3 +38,24 @@ describe JsDuck::DocFormatter, "#replace" do 'unfinished {@link tag here' end end describe "#format" do # Just a sanity check that Markdown formatting works it "converts Markdown to HTML" do @formatter.format("Hello **world**").should =~ /Hello <strong>world<\/strong>/ end it "does not create nested <pre> segments" do html = @formatter.format(" Some code<pre><code> if (condition) { doSomething(); } </code></pre> ") html.should_not =~ /<pre>.*<pre>/m end end end Loading
lib/jsduck/doc_formatter.rb +8 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,14 @@ module JsDuck # Formats doc-comment for placement into HTML. # Renders it with Markdown-formatter and replaces @link-s. def format(input) # In ExtJS source "<pre>" is often at the end of paragraph, not # on its own line. But in that case RDiscount doesn't recognize # it as the beginning of <pre>-block and goes on parsing it as # normal Markdown, which often causes nested <pre>-blocks. # # To prevent this, we always add extra newline before <pre>. input.gsub!(/([^\n])<pre>/, "\1\n<pre>") replace(RDiscount.new(input).to_html) end Loading
spec/doc_formatter_spec.rb +49 −26 Original line number Diff line number Diff line require "jsduck/doc_formatter" describe JsDuck::DocFormatter, "#replace" do describe JsDuck::DocFormatter do before do @formatter = JsDuck::DocFormatter.new("Context") end describe "#replace" do it "replaces {@link Ext.Msg} with link to class" do @formatter.replace("Look at {@link Ext.Msg}").should == 'Look at <a href="output/Ext.Msg.html" ext:cls="Ext.Msg">Ext.Msg</a>' Loading Loading @@ -36,3 +38,24 @@ describe JsDuck::DocFormatter, "#replace" do 'unfinished {@link tag here' end end describe "#format" do # Just a sanity check that Markdown formatting works it "converts Markdown to HTML" do @formatter.format("Hello **world**").should =~ /Hello <strong>world<\/strong>/ end it "does not create nested <pre> segments" do html = @formatter.format(" Some code<pre><code> if (condition) { doSomething(); } </code></pre> ") html.should_not =~ /<pre>.*<pre>/m end end end