Class: Typedown::Document
- Inherits:
-
String
- Object
- String
- Typedown::Document
- Defined in:
- lib/typedown/document.rb
Instance Method Summary collapse
-
#initialize(text = nil) ⇒ Document
constructor
A new instance of Document.
- #to_html ⇒ Object
- #to_markdown ⇒ Object
- #to_textile ⇒ Object
Constructor Details
#initialize(text = nil) ⇒ Document
Returns a new instance of Document.
8 9 10 11 |
# File 'lib/typedown/document.rb', line 8 def initialize text = nil super "" self << text if text end |
Instance Method Details
#to_html ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/typedown/document.rb', line 104 def to_html #kramdown = Kramdown::Document.new to_markdown #kramdown.to_html bluecloth = BlueCloth::new( to_markdown ) bluecloth.to_html #redcloth = RedCloth.new( to_textile ) #redcloth.to_html end |
#to_markdown ⇒ Object
13 14 15 16 17 18 19 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 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/typedown/document.rb', line 13 def to_markdown text = self # Translate '! headings' to '# headings' text.gsub!(/^! /, "# ") text.gsub!(/^!! /, "## ") text.gsub!(/^!!! /, "### ") text.gsub!(/^!!!! /, "#### ") text.gsub!(/^!!!!! /, "##### ") text.gsub!(/^!!!!!! /, "###### ") # Dialogue dashes text.gsub!(/^-\.? /, "― ") text.gsub!(/\s-\.? /, " ― ") # Insert placeholders around lead in text.gsub!(/^\. (( *[^\n].+\n)*)/, "! x!\\1!x-!\n") # Remove placeholders while using them to remove whitespace text.gsub!(/^! x!\s*/, "**") text.gsub!(/\s*!x-!$/, "**") # Insert placeholders around lead in text.gsub!(/^\/\/\. (( *[^\n].+\n)*)/, "! x!\\1!x-!\n") # Remove placeholders while using them to remove whitespace text.gsub!(/^! x!\s*/, "**") text.gsub!(/\s*!x-!$/, "**") # Textile links to markdown links text.gsub!(/\"([^\"]+)"\:(\S+[\w\d\/])/, "[\\1](\\2)") # Typedown image tag text.gsub!(/!\[(.+)\]\((.+)\)/, "<div class='image'><img src='\\2' /><div class='caption'>\\1</div></div>") # Insert placeholders around lead in text.gsub!(/^\/\. (( *[^\n].+\n)*)/, "! x!\\1!x-!\n") # Remove placeholders while using them to remove whitespace text.gsub!(/^! x!\s*/, "*") text.gsub!(/\s*!x-!$/, "*") # Slash for _ text.gsub!(/(\s)\/(\S+)\/(\s)[\.\,\?\!]?/, "\\1_\\2_\\3") text.gsub!(/(\s)\/\/(\S+)\/\/[\.\,\?\!]?(\s)/, "\\1__\\2__\\3") text.gsub!(/(\s)\/\/\/(\S+)\/\/\/[\.\,\?\!]?(\s)/, "\\1___\\2___\\3") text end |
#to_textile ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/typedown/document.rb', line 61 def to_textile text = self # Translate '! headings' to '# headings' text.gsub!(/^! /, "h1. ") text.gsub!(/^!! /, "h2. ") text.gsub!(/^!!! /, "h3. ") text.gsub!(/^!!!! /, "h4. ") text.gsub!(/^!!!!! /, "h5. ") text.gsub!(/^!!!!!! /, "h6. ") # Dialogue dashes text.gsub!(/^-\.? /, "― ") text.gsub!(/\s-\.? /, " ― ") # Insert placeholders around lead in text.gsub!(/^\. (( *[^\n].+\n)*)/, "! x!\\1!x-!\n") # Remove placeholders while using them to remove whitespace text.gsub!(/^! x!\s*/, "*") text.gsub!(/\s*!x-!$/, "*") # Insert placeholders around lead in / bold paragraph text.gsub!(/^\/\/\. (( *[^\n].*\n)*)/, "! x!\\1!x-!\n") # Remove placeholders while using them to remove whitespace text.gsub!(/^! x!\s*/, "*") text.gsub!(/\s*!x-!$/, "*") # Insert placeholders around italicized paragraph text.gsub!(/^\/\. (( *[^\n].*\n)*)/, "! x!\\1!x-!\n") # Remove placeholders while using them to remove whitespace text.gsub!(/^! x!\s*/, "_") text.gsub!(/\s*!x-!$/, "_") # Slash for _ text.gsub!(/(\s)\/(\S+)\/(\s)[\.\,\?\!]?/, "\\1_\\2_\\3") text.gsub!(/(\s)\/\/(\S+)\/\/[\.\,\?\!]?(\s)/, "\\1*\\2*\\3") text.gsub!(/(\s)\/\/\/(\S+)\/\/\/[\.\,\?\!]?(\s)/, "\\1*_\\2_*\\3") text end |