forked from Polymer/old-docs-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_toc.rb
41 lines (34 loc) · 989 Bytes
/
process_toc.rb
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 "jekyll-page-hooks"
#gem 'jekyll-page-hooks'
module Jekyll
class ProcessTOC < PageHooks
# 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)
end
# Access page/post data after it has been successfully written to disk.
#
def post_write(page)
#log_something(page.title)
end
# Plugin methods
# Moves the generated <ul id="markdown-toc"> into a <details> element.
def wrap_toc_in_details(content)
content.gsub /\<\!--TOC_START--\>(.+)?\<\!--TOC_END--\>/m do
<<-END
<details id="toc">
<summary>Table of contents</summary>
#{$1}
</details>
END
end
end
end
end