Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string_extensions.rb
Overview
String
Instance Method Summary collapse
Instance Method Details
#html_to_docbook ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/string_extensions.rb', line 20 def html_to_docbook text = self # p,en,li tags can't open and close on new lines only text.gsub!(/\n^<\/([p|em|li]*?)>/, "</\\1>") text.gsub!(/^<([p|em|li]*?)>\n/, "<\\1>") # ensure the code/pre tag combo doesn't open and close on different lines text.gsub!(/\n^(<\/code><\/pre>*)/, "</code></pre>") text.gsub!(/(<pre><code>)\n/, "\\1") # turn <p> into <para> text.gsub!(/<p>(.*?)<\/p>/m, "<para>\\1</para>") # turn <em> into <emphasis> # text.gsub!(/<em>(.*)<\/em>/, "<emphasis>\\1</emphasis>") text.gsub!(/<pre><code>(.*?)<\/code><\/pre>/m, "<screen>\\1</screen>") # ordered and itemized lists text.gsub!(/<ul>(.*?)<\/ul>/m, "<itemizedlist>\\1</itemizedlist>") text.gsub!(/<ol>(.*?)<\/ol>/m, "<orderedlist>\\1</orderedlist>") text.gsub!(/<li>(.*?)<\/li>/m, "<listitem><para>\\1</para></listitem>") return text end |
#md_to_docbook ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/string_extensions.rb', line 50 def md_to_docbook text = self text = text.md_to_html text = text.html_to_docbook return text end |
#md_to_html ⇒ Object
13 14 15 16 17 18 |
# File 'lib/string_extensions.rb', line 13 def md_to_html text = self = [:hard_wrap, :autolink, :no_intra_emphasis] renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML) renderer.render(text) end |
#to_x ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/string_extensions.rb', line 5 def to_x text = self text = text.gsub("&","&") text = text.gsub("<","<") text = text.gsub(">",">") return text end |