forked from Polymer/old-docs-site
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_toc.rb
More file actions
41 lines (34 loc) · 1.01 KB
/
process_toc.rb
File metadata and controls
41 lines (34 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require "octopress-hooks"
class ProcessTOCHook < Octopress::Hooks::Page
# # Manipulate page/post data before it has been processed with Liquid or
# # Converters like Markdown or Textile.
# #
# def pre_render(page)
# #page.content = highlight_code(page.content)
# end
# # Manipulate page/post data after content has been processed to html.
# #
# def post_render(page)
# # page.content = wrap_toc_in_details(page.content)
# page.output = wrap_toc_in_details(page.output)
# end
# # Access page/post data after it has been successfully written to disk.
# #
# def post_write(page)
# #log_something(page.title)
# end
def post_render(page)
wrap_toc_in_details(page.output)
end
# Moves the generated <ul id="markdown-toc"> into a <details> element.
def wrap_toc_in_details(output)
output.gsub! /\<\!--TOC_START--\>(.+)?\<\!--TOC_END--\>/m do
<<-END
<details id="toc">
<summary>Table of contents</summary>
#{$1}
</details>
END
end
end
end