summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2018-05-02 01:53:13 -0600
committerGitHub <noreply@github.com>2018-05-02 01:53:13 -0600
commit2ecca66a5d5801fe8efc14f8dc676db227b37d8a (patch)
tree639375dc33e80bc0c8228de46f9dd56f9b73c66c
parent02e63b9cf081fe69f67973536a4539aedf675fab (diff)
replace dot with idseparator in generated ID (PR #2744)
-rw-r--r--lib/asciidoctor.rb2
-rw-r--r--lib/asciidoctor/section.rb4
-rw-r--r--test/sections_test.rb8
3 files changed, 7 insertions, 7 deletions
diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb
index bf8a992f..d089179f 100644
--- a/lib/asciidoctor.rb
+++ b/lib/asciidoctor.rb
@@ -655,7 +655,7 @@ module Asciidoctor
# Matches invalid ID characters in a section title.
#
# NOTE uppercase chars not included since expression is only run on a lowercase string
- InvalidSectionIdCharsRx = /<[^>]+>|&(?:[a-z][a-z]+\d{0,2}|#\d\d\d{0,4}|#x[\da-f][\da-f][\da-f]{0,3});|[^ #{CC_WORD}-]+?/
+ InvalidSectionIdCharsRx = /<[^>]+>|&(?:[a-z][a-z]+\d{0,2}|#\d\d\d{0,4}|#x[\da-f][\da-f][\da-f]{0,3});|[^ #{CC_WORD}\-.]+?/
## Lists
diff --git a/lib/asciidoctor/section.rb b/lib/asciidoctor/section.rb
index f1baab94..5ff15d9c 100644
--- a/lib/asciidoctor/section.rb
+++ b/lib/asciidoctor/section.rb
@@ -198,10 +198,10 @@ class Section < AbstractBlock
pre = attrs['idprefix'] || '_'
if (sep = attrs['idseparator'])
if sep.length == 1 || (!(no_sep = sep.empty?) && (sep = attrs['idseparator'] = sep.chr))
- sep_sub = sep == '-' ? ' -' : %( #{sep}-)
+ sep_sub = sep == '-' || sep == '.' ? ' .-' : %( #{sep}.-)
end
else
- sep, sep_sub = '_', ' _-'
+ sep, sep_sub = '_', ' _.-'
end
gen_id = %(#{pre}#{title.downcase.gsub InvalidSectionIdCharsRx, ''})
if no_sep
diff --git a/test/sections_test.rb b/test/sections_test.rb
index 5fde1109..34791b19 100644
--- a/test/sections_test.rb
+++ b/test/sections_test.rb
@@ -46,9 +46,9 @@ context 'Sections' do
assert_equal '_state_of_the_art_design', sec.id
end
- test 'synthetic id drops dots' do
+ test 'synthetic id replaces dots with separator' do
sec = block_from_string("== Section 1.1.1")
- assert_equal '_section_111', sec.id
+ assert_equal '_section_1_1_1', sec.id
end
test 'synthetic id prefix can be customized' do
@@ -76,9 +76,9 @@ context 'Sections' do
assert_equal '_state-of-the-art-design', sec.id
end
- test 'synthetic id separator can be dot' do
+ test 'synthetic id separator can be dot and dots are preserved' do
sec = block_from_string(":idseparator: .\n\n== Version 5.0.1")
- assert_equal '_version.501', sec.id
+ assert_equal '_version.5.0.1', sec.id
end
test 'synthetic id separator can only be one character' do