Created
March 30, 2016 05:04
-
-
Save reasonset/ca7e64b9433e0a6b3f8593fc5362fad5 to your computer and use it in GitHub Desktop.
This file contains 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
diff --git a/puredoc.rb b/puredoc.rb | |
index 4f604f8..a478a58 100755 | |
--- a/puredoc.rb | |
+++ b/puredoc.rb | |
@@ -224,7 +224,7 @@ class PureDoc | |
(cur - i.level).times {|n| result << proc4close.call( (cur - n), ( cur - n - offset ) ) } | |
end | |
- result << proc4each.call(i.level, (i.level - offset), i.title) | |
+ result << proc4each.call(i.level, (i.level - offset), i.title, i.id) | |
cur = i.level | |
end | |
@@ -236,15 +236,15 @@ class PureDoc | |
end | |
end | |
- def stock_header(level, text) | |
- @toc << TOC.new(level, text) | |
+ def stock_header(level, text, id=nil) | |
+ @toc << TOC.new(level, text, id) | |
diff --git a/puredoc.rb b/puredoc.rb | |
index 4f604f8..a478a58 100755 | |
--- a/puredoc.rb | |
+++ b/puredoc.rb | |
@@ -224,7 +224,7 @@ class PureDoc | |
(cur - i.level).times {|n| result << proc4close.call( (cur - | |
n), ( cur - n - offset ) ) } | |
end | |
- result << proc4each.call(i.level, (i.level - offset), i.title) | |
+ result << proc4each.call(i.level, (i.level - offset), i.title, i. | |
id) | |
cur = i.level | |
end | |
@@ -236,15 +236,15 @@ class PureDoc | |
end | |
end | |
- def stock_header(level, text) | |
- @toc << TOC.new(level, text) | |
+ def stock_header(level, text, id=nil) | |
+ @toc << TOC.new(level, text, id) | |
end | |
# Each TOC term. | |
- TOC = Struct.new(:level, :title) | |
+ TOC = Struct.new(:level, :title, :id) | |
# ExtensionNamespace | |
module Extension | |
end | |
-end | |
\ No newline at end of file | |
+end | |
diff --git a/xhtpdoc.rb b/xhtpdoc.rb | |
index b976aab..d9bfbc0 100644 | |
--- a/xhtpdoc.rb | |
+++ b/xhtpdoc.rb | |
@@ -26,6 +26,31 @@ class PureDoc::XHTPureDoc < PureDoc | |
end | |
} | |
+ HEADERLINK_HEADNAME = ->(**arg) { | |
+ if arg[:used_id].key?(arg[:baretext]) | |
+ arg[:used_id][arg[:baretext]] += 1 | |
+ id = ("%s-%d" % [ arg[:baretext], arg[:used_id][arg[:baretext]] ] ) | |
+ elem = '<h%1$d id="%2$s">%3$s</h%1$d>' % [ arg[:level], id, arg[:text] ] | |
+ else | |
+ id = arg[:baretext] | |
+ elem = '<h%1$d id="%2$s">%3$s</h%1$d>' % [ arg[:level], arg[:baretext], arg[:text] ] | |
+ arg[:used_id][arg[:baretext]] = 0 | |
+ end | |
+ | |
+ [ elem, id ] | |
+ | |
+ } | |
+ HEADERLINK_SECTION = ->(**arg) { | |
+ id = 'Section-%d' % arg[:secnum] | |
+ elem = '<h%1$d id="%2$s">%3$s</h%1$d>' % [ arg[:level], id , arg[:text] ] | |
+ [ elem, id ] | |
+ } | |
+ HEADERLINK_NAME_AND_SECTION = ->(**arg) { | |
+ id = '%d_%s' % [ arg[:secnum], arg[:baretext] ] | |
+ elem = '<h%1$d id="">%4$s</h%1$d>' % [ arg[:level], id, arg[:text] ] | |
+ [ elem, id ] | |
+ } | |
+ | |
##### INITIALIZATION ##### | |
@@ -35,8 +60,13 @@ class PureDoc::XHTPureDoc < PureDoc | |
@indent_spaces = ENV["puredoc_indent_spaces"] || "\t" # Set default indent string. Use a tab by default. | |
# If environment paramater $puredoc_indent_spaces set, | |
# use instead a tab. | |
+ @section_count = 0 # Count up on each header element. | |
+ @headerlink_style = HEADERLINK_HEADNAME # Whice style of header element's id. | |
+ @used_header_id = {} | |
end | |
+ attr_writer :headerlink_style | |
+ | |
### ESCAPE ### | |
@@ -251,22 +281,26 @@ class PureDoc::XHTPureDoc < PureDoc | |
# Header | |
def self.header(level) | |
- define_method(("h%d" % level).to_sym) do |text| | |
- puredoc_element(("h%d" % level).to_sym) do | |
- #Make no tag text. | |
- baretext = text.dup | |
- while baretext.gsub!(/<[^<>]*>/, '') | |
- nil | |
- end | |
- | |
- # If this level header is included in TOC store range. | |
- if @toc_range.include?(level) | |
- @toc << TOC.new(level, esc!(baretext)) | |
- end | |
+ define_method(("h%d" % level).to_sym) do |text| | |
+ puredoc_element(("h%d" % level).to_sym) do | |
+ #Make no tag text. | |
+ baretext = text.dup | |
+ while baretext.gsub!(/<[^<>]*>/, '') | |
+ nil | |
+ end | |
+ | |
+ @section_count += 1 | |
+ elem, id = @headerlink_style.(level: level, text: text, baretext: baretext, secnum: @section_count, used_id: @used_header_id) | |
- "\n" + stringify("<a id=\"%3$s\"></a><h%1$d>%2$s</h%1$d>" % [level, esc(text), esc!(baretext)]) | |
- end | |
+ # If this level header is included in TOC store range. | |
+ if @toc_range.include?(level) | |
+ @toc << TOC.new(level, esc!(baretext), id) | |
+ end | |
+ | |
+ elem | |
+ | |
end | |
+ end | |
end | |
@@ -396,6 +430,10 @@ class PureDoc::XHTPureDoc < PureDoc | |
raise ArgumentError.new("tbl element should take a block that returns arraies on array.") | |
end | |
+ if c | |
+ text << "<caption>" << esc(c) << "</caption>" | |
+ end | |
+ | |
# thead | |
if h > 0 | |
text << '<thead>' | |
@@ -403,7 +441,7 @@ class PureDoc::XHTPureDoc < PureDoc | |
while hrindex <= h | |
r = rows.shift | |
text << '<tr>' | |
- text << r.each.with_index.map {|x, i| (i+1) <= l ? sprintf('<th>%s</th>', x) : sprintf('<td>%s</td>', x) } | |
+ text << r.each.with_index.map {|x, i| (i+1) <= l ? sprintf('<th>%s</th>', esc(x)) : sprintf('<td>%s</td>', esc(x)) } | |
text << '</tr>' | |
hrindex += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment