Introducing the Yatoc gem
require 'yatoc'
require 'kramdown'
s2=<<EOF
# Story 1345
The story of this is not important. Learn more from the text below.
## Foo
This is 1st paragraph
### Train
Work at something
### Travel By Bike
Travel by bike.
## Bar
This is 2nd paragraph
### Mary
Mary had a little lamb
#### Time
Take time to rest
### Weakness
Your weakness is my weakness
--------------
EOF
y = Yatoc.new(Kramdown::Document.new(s2).to_html)
#File.write '/tmp/foo.html', y.to_html
#puts Rexle.new(y.to_toc).xml pretty: true
puts y.to_html
Output
Story 1345
The story of this is not important. Learn more from the text below.
-
1 Foo
- 1.1 Train
- 1.2 Travel By Bike
-
2 Bar
-
2.1 Mary
- 2.1.1 Time
- 2.2 Weakness
-
2.1 Mary
Foo
This is 1st paragraph
Train
Work at something
Travel By Bike
Travel by bike.
Bar
This is 2nd paragraph
Mary
Mary had a little lamb
Time
Take time to rest
Weakness
Your weakness is my weakness
Resources
html toc yatoc gem