Skip to content

Commit

Permalink
(generate_id) support Vietnamese accents
Browse files Browse the repository at this point in the history
Vietnamese chars with accents will be converted to non-accent verion
that help the link id (anchor name) readable
  • Loading branch information
icy committed Feb 9, 2013
1 parent 1fccba5 commit 7b7ac02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/kramdown/converter/base.rb
Expand Up @@ -164,7 +164,16 @@ def extract_code_language!(attr)
# Uses the option +auto_id_prefix+: the value of this option is prepended to every generated
# ID.
def generate_id(str)
gen_id = str.gsub(/^[^a-zA-Z]+/, '')
# Convert Vietnamese accents to non-accent version
# This will help the link readable
vntext_src = "áàảãạăắằẳẵặâấầẩẫậđéèẻẽẹêếềểễệíìỉĩịóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵ"
vntext_dst = "aaaaaaaaaaaaaaaaadeeeeeeeeeeeiiiiioooooooooooooooouuuuuuuuuuuuyyyyy"
vntext_src += "ÁÀẢÃẠĂẮẰẲẴẶÂẤẦẨẪẬĐÉÈẺẼẸÊẾỀỂỄỆÍÌỈĨỊÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢÚÙỦŨỤƯỨỪỬỮỰÝỲỶỸỴ"
vntext_dst += vntext_dst.upcase

gen_id = str
gen_id.tr!(vntext_src, vntext_dst)
gen_id.gsub!(/^[^a-zA-Z]+/, '')
gen_id.tr!('^a-zA-Z0-9 -', '')
gen_id.tr!(' ', '-')
gen_id.downcase!
Expand Down
2 changes: 2 additions & 0 deletions test/testcases/block/04_header/with_auto_ids.html
Expand Up @@ -17,3 +17,5 @@ <h1 id="section-1">33333</h1>
<h2 id="hallo-2">hallO</h2>

<h1>Header without ID</h1>

<h1 id="day-la-vi-du-voi-tieng-viet">Đây là ví dụ với tiếng Việt</h1>
2 changes: 2 additions & 0 deletions test/testcases/block/04_header/with_auto_ids.text
Expand Up @@ -20,3 +20,5 @@ Not now

# Header without ID
{: id=""}

# Đây là ví dụ với tiếng Việt

0 comments on commit 7b7ac02

Please sign in to comment.