Skip to content
This repository

Use Kramdown on JRuby #58

Closed
wants to merge 1 commit into from

8 participants

Charles Oliver Nutter Darrick Wiebe consiliens Steve Klabnik Tobias Pfeiffer Chris Westbrook Robin Stocker David Foster
Charles Oliver Nutter

There's a number of libraries that depend on rdiscount directly, and since there's no "markdown" meta-gem like there is for json, this commit makes a 'java' version of the rdiscount gem that just uses the pure-Ruby Kramdown library.

The rdiscount tests have very specific requirements about HTML formatting, so I wan't quite able to get everything to pass; markdown_test.rb fails 7 tests, and rdiscount_test.rb appears to hang (possibly a JRuby bug). But the output from Kramdown is usually correct "in spirit" if not exactly what rdiscount would produce.

Darrick Wiebe

+1

consiliens

+1

Charles Oliver Nutter

FWIW, I'm also interested in building a wrapper around some fast Java markdown lib, but on my benchmarks Kramdown on JRuby is only about 50% slower than rdiscount on 1.9.3.

Tobias Pfeiffer

+1

Charles Oliver Nutter

Another approach...markdown_meta gem that prefers rdiscount but uses kramdown as a fallback: https://github.com/headius/markdown_meta

Chris Westbrook

+1

Robin Stocker

There's a little problem though: kramdown is GPLv3, so not compatible with the BSD license of RDiscount.

Chris Westbrook

I would say that this is a problem for rdiscount. Even Berkeley Systems has switched from the 4 clause to the three clause.

ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
http://www.gnu.org/philosophy/bsd.html
http://www.dwheeler.com/essays/gpl-compatible.html

I am not saying that Kramdown is the only solution, I am just looking for JRuby support for 32-bit/64-bit systems

David Foster
Owner

RDiscount is designed as a thin wrapper around the Discount library, not a meta-gem for arbitrary Markdown parsers. Having RDiscount support both Discount and Kramdown would significantly complicate the interface.

Closing as By Design.

David Foster davidfstr closed this January 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 03, 2012
Charles Oliver Nutter Use Kramdown on JRuby, instead of the C ext. 452a6f2
This page is out of date. Refresh to see the latest.
28  lib/rdiscount-kramdown.rb
... ...
@@ -0,0 +1,28 @@
  1
+require 'kramdown'
  2
+
  3
+class RDiscount
  4
+  class ::Kramdown::Converter::Rdiscounthtml < Kramdown::Converter::Html
  5
+    def initialize(root, options)
  6
+      super
  7
+      self.indent = 0
  8
+    end
  9
+  end
  10
+  
  11
+  def to_html(*)
  12
+    text = self.text
  13
+    html = Kramdown::Document.new(text).to_rdiscounthtml
  14
+    if text.respond_to? :encoding
  15
+      html.force_encoding text.encoding
  16
+    end
  17
+    html
  18
+  end
  19
+  
  20
+  def toc_content(*)
  21
+    text = self.text
  22
+    html = Kramdown::Document.new(text).to_toc
  23
+    if text.respond_to? :encoding
  24
+      html.force_encoding text.encoding
  25
+    end
  26
+    html
  27
+  end
  28
+end
7  lib/rdiscount.rb
@@ -93,4 +93,9 @@ def initialize(text, *extensions)
93 93
 
94 94
 Markdown = RDiscount unless defined? Markdown
95 95
 
96  
-require 'rdiscount.so'
  96
+begin
  97
+  require 'rdiscount.so'
  98
+rescue LoadError
  99
+  # fall back on kramdown
  100
+  require 'rdiscount-kramdown'
  101
+end
37  rdiscount-java.gemspec
... ...
@@ -0,0 +1,37 @@
  1
+Gem::Specification.new do |s|
  2
+  s.name = 'rdiscount'
  3
+  s.version = '1.6.8'
  4
+  s.summary = "Fast Implementation of Gruber's Markdown in C"
  5
+  s.date = '2011-01-25'
  6
+  s.email = 'rtomayko@gmail.com'
  7
+  s.homepage = 'http://github.com/rtomayko/rdiscount'
  8
+  s.authors = ["Ryan Tomayko", "David Loren Parsons", "Andrew White"]
  9
+  # = MANIFEST =
  10
+  s.files = %w[
  11
+    BUILDING
  12
+    COPYING
  13
+    README.markdown
  14
+    Rakefile
  15
+    bin/rdiscount
  16
+    discount
  17
+    lib/markdown.rb
  18
+    lib/rdiscount.rb
  19
+    lib/rdiscount-kramdown.rb
  20
+    man/markdown.7
  21
+    man/rdiscount.1
  22
+    man/rdiscount.1.ronn
  23
+    rdiscount-java.gemspec
  24
+    test/benchmark.rb
  25
+    test/benchmark.txt
  26
+    test/markdown_test.rb
  27
+    test/rdiscount_test.rb
  28
+  ]
  29
+  # = MANIFEST =
  30
+  s.test_files = ["test/markdown_test.rb", "test/rdiscount_test.rb"]
  31
+  s.extra_rdoc_files = ["COPYING"]
  32
+  s.executables = ["rdiscount"]
  33
+  s.require_paths = ["lib"]
  34
+  s.rubyforge_project = 'wink'
  35
+  s.add_dependency 'kramdown', '>= 0.13.5'
  36
+  s.platform = "java"
  37
+end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.