diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2014-07-19 01:49:09 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2014-07-19 01:49:09 -0600 |
| commit | 2dd757f561611383daf6a1006c68b2885448427d (patch) | |
| tree | efdc479bcaf9ba082c40abc88f044cc1f6922487 | |
| parent | 233c1e245832ba2101399310c901e3e681ea8684 (diff) | |
| parent | 29d1175c15ecd0add9aa052fb9ea048f46ec203b (diff) | |
Merge pull request #1032 from mojavelinux/issue-225
resolves #225 phrase surrounded with # defaults to marked text
| -rw-r--r-- | compat/asciidoc.conf | 1 | ||||
| -rw-r--r-- | lib/asciidoctor.rb | 8 | ||||
| -rw-r--r-- | lib/asciidoctor/converter/docbook5.rb | 17 | ||||
| -rw-r--r-- | lib/asciidoctor/converter/html5.rb | 11 | ||||
| -rw-r--r-- | lib/asciidoctor/substitutors.rb | 16 | ||||
| -rw-r--r-- | test/substitutions_test.rb | 29 |
6 files changed, 51 insertions, 31 deletions
diff --git a/compat/asciidoc.conf b/compat/asciidoc.conf index 5053fd0d..94784bb4 100644 --- a/compat/asciidoc.conf +++ b/compat/asciidoc.conf @@ -170,6 +170,7 @@ strong=<strong{1? class="{1}"}>|</strong> monospaced=<code{1? class="{1}"}>|</code> superscript=<sup{1? class="{1}"}>|</sup> subscript=<sub{1? class="{1}"}>|</sub> +unquoted={1=<mark>}{1?<span class="{1}">}|{1?</span>}{1=</mark>} [monospacedwords] <code>{words}</code> diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb index 738d88fd..d099b395 100644 --- a/lib/asciidoctor.rb +++ b/lib/asciidoctor.rb @@ -1157,11 +1157,11 @@ module Asciidoctor # _emphasis_ [:emphasis, :constrained, /(^|[^#{CC_WORD};:}])(?:\[([^\]]+?)\])?_(\S|\S.*?\S)_(?!#{CG_WORD})/m], - # ##unquoted## - [:none, :unconstrained, /\\?(?:\[([^\]]+?)\])?##(.+?)##/m], + # ##mark## (referred to in AsciiDoc Python as unquoted) + [:mark, :unconstrained, /\\?(?:\[([^\]]+?)\])?##(.+?)##/m], - # #unquoted# - [:none, :constrained, /(^|[^#{CC_WORD};:}])(?:\[([^\]]+?)\])?#(\S|\S.*?\S)#(?!#{CG_WORD})/m], + # #mark# (referred to in AsciiDoc Python as unquoted) + [:mark, :constrained, /(^|[^#{CC_WORD};:}])(?:\[([^\]]+?)\])?#(\S|\S.*?\S)#(?!#{CG_WORD})/m], # ^superscript^ [:superscript, :unconstrained, /\\?(?:\[([^\]]+?)\])?\^(\S*?)\^/m], diff --git a/lib/asciidoctor/converter/docbook5.rb b/lib/asciidoctor/converter/docbook5.rb index c0f14e3c..ab8c43f5 100644 --- a/lib/asciidoctor/converter/docbook5.rb +++ b/lib/asciidoctor/converter/docbook5.rb @@ -555,16 +555,17 @@ module Asciidoctor end end - QUOTED_TAGS = { + QUOTE_TAGS = { :emphasis => ['<emphasis>', '</emphasis>', true], :strong => ['<emphasis role="strong">', '</emphasis>', true], :monospaced => ['<literal>', '</literal>', false], :superscript => ['<superscript>', '</superscript>', false], :subscript => ['<subscript>', '</subscript>', false], :double => ['“', '”', true], - :single => ['‘', '’', true] + :single => ['‘', '’', true], + :mark => ['<emphasis role="marked">', '</emphasis>', false] } - QUOTED_TAGS.default = [nil, nil, true] + QUOTE_TAGS.default = [nil, nil, true] def inline_quoted node if (type = node.type) == :latexmath @@ -573,16 +574,16 @@ module Asciidoctor <inlinemediaobject><textobject><phrase><![CDATA[#{node.text}]]></phrase></textobject></inlinemediaobject> </inlineequation>) else - open, close, supports_phrase = QUOTED_TAGS[type] + open, close, supports_phrase = QUOTE_TAGS[type] text = node.text - quoted_text = if (role = node.role) + if (role = node.role) if supports_phrase - %(#{open}<phrase role="#{role}">#{text}</phrase>#{close}) + quoted_text = %(#{open}<phrase role="#{role}">#{text}</phrase>#{close}) else - %(#{open.chop} role="#{role}">#{text}#{close}) + quoted_text = %(#{open.chop} role="#{role}">#{text}#{close}) end else - %(#{open}#{text}#{close}) + quoted_text = %(#{open}#{text}#{close}) end node.id ? %(<anchor#{common_attributes node.id, nil, text}/>#{quoted_text}) : quoted_text diff --git a/lib/asciidoctor/converter/html5.rb b/lib/asciidoctor/converter/html5.rb index 1b0dcbab..e9eb13e7 100644 --- a/lib/asciidoctor/converter/html5.rb +++ b/lib/asciidoctor/converter/html5.rb @@ -10,6 +10,7 @@ module Asciidoctor :subscript => ['<sub>', '</sub>', true], :double => ['“', '”', false], :single => ['‘', '’', false], + :mark => ['<mark>', '</mark>', true], :asciimath => ['\\$', '\\$', false], :latexmath => ['\\(', '\\)', false] # Opal can't resolve these constants when referenced here @@ -1057,10 +1058,14 @@ Your browser does not support the video tag. def inline_quoted node open, close, is_tag = QUOTE_TAGS[node.type] - quoted_text = if (role = node.role) - is_tag ? %(#{open.chop} class="#{role}">#{node.text}#{close}) : %(<span class="#{role}">#{open}#{node.text}#{close}</span>) + if (role = node.role) + if is_tag + quoted_text = %(#{open.chop} class="#{role}">#{node.text}#{close}) + else + quoted_text = %(<span class="#{role}">#{open}#{node.text}#{close}</span>) + end else - %(#{open}#{node.text}#{close}) + quoted_text = %(#{open}#{node.text}#{close}) end node.id ? %(<a id="#{node.id}"></a>#{quoted_text}) : quoted_text diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb index cecbb01b..fd08b90e 100644 --- a/lib/asciidoctor/substitutors.rb +++ b/lib/asciidoctor/substitutors.rb @@ -1059,13 +1059,21 @@ module Substitutors if unescaped_attrs %(#{unescaped_attrs}#{Inline.new(self, :quoted, match[3], :type => type).convert}) else - attributes = parse_quoted_text_attributes(match[2]) - id = attributes ? attributes.delete('id') : nil + if (attributes = parse_quoted_text_attributes(match[2])) + id = attributes.delete 'id' + type = :unquoted if type == :mark + else + id = nil + end %(#{match[1]}#{Inline.new(self, :quoted, match[3], :type => type, :id => id, :attributes => attributes).convert}) end else - attributes = parse_quoted_text_attributes(match[1]) - id = attributes ? attributes.delete('id') : nil + if (attributes = parse_quoted_text_attributes(match[1])) + id = attributes.delete 'id' + type = :unquoted if type == :mark + else + id = nil + end Inline.new(self, :quoted, match[2], :type => type, :id => id, :attributes => attributes).convert end end diff --git a/test/substitutions_test.rb b/test/substitutions_test.rb index 7b627b33..fb144aab 100644 --- a/test/substitutions_test.rb +++ b/test/substitutions_test.rb @@ -73,34 +73,39 @@ context 'Substitutions' do assert_equal %q{‘Here`s Johnny!’}, para.sub_quotes(para.source) end - test 'single-line constrained unquoted string' do + test 'single-line constrained marked string' do para = block_from_string(%q{#a few words#}) - assert_equal 'a few words', para.sub_quotes(para.source) + assert_equal '<mark>a few words</mark>', para.sub_quotes(para.source) end - test 'escaped single-line constrained unquoted string' do + test 'escaped single-line constrained marked string' do para = block_from_string(%(#{BACKSLASH}#a few words#)) assert_equal '#a few words#', para.sub_quotes(para.source) end - test 'multi-line constrained unquoted string' do + test 'multi-line constrained marked string' do para = block_from_string(%Q{#a few\nwords#}) - assert_equal "a few\nwords", para.sub_quotes(para.source) + assert_equal "<mark>a few\nwords</mark>", para.sub_quotes(para.source) end - test 'single-line unconstrained unquoted string' do + test 'single-line unconstrained marked string' do para = block_from_string(%q{##--anything goes ##}) - assert_equal '--anything goes ', para.sub_quotes(para.source) + assert_equal '<mark>--anything goes </mark>', para.sub_quotes(para.source) end - test 'escaped single-line unconstrained unquoted string' do - para = block_from_string(%(#{BACKSLASH}##--anything goes ##)) - assert_equal '#--anything goes #', para.sub_quotes(para.source) + test 'escaped single-line unconstrained marked string' do + para = block_from_string(%(#{BACKSLASH}#{BACKSLASH}##--anything goes ##)) + assert_equal '##--anything goes ##', para.sub_quotes(para.source) end - test 'multi-line unconstrained unquoted string' do + test 'multi-line unconstrained marked string' do para = block_from_string(%Q{##--anything\ngoes ##}) - assert_equal "--anything\ngoes ", para.sub_quotes(para.source) + assert_equal "<mark>--anything\ngoes </mark>", para.sub_quotes(para.source) + end + + test 'single-line constrained marked string with role' do + para = block_from_string(%q{[statement]#a few words#}) + assert_equal '<span class="statement">a few words</span>', para.sub_quotes(para.source) end test 'single-line constrained strong string' do |
