Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bring back the Compat layer

...And I thought I was going to have a good weekend.
  • Loading branch information...
commit 14674883baf282913d2018c3f2c95a6f39d4851b 1 parent 39c540f
@vmg vmg authored
Showing with 49 additions and 0 deletions.
  1. +28 −0 README.markdown
  2. +21 −0 lib/redcarpet/compat.rb
View
28 README.markdown
@@ -283,6 +283,34 @@ SmartyPants works on top of already-rendered HTML, and will ignore replacements
inside the content of HTML tags and inside specific HTML blocks such as
`<code>` or `<pre>`.
+What? You really want to mix Markdown renderers?
+------------------------------------------------
+
+What a terrible idea! Markdown is already ill-specified enough; if you create
+software that is renderer-independent, the results will be completely unreliable!
+
+Each renderer has its own API and its own set of extensions: you should choose one
+(it doesn't have to be Redcarpet, though that would be great!), write your
+software accordingly, and force your users to install it. That's the
+only way to have reliable and predictable Markdown output on your program.
+
+Still, if major forces (let's say, tornadoes or other natural disasters) force you
+to keep a Markdown-compatibility later, Redcarpet also supports this:
+
+ require 'redcarpet/compat'
+
+Requiring the compatibility library will declare a `Markdown` class with the
+classical RedCloth API, e.g.
+
+ Markdown.new('this is my text').to_html
+
+This class renders 100% standards compliant Markdown with 0 extensions. Nada.
+Don't even try to enable extensions with a compatibility layer, because
+that's a maintance nightmare and won't work.
+
+On a related topic: if your Markdown gem has a `lib/markdown.rb` file that
+monkeypatches the Markdown class, you're a terrible human being. Just saying.
+
Boring legal stuff
------------------
View
21 lib/redcarpet/compat.rb
@@ -0,0 +1,21 @@
+require 'redcarpet'
+
+# Compatibility class;
+# Creates a instance of Redcarpet with the RedCloth
+# API. This instance has no extensions enabled whatsoever,
+# and no accessors to change this. 100% pure, standard
+# Markdown.
+class RedcarpetCompat
+ attr_accessor :text
+
+ def initialize(text, *_dummy)
+ @text = text
+ @markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
+ end
+
+ def to_html(*_dummy)
+ @markdown.render(@text)
+ end
+end
+
+Markdown = RedcarpetCompat unless defined? Markdown
Please sign in to comment.
Something went wrong with that request. Please try again.