Anchors for nested chapters
This commit is contained in:
parent
3ef42983d6
commit
71ec8dc7f6
6 changed files with 48 additions and 11 deletions
|
@ -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": [
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -27,6 +27,10 @@ Chapter 1 paragraph text
|
|||
|
||||
Chapter 2 paragraph text
|
||||
|
||||
### Chapter 2.1
|
||||
|
||||
Chapter 2.1 paragraph text
|
||||
|
||||
|
||||
|
||||
## Related articles
|
||||
|
|
|
@ -63,18 +63,24 @@ The Rty
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h2 id="chapter-1">Chapter 1</h2>
|
||||
<h2 id="chapter-1-юникод">Chapter 1</h2>
|
||||
<p>
|
||||
<span>
|
||||
Chapter 1 paragraph text
|
||||
</span>
|
||||
</p>
|
||||
<h2 id="chapter-2-юникод">Chapter 2</h2>
|
||||
<h2 id="chapter-2">Chapter 2</h2>
|
||||
<p>
|
||||
<span>
|
||||
Chapter 2 paragraph text
|
||||
</span>
|
||||
</p>
|
||||
<h3 id="chapter-2-nested">Chapter 2.1</h3>
|
||||
<p>
|
||||
<span>
|
||||
Chapter 2.1 paragraph text
|
||||
</span>
|
||||
</p>
|
||||
<div>
|
||||
<hr/>
|
||||
<h2>Related articles</h2>
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
"<h#@level#{anchor}>#@title</h#@level>\n" if @level != 1
|
||||
%(<h#@level id="#{anchor}">#@title</h#@level>\n) if @level != 1
|
||||
end
|
||||
|
||||
def build_title_gemtext
|
||||
|
|
Loading…
Reference in a new issue