Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add support for AsciiDoc powered by Asciidoctor #830

Closed
wants to merge 1 commit into from

3 participants

@mojavelinux
  • enable hardbreaks by default to be consistent w/ how Jekyll works
  • enable rendering of title as h1 heading
  • include support for passing attributes to Asciidoctor
  • tests and cucumber feature!
@mojavelinux mojavelinux add support for AsciiDoc powered by Asciidoctor
- enable hardbreaks by default to be consistent w/ how Jekyll works
- enable rendering of title as h1 heading
- include support for passing attributes to Asciidoctor
- tests and cucumber feature
7f47b37
@paulrayner

Can't wait for this!

@parkr
Owner

@mojavelinux Interesting! Before we can consider this, we'll need to have a happy travis report. Would you please fix the error with 1.8.7? Thanks!

@parkr
Owner

Whoops - that test failure is my b. I'll take care of it :)

@mojavelinux

Excellent! Just let me know if you need me to make any updates.

@parkr
Owner

Related to #819.

@parkr
Owner

I think we're going to go with a solution like in #819. Thanks anyway for this! A catch-all solution is the preferred sol'n.

@parkr parkr closed this
@mojavelinux

I agree. Using Tilt is best :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 2, 2013
  1. @mojavelinux

    add support for AsciiDoc powered by Asciidoctor

    mojavelinux authored
    - enable hardbreaks by default to be consistent w/ how Jekyll works
    - enable rendering of title as h1 heading
    - include support for passing attributes to Asciidoctor
    - tests and cucumber feature
