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

Allow backtick-quoting of <pre> tags.

The backwards-compatibility fix for code like:

    Here's the code example:<pre><code>
    alert("Blah");
    </code></pre>

was a bit too lose.  So tightened it up to only apply in case
where the <pre> or <pre><code> is at the end of line.

Fixes: #380
parent e46e0724
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ 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>((<code>)?$)/, "\\1\n<pre>\\2")

      # But we remove trailing newline after <pre> to prevent
      # code-blocks beginning with empty line.
+20 −0
Original line number Diff line number Diff line
@@ -494,6 +494,26 @@ describe JsDuck::DocFormatter do
      end
    end

    describe "quoted `<pre>`" do
      before do
        @html = @formatter.format("Some `<pre>` in here.")
      end

      it "is correctly escaped" do
        @html.should == "<p>Some <code>&lt;pre&gt;</code> in here.</p>\n"
      end
    end

    describe "quoted `<pre><code>`" do
      before do
        @html = @formatter.format("Some `<pre><code>` in here.")
      end

      it "is correctly escaped" do
        @html.should == "<p>Some <code>&lt;pre&gt;&lt;code&gt;</code> in here.</p>\n"
      end
    end

    shared_examples_for "example" do
      it "creates <pre> with inline-example class" do
        @html.should =~ /<pre class='inline-example *'>/m