Skip to content

Commit

Permalink
Update parser to respect 'transliterated_header_ids' kramdown option (k…
Browse files Browse the repository at this point in the history
…ramdown#22)

While using 'transliterated_header_ids: true', one should get something like this:
<h3 id="abc-def-ouss">abc def öúß</h3>
  • Loading branch information
kill9zombie authored Jan 8, 2021
1 parent a3f87b9 commit f1012be
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ task :gemfile do
gem 'minitest', '~> 5.0'
gem 'rouge', '~> 3.0'
gem 'rubocop', '~> 0.62.0'
gem 'stringex', '~> 2.8.5'
RUBY
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/kramdown/parser/gfm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def update_elements(element)
update_text_type(element, child)
elsif child.type == :html_element
child
elsif child.type == :header && @options[:auto_ids] && @options[:transliterated_header_ids]
# Let the kramdown converter create the ID
child
elsif child.type == :header && @options[:auto_ids] && !child.attr.key?('id')
child.attr['id'] = generate_gfm_header_id(child.options[:raw_text])
child
Expand Down
27 changes: 27 additions & 0 deletions test/testcases/header_ids_with_transliteration.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<h3 id="myid">test</h3>

<h3 id="variablename">variable_name</h3>

<h3 id="abc-def-ouss">abc def öúß</h3>

<h3 id="abc-192">192 abc 192</h3>

<h3 id="section">;.;;</h3>

<h3 id="variablename-1">variable_name</h3>

<h3 id="variablename-2">variable_name</h3>

<h3 id="section-1">;;</h3>

<h3 id="before-after-tab">before after tab</h3>

<h3 id="with-code">with <code>code</code></h3>

<h3 id="with--a-space">with  ä space</h3>

<h3 id="with-smart-quotes">With “smart” quotes</h3>

<h3 id="with------typographic---symbols">with — « typographic » … symbols</h3>

<h3 id="with-m5">with \(m=5\)</h3>
2 changes: 2 additions & 0 deletions test/testcases/header_ids_with_transliteration.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:auto_ids: true
:transliterated_header_ids: true
27 changes: 27 additions & 0 deletions test/testcases/header_ids_with_transliteration.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
### test {#myid}

### variable_name

### abc def öúß

### 192 abc 192

### ;.;;

### variable_name

### variable_name

### ;;

### before after tab

### with `code`

### with &nbsp;&auml;&nbsp;space

### With "smart" quotes

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

### with $$m=5$$

0 comments on commit f1012be

Please sign in to comment.