Skip to content

Commit

Permalink
Allow backtick-quoting of <pre> tags.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nene committed May 31, 2013
1 parent e46e072 commit e026049
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/jsduck/doc_formatter.rb
Expand Up @@ -67,7 +67,7 @@ def format(input)
# 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.
Expand Down
20 changes: 20 additions & 0 deletions spec/doc_formatter_spec.rb
Expand Up @@ -494,6 +494,26 @@ def get(filename)
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
Expand Down

0 comments on commit e026049

Please sign in to comment.