Skip to content

Commit

Permalink
GFM parser: quirk to disable auto typographic symbol conversion
Browse files Browse the repository at this point in the history
With GFM, we want to be as close as possible to GitHub Flavored
Markdown. In particular, GitHub does not replace -- with en-dash,
--- with em-dash et cetera, and doing this not only breaks
HTML rendering (resulting in, say, –option instead of --option).

The above replacement also makes header IDs incompatible with those
generated by GitHub, making it way harder to create a document
with intralinks that work both on GitHub and kramdown-generated
HTML.

So, let's introduce another GFM quirk to turn off automatic
typographic symbol conversion. NOTE it is off by default, i.e.
needs to be explicitly enabled.

For more details on the issue and examples, see
#459

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin authored and gettalong committed Oct 26, 2017
1 parent 91f2c7f commit 06b524e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/kramdown/options.rb
Expand Up @@ -614,6 +614,13 @@ def self.simple_hash_validator(val, name)
Note that if this quirk is used, lazy line wrapping does not fully
work anymore!
* no_auto_typographic
Disables automatic conversion of some characters into their
corresponding typographic symbols (like `--` to em-dash etc).
This helps to achieve results closer to what GitHub Flavored
Markdown produces.
Default: paragraph_end
Used by: GFM parser
EOF
Expand Down
1 change: 1 addition & 0 deletions lib/kramdown/parser/gfm.rb
Expand Up @@ -20,6 +20,7 @@ def initialize(source, options)
@id_counter = Hash.new(-1)

@span_parsers.delete(:line_break) if @options[:hard_wrap]
@span_parsers.delete(:typographic_syms) if @options[:gfm_quirks].include?(:no_auto_typographic)
if @options[:gfm_quirks].include?(:paragraph_end)
atx_header_parser = :atx_header_gfm_quirk
@paragraph_end = self.class::PARAGRAPH_END_GFM
Expand Down
3 changes: 3 additions & 0 deletions test/testcases_gfm/no_typographic.html
@@ -0,0 +1,3 @@
<h3 id="header-with---ndash">Header with --ndash</h3>

<h3 id="with------typographic---symbols">with --- &lt;&lt; typographic &gt;&gt; ... symbols</h3>
3 changes: 3 additions & 0 deletions test/testcases_gfm/no_typographic.html.19
@@ -0,0 +1,3 @@
<h3 id="header-with---ndash">Header with --ndash</h3>

<h3 id="with------typographic---symbols">with --- &lt;&lt; typographic &gt;&gt; ... symbols</h3>
1 change: 1 addition & 0 deletions test/testcases_gfm/no_typographic.options
@@ -0,0 +1 @@
:gfm_quirks: [no_auto_typographic]
3 changes: 3 additions & 0 deletions test/testcases_gfm/no_typographic.text
@@ -0,0 +1,3 @@
### Header with --ndash

### with --- << typographic >> ... symbols

0 comments on commit 06b524e

Please sign in to comment.