class String

String

Public Instance Methods

html_to_docbook() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/string_extensions.rb, line 13
def md_to_html
    text = self
    options = [:hard_wrap, :autolink, :no_intra_emphasis]
    renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
    renderer.render(text)
end
to_x() click to toggle source
# File lib/string_extensions.rb, line 5
def to_x 
    text = self
    text = text.gsub("&","&amp;")
    text = text.gsub("<","&lt;")
    text = text.gsub(">","&gt;")
    return text
end