Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :disable_parsers option. #379

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/kramdown/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,23 @@ def self.simple_hash_validator(val, name)
Used by: HTML/Latex converter
EOF

define(:disable_parsers, Object, [], <<EOF) do |val|
List of parsers to disable

Kramdown has a number of built-in span and block parsers, and
additional parsers can be added by subclassing. This option allows the
caller to disable specific parsers by name, especially when something
like smart quotes or typographic dashes will be supplied by a separate
processing step.

Default: []
Used by: kramdown parser
EOF
val = simple_array_validator(val, :disable_parsers)
val.map! {|v| v.to_sym rescue v}
val
end

define(:parse_block_html, Boolean, false, <<EOF)
Process kramdown syntax in block HTML tags

Expand Down
4 changes: 4 additions & 0 deletions lib/kramdown/parser/kramdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def update_link_definitions(link_defs)
# Adapt the object to allow parsing like specified in the options.
def configure_parser
@parsers = {}
# Remove disabled parsers now; this is the first opportunity
# since subclasses might append in their initialization.
@block_parsers -= @options[:disable_parsers]
@span_parsers -= @options[:disable_parsers]
(@block_parsers + @span_parsers).each do |name|
if self.class.has_parser?(name)
@parsers[name] = self.class.parser(name)
Expand Down
4 changes: 4 additions & 0 deletions test/test_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class TestFiles < Minitest::Test
'test/testcases/span/05_html/mark_element.html', # bc of tidy
'test/testcases/block/09_html/xml.html', # bc of tidy
'test/testcases/span/05_html/xml.html', # bc of tidy
'test/testcases/span/text_substitutions/typography_disabled.html', # bc of tidy
].compact
EXCLUDE_HTML_TEXT_FILES = ['test/testcases/block/09_html/parse_as_span.htmlinput',
'test/testcases/block/09_html/parse_as_raw.htmlinput',
Expand Down Expand Up @@ -192,6 +193,7 @@ def tidy_output(out)
'test/testcases/span/05_html/mark_element.text', # bc of tidy
'test/testcases/block/09_html/xml.text', # bc of tidy
'test/testcases/span/05_html/xml.text', # bc of tidy
'test/testcases/span/text_substitutions/typography_disabled.text', # bc of tidy
].compact
Dir[File.dirname(__FILE__) + '/testcases/**/*.text'].each do |text_file|
next if EXCLUDE_TEXT_FILES.any? {|f| text_file =~ /#{f}$/}
Expand Down Expand Up @@ -245,6 +247,7 @@ def tidy_output(out)
'test/testcases/span/05_html/mark_element.html', # bc of tidy
'test/testcases/block/09_html/xml.html', # bc of tidy
'test/testcases/span/05_html/xml.html', # bc of tidy
'test/testcases/span/text_substitutions/typography_disabled.html', # bc of tidy
].compact
Dir[File.dirname(__FILE__) + '/testcases/**/*.{html,html.19}'].each do |html_file|
next if EXCLUDE_HTML_KD_FILES.any? {|f| html_file =~ /#{f}(\.19)?$/}
Expand Down Expand Up @@ -318,6 +321,7 @@ def tidy_output(out)
'test/testcases/span/text_substitutions/entities_as_char.text',
'test/testcases/span/text_substitutions/entities.text',
'test/testcases/span/text_substitutions/typography.text',
'test/testcases/span/text_substitutions/typography_disabled.text',
('test/testcases/span/03_codespan/rouge/simple.text' if RUBY_VERSION < '2.0'),
('test/testcases/span/03_codespan/rouge/disabled.text' if RUBY_VERSION < '2.0'),
('test/testcases/block/06_codeblock/rouge/simple.text' if RUBY_VERSION < '2.0'), #bc of rouge
Expand Down
38 changes: 38 additions & 0 deletions test/testcases/span/text_substitutions/typography_disabled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<p>This is... something---this too--!</p>

<p>This &lt;<is>&gt; some text, &lt;&lt; this &gt;&gt; too!</is></p>

<p>"Fancy quotes" are 'cool', even in the '80s!
Je t' aime. You're a funny one! Thomas' name
Mark's name. "...you"
"'Nested' quotes are 'possible'", too!
'"Otherway" is "round"'!</p>

<p>'Opening now!'</p>

<p>'80s are really cool.</p>

<p><em>Cluster</em>'s Last Stand.</p>

<p>Nam liber tempor
"...At vero eos et accusam"</p>

<p>"<em>Single underscores</em> should work."</p>

<p>"<em>Single asterisks</em> should work."</p>

<p>'<strong>Double underscores</strong> should work.'</p>

<p>'<strong>Double asterisks</strong> should work.'</p>

<p>"<em>Hurrah!</em>"</p>

<p>'<strong>Absolutely</strong>.'</p>

<p>"...some Text"</p>

<p>"... some Text"</p>

<p>This: "...some Text"</p>

<p>This: "... some Text"</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:disable_parsers: typographic_syms,smart_quotes
:entity_output: symbolic
38 changes: 38 additions & 0 deletions test/testcases/span/text_substitutions/typography_disabled.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
This is... something---this too--!

This <<is>> some text, << this >> too!

"Fancy quotes" are 'cool', even in the '80s!
Je t' aime. You're a funny one! Thomas' name
Mark's name. "...you"
"'Nested' quotes are 'possible'", too!
'"Otherway" is "round"'!

'Opening now!'

'80s are really cool.

<em>Cluster</em>'s Last Stand.

Nam liber tempor
"...At vero eos et accusam"

"_Single underscores_ should work."

"*Single asterisks* should work."

'__Double underscores__ should work.'

'**Double asterisks** should work.'

"_Hurrah!_"

'__Absolutely__.'

"...some Text"

"... some Text"

This: "...some Text"

This: "... some Text"