Commit 286b0808 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Remove trailing newlines after <pre>.

This prevents ugly empty lines at the beginning of almost all
code examples in ExtJS documentation.
parent 6584d4a7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -56,6 +56,10 @@ module JsDuck
      # To prevent this, we always add extra newline before <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")

      replace(RDiscount.new(input).to_html)
    end

+33 −4
Original line number Diff line number Diff line
@@ -46,15 +46,44 @@ describe JsDuck::DocFormatter do
      @formatter.format("Hello **world**").should =~ /Hello <strong>world<\/strong>/
    end

    describe "<pre>" do
      before do
        @html = @formatter.format(<<-EOS)
Some code<pre>
if (condition) {
    doSomething();
}
</pre>
        EOS
      end

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

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

    describe "<pre><code>" do
      before do
        @html = @formatter.format(<<-EOS)
Some code<pre><code>
if (condition) {
    doSomething();
}
</code></pre>
")
      html.should_not =~ /<pre>.*<pre>/m
        EOS
      end

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

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