mirror of
https://github.com/pyenv/pyenv.git
synced 2025-11-18 00:03:45 -05:00
replace build system with generated table of contents
Gets rid of `doc/README.mdtoc` and its build script. Since GitHub.com
renders anchors for each heading, all we have to do is put a simple
table of contents into `README.md` itself, and everything will get
linked up nicely.
Pros of this approach:
* We don't have to point out to people not to edit `README.md` anymore
* We don't have to run the build script each time README gets edited
Cons of this change:
* The "chapter" numbers are lost. They were silly anyway.
`doc/mdtoc` renders a Markdown table of contents for a Markdown file.
`doc/filter-toc` filters that down to only headings after ToC.
This script can be used to easily insert ToC into the current document
when editing `README.md` with, e.g., Vim:
:read !doc/filter-toc %
This commit is contained in:
33
doc/mdtoc
Executable file
33
doc/mdtoc
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'escape_utils'
|
||||
|
||||
start_at_level = 2
|
||||
|
||||
headers = Hash.new(0)
|
||||
|
||||
anchor = lambda { |title|
|
||||
href = title.downcase
|
||||
href.gsub!(/[^\w\- ]/, '') # remove punctuation
|
||||
href.gsub!(' ', '-') # replace spaces with dash
|
||||
href = EscapeUtils.escape_uri(href) # escape extended UTF-8 chars
|
||||
|
||||
uniq = (headers[href] > 0) ? "-#{headers[href]}" : ''
|
||||
headers[href] += 1
|
||||
|
||||
href + uniq
|
||||
}
|
||||
|
||||
ARGF.each_line do |line|
|
||||
if line =~ /^(#+) (.+?)#*$/
|
||||
level = $1.size
|
||||
next if level < start_at_level
|
||||
title = $2.strip
|
||||
href = anchor.call title
|
||||
|
||||
puts "%s* [%s](#%s)" % [
|
||||
' ' * (level - start_at_level),
|
||||
title,
|
||||
href
|
||||
]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user