Skip to content

Commit

Permalink
Re-organize markup types text, none, and add type 'pre'.
Browse files Browse the repository at this point in the history
The new behaviour for the types are as follows:

pre: Pre-formatted text, wrapping input inside <pre> tags.
text: No formatting except for replacing newlines with <br> tags.
none: No formatting at all.

In all cases, HTML is escaped. Note that syntax highlighting does not
work in these markup types.

Closes #416
  • Loading branch information
lsegal committed Dec 3, 2011
1 parent 62f04c7 commit 1eac919
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
16 changes: 12 additions & 4 deletions lib/yard/templates/helpers/html_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def htmlify(text, markup = options[:markup])
string = html_syntax_highlight(CGI.unescapeHTML(string), language) unless options[:no_highlight]
classes = ['code', language].compact.join(' ')
%Q{<pre class="#{classes}">#{string}</pre>}
end unless markup == :text
end unless [:text, :none, :pre].include?(markup)
html
end

Expand Down Expand Up @@ -99,18 +99,26 @@ def html_markup_rdoc(text)
doc.to_html
end

# Converts plaintext to HTML
# Converts plaintext to pre-formatted HTML
# @param [String] text the input text
# @return [String] the output HTML
# @since 0.6.0
def html_markup_text(text)
def html_markup_pre(text)
"<pre>" + h(text) + "</pre>"
end

# Converts plaintext to regular HTML
# @param [String] text the input text
# @return [String] the output HTML
# @since 0.6.0
def html_markup_text(text)
h(text).gsub(/\r?\n/, '<br/>')
end

# @return [String] the same text with no markup
# @since 0.6.6
def html_markup_none(text)
h(text).gsub(/(?:\r?\n){2}/, '<br/>')
h(text)
end

# Converts HTML to HTML
Expand Down
1 change: 1 addition & 0 deletions lib/yard/templates/helpers/markup_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def clear_markup_cache
],
:ruby => [],
:text => [],
:pre => [],
:html => [],
:none => [],
}
Expand Down
12 changes: 10 additions & 2 deletions spec/templates/helpers/html_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,17 @@ def options; {} end
htmlify("\xB0\xB1", :text)
# TODO: add more encoding tests
end

it "should return pre-formatted text with :pre markup" do
htmlify("fo\no\n\nbar<>", :pre).should == "<pre>fo\no\n\nbar&lt;&gt;</pre>"
end

it "should return regular text with :none markup" do
htmlify("fo\no\n\nbar<>", :none).should == "fo\no<br/>bar&lt;&gt;"
it "should return regular text with :text markup" do
htmlify("fo\no\n\nbar<>", :text).should == "fo<br/>o<br/><br/>bar&lt;&gt;"
end

it "should return unmodified text with :none markup" do
htmlify("fo\no\n\nbar<>", :none).should == "fo\no\n\nbar&lt;&gt;"
end

it "should highlight ruby if markup is :ruby" do
Expand Down

0 comments on commit 1eac919

Please sign in to comment.