This page is out of date. Refresh to see the latest.
View
30 features/asciidoc.feature
@@ -0,0 +1,30 @@
+Feature: AsciiDoc
+ As a hacker who likes to blog
+ I want to be able to make a static site
+ In order to share my awesome ideas with the interwebs
+
+ Scenario: AsciiDoc in list on index
+ Given I have a configuration file with "paginate" set to "5"
+ And I have an "index.html" page that contains "Index - {% for post in site.posts %} {{ post.content }} {% endfor %}"
+ And I have a _posts directory
+ And I have the following post:
+ | title | date | content | type |
+ | Hackers | 3/2/2013 | = My Title | asciidoc |
+ When I run jekyll
+ Then the _site directory should exist
+ And I should see "Index" in "_site/index.html"
+ And I should see "<h1>My Title</h1>" in "_site/2013/03/02/hackers.html"
+ And I should see "<h1>My Title</h1>" in "_site/index.html"
+
+ Scenario: AsciiDoc in pagination on index
+ Given I have a configuration file with "paginate" set to "5"
+ And I have an "index.html" page that contains "Index - {% for post in paginator.posts %} {{ post.content }} {% endfor %}"
+ And I have a _posts directory
+ And I have the following post:
+ | title | date | content | type |
+ | Hackers | 3/2/2013 | = My Title | asciidoc |
+ When I run jekyll
+ Then the _site directory should exist
+ And I should see "Index" in "_site/index.html"
+ And I should see "<h1>My Title</h1>" in "_site/index.html"
+
View
1  jekyll.gemspec
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('shoulda', "~> 3.3.2")
s.add_development_dependency('rr', "~> 1.0")
s.add_development_dependency('cucumber', "~> 1.2.1")
+ s.add_development_dependency('asciidoctor', "~> 0.1.1")
s.add_development_dependency('RedCloth', "~> 4.2")
s.add_development_dependency('rdiscount', "~> 1.6")
s.add_development_dependency('redcarpet', "~> 2.2.2")
View
7 lib/jekyll.rb
@@ -66,11 +66,13 @@ module Jekyll
'pygments' => false, # remove and make true just default
'markdown' => 'maruku', # no longer a command option
+ 'asciidoc' => 'asciidoctor', # no longer a command option
'permalink' => 'date', # no longer a command option
'include' => ['.htaccess'], # no longer a command option
'paginate_path' => 'page:num', # no longer a command option
'markdown_ext' => 'markdown,mkd,mkdn,md',
+ 'asciidoc_ext' => 'asciidoc,adoc,ad',
'textile_ext' => 'textile',
'maruku' => {
@@ -107,6 +109,11 @@ module Jekyll
}
},
+ 'asciidoctor' => {
+ 'notitle!' => '',
+ 'hardbreaks' => ''
+ },
+
'redcloth' => {
'hard_breaks' => true
}
View
49 lib/jekyll/converters/asciidoc.rb
@@ -0,0 +1,49 @@
+module Jekyll
+ module Converters
+ class AsciiDoc < Converter
+ safe true
+
+ pygments_prefix "\n"
+ pygments_suffix "\n"
+
+ def setup
+ return if @setup
+ case @config['asciidoc']
+ when 'asciidoctor'
+ begin
+ require 'asciidoctor'
+ @setup = true
+ rescue LoadError
+ STDERR.puts 'You are missing a library required for AsciiDoc. Please run:'
+ STDERR.puts ' $ [sudo] gem install asciidoctor'
+ raise FatalException.new("Missing dependency: asciidoctor")
+ end
+ else
+ STDERR.puts "Invalid AsciiDoc processor: #{@config['asciidoc']}"
+ STDERR.puts " Valid options are [ asciidoctor ]"
+ raise FatalException.new("Invalid AsciiDoc process: #{@config['asciidoc']}")
+ end
+ @setup = true
+ end
+
+ def matches(ext)
+ rgx = '(' + @config['asciidoc_ext'].gsub(',','|') +')'
+ ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
+ end
+
+ def output_ext(ext)
+ ".html"
+ end
+
+ def convert(content)
+ setup
+ case @config['asciidoc']
+ when 'asciidoctor'
+ Asciidoctor.render(content, :attributes => @config['asciidoctor'])
+ else
+ content
+ end
+ end
+ end
+ end
+end
View
11 lib/jekyll/filters.rb
@@ -24,6 +24,17 @@ def markdownify(input)
converter.convert(input)
end
+ # Convert an AsciiDoc string into HTML output.
+ #
+ # input - The AsciiDoc String to convert.
+ #
+ # Returns the HTML formatted String.
+ def asciidocify(input)
+ site = @context.registers[:site]
+ converter = site.getConverterImpl(Jekyll::Converters::AsciiDoc)
+ converter.convert(input)
+ end
+
# Format a date in short format e.g. "27 Jan 2011".
#
# date - the Time to format.
View
1  test/helper.rb
@@ -10,6 +10,7 @@
require 'jekyll'
+require 'asciidoctor'
require 'RedCloth'
require 'rdiscount'
require 'kramdown'
View
51 test/test_asciidoctor.rb
@@ -0,0 +1,51 @@
+require File.dirname(__FILE__) + '/helper'
+
+class TestAsciidoctor < Test::Unit::TestCase
+
+ context "Default hardbreaks disabled w/ asciidoc section, no hardbreaks attribute" do
+ setup do
+ config = {
+ 'asciidoc' => 'asciidoctor',
+ 'asciidoctor' => {}
+ }
+ @asciidoc = Converters::AsciiDoc.new config
+ end
+
+ should "not preserve single line breaks in HTML output" do
+ assert_equal "<div class=\"paragraph\">\n<p>line1\nline2</p>\n</div>", @asciidoc.convert("line1\nline2").strip.gsub(/^ *(\n|(?=[^ ]))/, '')
+ end
+ end
+
+ context "Asciidoctor with hardbreaks enabled" do
+ setup do
+ config = {
+ 'asciidoc' => 'asciidoctor',
+ 'asciidoctor' => {
+ 'hardbreaks' => '' # default
+ }
+ }
+ @asciidoc = Converters::AsciiDoc.new config
+ end
+
+ should "preserve single line breaks in HTML output" do
+ assert_equal "<div class=\"paragraph\">\n<p>line1<br>\nline2</p>\n</div>", @asciidoc.convert("line1\nline2").strip.gsub(/^ *(\n|(?=[^ ]))/, '')
+ end
+ end
+
+ context "Asciidoctor with title enabled" do
+ setup do
+ config = {
+ 'asciidoc' => 'asciidoctor',
+ 'asciidoctor' => {
+ 'notitle!' => '' # default
+ }
+ }
+ @asciidoc = Converters::AsciiDoc.new config
+ end
+
+ should "shows title as h1 heading" do
+ assert_equal "<h1>Header</h1>", @asciidoc.convert("= Header").strip.gsub(/^ *(\n|(?=[^ ]))/, '')
+ end
+ end
+
+end
Something went wrong with that request. Please try again.