You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The adapted headreg expression should parse the
textile IDs from headings, e.g. "h2(#ID)." :
headreg = /^\s*h([1-6])#?\((.*)\)\.\s+(.*)/
def generate_toc (file_name, headreg)
document = IO.read(file_name)
toc = ""
document.gsub(headreg) do |match|
number = $1
id = $2
title = $3
toc << '#' * number.to_i + ' "' + title + '":#' + id +
"\n" end
RedCloth.new(toc).to_html
end
To manually assign descriptive IDs to headers, one may explicitly write them like
"h2(#ch1). Chapter 1".
Redcloth already renders this as <h2 id=“ch1”>Chapter 1</h2>
(using id for anchors is ok, html5 even dropped named <a> tags)
and it can be cross referenced as "":#ch1
Another possibility may be auto IDs on saving:
All headers without a given ID, for example,
h2. Chapter 1
may automatically get expanded with a random not yet used 4-5 character
string, and get saved for example as
h2(#45i4t). Chapter 1
The text was updated successfully, but these errors were encountered:
The following snippet from
http://snippets.aktagon.com/snippets/48-generate-a-toc-for-a-textile-file
has a generate_toc method, probably usefull to auto-render a table of
contents for a zazen "ToC." paragraph,, or a tag?
The adapted headreg expression should parse the
textile IDs from headings, e.g. "h2(#ID)." :
To manually assign descriptive IDs to headers, one may explicitly write them like
"h2(#ch1). Chapter 1".
Redcloth already renders this as
<h2 id=“ch1”>Chapter 1</h2>
(using id for anchors is ok, html5 even dropped named
<a>
tags)and it can be cross referenced as "":#ch1
Another possibility may be auto IDs on saving:
All headers without a given ID, for example,
h2. Chapter 1
may automatically get expanded with a random not yet used 4-5 character
string, and get saved for example as
h2(#45i4t). Chapter 1
The text was updated successfully, but these errors were encountered: