summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dallen@redhat.com>2013-06-26 15:27:03 -0600
committerDan Allen <dallen@redhat.com>2013-06-27 20:01:31 -0600
commitb8a2f21bf51eaee8bf9951621ee6bcb99dd55839 (patch)
treeee9e92c2499ffe43caf1ee0c5b14285edd36a60e
parentf620bfd8e6fe8c483bf47fe69e52dc6608927f78 (diff)
resolves #455 add Markdown-style horizontal rules (w/ restriction)
-rw-r--r--compat/asciidoc.conf3
-rwxr-xr-xlib/asciidoctor.rb12
-rw-r--r--lib/asciidoctor/lexer.rb2
-rw-r--r--test/text_test.rb41
4 files changed, 50 insertions, 8 deletions
diff --git a/compat/asciidoc.conf b/compat/asciidoc.conf
index db3e7d00..ee3208af 100644
--- a/compat/asciidoc.conf
+++ b/compat/asciidoc.conf
@@ -70,6 +70,9 @@ delimiter=^:={3,}$
format=dsv
[macros]
+# --- or - - - or *** or * * * or ' ' ' (in addition to the built-in ''')
+^(?:-\s*-\s*-|\*\s*\*\s*\*|'\s*'\s*')$=#ruler
+
# btn:[Save]
(?su)(?<!\w)\\?btn:\[(?P<attrlist>(?:\\\]|[^\]])+?)\]=button
diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb
index 2f3408a4..a48677dc 100755
--- a/lib/asciidoctor.rb
+++ b/lib/asciidoctor.rb
@@ -159,8 +159,10 @@ module Asciidoctor
}
BREAK_LINES = {
- %q{'''} => :ruler,
- '<<<' => :page_break
+ '\'' => :ruler,
+ '-' => :ruler,
+ '*' => :ruler,
+ '<' => :page_break
}
LIST_CONTEXTS = [:ulist, :olist, :dlist, :colist]
@@ -427,9 +429,11 @@ module Asciidoctor
# REVIEW leading space has already been stripped, so may not need in regex
:olist => /^[[:blank:]]*(\.{1,5}|\d+\.|[A-Za-z]\.|[IVXivx]+\))[[:blank:]]+(.*)$/,
- # ''' (ruler)
+ # ''' or ' ' ' (ruler)
+ # --- or - - - (ruler)
+ # *** or * * * (ruler)
# <<< (pagebreak)
- :break_line => /^('|<){3,}$/,
+ :break_line => /^(?:'|<){3,}|' *' *'|- *- *-|\* *\* *\*$/,
# inline passthrough macros
# +++text+++
diff --git a/lib/asciidoctor/lexer.rb b/lib/asciidoctor/lexer.rb
index abafbc2a..85f29b8d 100644
--- a/lib/asciidoctor/lexer.rb
+++ b/lib/asciidoctor/lexer.rb
@@ -368,7 +368,7 @@ class Lexer
if !text_only
# NOTE we're letting break lines (ruler, page_break, etc) have attributes
if (match = this_line.match(REGEXP[:break_line]))
- block = Block.new(parent, BREAK_LINES[match[0][0..2]])
+ block = Block.new(parent, BREAK_LINES[match[0][0..0]])
break
# TODO make this a media_blk and handle image, video & audio
diff --git a/test/text_test.rb b/test/text_test.rb
index a77e01b3..3bf81c73 100644
--- a/test/text_test.rb
+++ b/test/text_test.rb
@@ -63,9 +63,44 @@ include::fixtures/encoding.asciidoc[tags=romé]
assert_match(/&#8216;The New Yorker.&#8217;/, rendered)
end
- test "separator" do
- # for some reason, the html enclosure breaks the xpath //*[@id='content']//hr
- assert_xpath "//*[@id='content']//hr", render_string("This is separated.\n\n'''\n\n...from this!"), 1
+ test 'horizontal rule' do
+ input = <<-EOS
+This line is separated by a horizontal rule...
+
+'''
+
+...from this line.
+ EOS
+ output = render_embedded_string input
+ assert_xpath "//hr", output, 1
+ assert_xpath "/*[@class='paragraph']", output, 2
+ assert_xpath "(/*[@class='paragraph'])[1]/following-sibling::hr", output, 1
+ assert_xpath "/hr/following-sibling::*[@class='paragraph']", output, 1
+ end
+
+ test 'markdown horizontal rules' do
+ variants = [
+ '---',
+ '- - -',
+ '***',
+ '* * *',
+ '\' \' \''
+ ]
+
+ variants.each do |variant|
+ input = <<-EOS
+This line is separated by a horizontal rule...
+
+#{variant}
+
+...from this line.
+ EOS
+ output = render_embedded_string input
+ assert_xpath "//hr", output, 1
+ assert_xpath "/*[@class='paragraph']", output, 2
+ assert_xpath "(/*[@class='paragraph'])[1]/following-sibling::hr", output, 1
+ assert_xpath "/hr/following-sibling::*[@class='paragraph']", output, 1
+ end
end
test "emphasized text" do