Skip to content
Browse files

(generate_id) support Vietnamese accents

Vietnamese chars with accents will be converted to non-accent verion
that help the link id (anchor name) readable
  • Loading branch information...
1 parent 1fccba5 commit 7b7ac0210af3068663ad0aec8b69914c319f1fa4 @icy icy committed Feb 9, 2013
View
11 lib/kramdown/converter/base.rb
@@ -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!
View
2 test/testcases/block/04_header/with_auto_ids.html
@@ -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>
View
2 test/testcases/block/04_header/with_auto_ids.text
@@ -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.
Something went wrong with that request. Please try again.