diff --git a/examples/full.chapters.json b/examples/full.chapters.json
index 1123d13..44ea17e 100644
--- a/examples/full.chapters.json
+++ b/examples/full.chapters.json
@@ -1,16 +1,22 @@
[
{
- "slug": "1",
+ "slug": "1-юникод",
"title": "Chapter 1",
"chapters": [
]
},
{
- "slug": "2-юникод",
+ "slug": "2",
"title": "Chapter 2",
"chapters": [
+ {
+ "slug": "2-nested",
+ "title": "Chapter 2.1",
+ "chapters": [
+ ]
+ }
]
}
]
diff --git a/examples/full.gmi b/examples/full.gmi
index 3c77dd7..c7fdb05 100644
--- a/examples/full.gmi
+++ b/examples/full.gmi
@@ -27,6 +27,10 @@ Chapter 1 paragraph text
Chapter 2 paragraph text
+### Chapter 2.1
+
+Chapter 2.1 paragraph text
+
## Related articles
diff --git a/examples/full.html b/examples/full.html
index 78c5109..321e136 100644
--- a/examples/full.html
+++ b/examples/full.html
@@ -63,18 +63,24 @@ The Rty
-
Chapter 1
+Chapter 1
Chapter 1 paragraph text
-Chapter 2
+Chapter 2
Chapter 2 paragraph text
+Chapter 2.1
+
+
+Chapter 2.1 paragraph text
+
+
Related articles
diff --git a/examples/full.repub b/examples/full.repub
index dc27595..d93bc8b 100644
--- a/examples/full.repub
+++ b/examples/full.repub
@@ -33,7 +33,7 @@ end
-article.chapter '1', 'Chapter 1' do |chapter|
+article.chapter '1-юникод', 'Chapter 1' do |chapter|
chapter.paragraph do |paragraph|
paragraph.text 'Chapter 1 paragraph text'
end
@@ -41,10 +41,18 @@ end
-article.chapter '2-юникод', 'Chapter 2' do |chapter|
+article.chapter '2', 'Chapter 2' do |chapter|
chapter.paragraph do |paragraph|
paragraph.text 'Chapter 2 paragraph text'
end
+
+
+
+ chapter.chapter 'nested', 'Chapter 2.1' do |chapter|
+ chapter.paragraph do |paragraph|
+ paragraph.text 'Chapter 2.1 paragraph text'
+ end
+ end
end
diff --git a/examples/full.summary.txt b/examples/full.summary.txt
index 9374b10..5227adc 100644
--- a/examples/full.summary.txt
+++ b/examples/full.summary.txt
@@ -1,2 +1,2 @@
Annotation paragraph text Chapter 1 Chapter 1 paragraph text Chapter 2
-Chapter 2 paragraph text
+Chapter 2 paragraph text Chapter 2.1 Chapter 2.1 paragraph text
diff --git a/lib/repubmark/elems/chapter.rb b/lib/repubmark/elems/chapter.rb
index e13b72c..31766cf 100644
--- a/lib/repubmark/elems/chapter.rb
+++ b/lib/repubmark/elems/chapter.rb
@@ -54,12 +54,27 @@ module Repubmark
def chapters
{
- slug: @slug,
+ slug: anchor,
title: @title,
chapters: @chapters.map(&:chapters).freeze,
}.freeze
end
+ ##################
+ # Helper methods #
+ ##################
+
+ def anchor
+ if parent.instance_of?(self.class) && @level > 2
+ "#{parent.anchor}-#@slug"
+ elsif (anchor_prefix =
+ String(config[:chapter_anchor_prefix]).strip).empty?
+ @slug
+ else
+ "#{anchor_prefix}-#@slug"
+ end.freeze
+ end
+
###################
# Builder methods #
###################
@@ -118,9 +133,7 @@ module Repubmark
end
def build_title_html
- anchor_prefix = String(config[:chapter_anchor_prefix]).strip
- anchor = %( id="#{anchor_prefix}-#@slug") unless anchor_prefix.empty?
- "#@title\n" if @level != 1
+ %(#@title\n) if @level != 1
end
def build_title_gemtext