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

Fix regexes in DocFormatter#format.

Plus tests to catch this bug.
parent 286b0808
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -54,11 +54,11 @@ module JsDuck
      # 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>")
      input.gsub!(/([^\n])<pre>/, "\\1\n<pre>")

      # But we remove trailing newline after <pre> to prevent
      # code-blocks beginning with empty line.
      input.gsub!(/<pre>(<code>)?\n?/, "<pre>\1")
      input.gsub!(/<pre>(<code>)?\n?/, "<pre>\\1")

      replace(RDiscount.new(input).to_html)
    end
+17 −6
Original line number Diff line number Diff line
@@ -46,6 +46,20 @@ describe JsDuck::DocFormatter do
      @formatter.format("Hello **world**").should =~ /Hello <strong>world<\/strong>/
    end

    shared_examples_for "code blocks" do
      it "contains text before" do
        @html.should =~ /Some code/
      end

      it "contains the code" do
        @html.include?("if (condition) {\n    doSomething();\n}").should == true
      end

      it "does not create nested <pre> segments" do
        @html.should_not =~ /<pre>.*<pre>/m
      end
    end

    describe "<pre>" do
      before do
        @html = @formatter.format(<<-EOS)
@@ -57,9 +71,7 @@ if (condition) {
        EOS
      end

      it "does not create nested <pre> segments" do
        @html.should_not =~ /<pre>.*<pre>/m
      end
      it_should_behave_like "code blocks"

      it "avoids newline after <pre>" do
        @html.should_not =~ /<pre>\n/m
@@ -77,14 +89,13 @@ if (condition) {
        EOS
      end

      it "does not create nested <pre><code> segments" do
        @html.should_not =~ /<pre><code>.*<pre><code>/m
      end
      it_should_behave_like "code blocks"

      it "avoids newline after <pre><code>" do
        @html.should_not =~ /<pre><code>\n/m
      end
    end

  end

end