Created
October 15, 2011 16:46
-
-
Save sugamasao/1289822 to your computer and use it in GitHub Desktop.
ReVIEWのh1とかのタグの a タグをどうにかする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/review/htmlbuilder.rb | |
def headline(level, label, caption) | |
prefix, anchor = headline_prefix(level) | |
puts '' if level > 1 | |
a_id = anchor.nil? ? "" : "h#{anchor}" | |
if caption.empty? | |
# ここの出力が何が正しいのかよくわかんないんだよなー | |
unless label.nil? | |
puts %Q[<a id="#{a_id}" >#{a_id}</a>] unless a_id.empty? | |
end | |
else | |
h_id = label.nil? ? "" : %Q[id="#{label}"] | |
puts %Q[<h#{level}#{h_id}><a id="#{a_id}">#{prefix}#{compile_inline(caption)}</a></h#{level}>] | |
end | |
end | |
# bin/review-epubmaker | |
# ePubの目次を作るときに上記の h タグをパースするので、合わせて変更する必要がある | |
def getanchors(filename) | |
File.open(filename) {|f| | |
file = filename.sub(/.+\//, '') | |
f.each_line {|l| | |
#if l =~ /\A<h(\d)><a id=\"(.+?)\" \/>(.+?)<\/h/ | |
if l =~ /\A<h(\d)><a id=\"(.+?)\">(.+?)<\/a/ | |
# level, ID, content | |
@tocdesc << [$1.to_i, file, $2, $3] | |
end | |
} | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment