| 1 | # Discount is an implementation of John Gruber's Markdown markup |
| 2 | # language in C. It implements all of the language as described in |
| 3 | # {Markdown Syntax}[http://daringfireball.net/projects/markdown/syntax] |
| 4 | # and passes the Markdown 1.0 test suite. The RDiscount extension makes |
| 5 | # the Discount processor available via a Ruby C Extension library. |
| 6 | # |
| 7 | # == Usage |
| 8 | # |
| 9 | # RDiscount implements the basic protocol popularized by RedCloth and adopted |
| 10 | # by BlueCloth: |
| 11 | # require 'rdiscount' |
| 12 | # markdown = RDiscount.new("Hello World!") |
| 13 | # puts markdown.to_html |
| 14 | # |
| 15 | # == Replacing BlueCloth |
| 16 | # |
| 17 | # Inject RDiscount into your BlueCloth-using code by replacing your bluecloth |
| 18 | # require statements with the following: |
| 19 | # begin |
| 20 | # require 'rdiscount' |
| 21 | # BlueCloth = RDiscount |
| 22 | # rescue LoadError |
| 23 | # require 'bluecloth' |
| 24 | # end |
| 25 | # |
| 26 | class RDiscount |
| 27 | VERSION = '2.2.7.5' |
| 28 | |
| 29 | # Original Markdown formatted text. |
| 30 | attr_reader :text |
| 31 | |
| 32 | # Set true to have smarty-like quote translation performed. |
| 33 | attr_accessor :smart |
| 34 | |
| 35 | # Do not output <tt><style></tt> tags included in the source text. |
| 36 | attr_accessor :filter_styles |
| 37 | |
| 38 | # Do not output any raw HTML included in the source text. |
| 39 | attr_accessor :filter_html |
| 40 | |
| 41 | # RedCloth compatible line folding -- not used for Markdown but |
| 42 | # included for compatibility. |
| 43 | attr_accessor :fold_lines |
| 44 | |
| 45 | # Enable php markdown extra-style footnotes |
| 46 | attr_accessor :footnotes |
| 47 | |
| 48 | # Enable Table Of Contents generation |
| 49 | attr_accessor :generate_toc |
| 50 | |
| 51 | # Do not process <tt>![]</tt> and remove <tt><img></tt> tags from the output. |
| 52 | attr_accessor :no_image |
| 53 | |
| 54 | # Do not process <tt>[]</tt> and remove <tt><a></tt> tags from the output. |
| 55 | attr_accessor :no_links |
| 56 | |
| 57 | # Do not process tables |
| 58 | attr_accessor :no_tables |
| 59 | |
| 60 | # Disable superscript and relaxed emphasis processing. |
| 61 | attr_accessor :strict |
| 62 | |
| 63 | # Convert URL in links, even if they aren't encased in <tt><></tt> |
| 64 | attr_accessor :autolink |
| 65 | |
| 66 | # Don't make hyperlinks from <tt>[][]</tt> links that have unknown URL types. |
| 67 | attr_accessor :safelink |
| 68 | |
| 69 | # Do not process pseudo-protocols like <tt>[](id:name)</tt> |
| 70 | attr_accessor :no_pseudo_protocols |
| 71 | |
| 72 | # Disable superscript processing. |
| 73 | attr_accessor :no_superscript |
| 74 | |
| 75 | # Disable strikethrough processing. |
| 76 | attr_accessor :no_strikethrough |
| 77 | |
| 78 | # Keep LaTeX inside $$ intact. |
| 79 | attr_accessor :latex |
| 80 | |
| 81 | # Don't merge adjacent list into a single list. |
| 82 | attr_accessor :explicitlist |
| 83 | |
| 84 | # Not documented: run in markdown 1 compat mode (only used for MarkdownTest1.0) |
| 85 | attr_accessor :md1compat |
| 86 | |
| 87 | # Create a RDiscount Markdown processor. The +text+ argument |
| 88 | # should be a string containing Markdown text. Additional arguments may be |
| 89 | # supplied to set various processing options: |
| 90 | # |
| 91 | # * <tt>:smart</tt> - Enable SmartyPants processing. |
| 92 | # * <tt>:filter_styles</tt> - Do not output <tt><style></tt> tags. |
| 93 | # * <tt>:filter_html</tt> - Do not output any raw HTML tags included in |
| 94 | # the source text. |
| 95 | # * <tt>:fold_lines</tt> - RedCloth compatible line folding (not used). |
| 96 | # * <tt>:footnotes</tt> - PHP markdown extra-style footnotes. |
| 97 | # * <tt>:generate_toc</tt> - Enable Table Of Contents generation |
| 98 | # * <tt>:no_image</tt> - Do not output any <tt><img></tt> tags. |
| 99 | # * <tt>:no_links</tt> - Do not output any <tt><a></tt> tags. |
| 100 | # * <tt>:no_tables</tt> - Do not output any tables. |
| 101 | # * <tt>:strict</tt> - Disable superscript and relaxed emphasis processing. |
| 102 | # * <tt>:autolink</tt> - Greedily urlify links. |
| 103 | # * <tt>:safelink</tt> - Do not make links for unknown URL types. |
| 104 | # * <tt>:no_pseudo_protocols</tt> - Do not process pseudo-protocols. |
| 105 | # * <tt>:no_superscript</tt> - Disable superscript processing. |
| 106 | # * <tt>:no_strikethrough</tt> - Disable strikethrough processing. |
| 107 | # * <tt>:latex</tt> - Keep LaTeX inside $$ intact. |
| 108 | # * <tt>:explicitlist</tt> - Don't merge adjacent list into a single list. |
| 109 | # |
| 110 | def initialize(text, *extensions) |
| 111 | @text = text |
| 112 | extensions.each { |e| send("#{e}=", true) } |
| 113 | end |
| 114 | |
| 115 | end |
| 116 | |
| 117 | Markdown = RDiscount unless defined? Markdown |
| 118 | |
| 119 | require 'rdiscount.so' |