-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhtml5tize.rb
More file actions
executable file
·47 lines (33 loc) · 885 Bytes
/
html5tize.rb
File metadata and controls
executable file
·47 lines (33 loc) · 885 Bytes
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
42
43
44
45
#!/usr/bin/env ruby
# coding: UTF-8
ARGV.each { |arg|
infile = arg
body = ""
File.open(infile, "r") { |f|
body = f.read
}
need_close_section = false;
body.gsub!(/<\/div>\n+<div +id *= *"outline-container-([0-9])" +class *= *"outline-2" *>\n+<h2 +id *= *"(sec-[0-9])">(.*?)<\/h2> *\n/) { |m|
repl = ""
if $1 != "1"
repl += "</section>\n"
else
repl += "</div>\n"
end
repl += "<section id=\"#{$2}\">\n"
repl += "<div id=\"outline-container-#{$1}\">\n"
repl += "<div class=\"page-header\">\n"
repl += "<h1>#{$3}</h1>\n"
repl += "</div>\n</div>\n"
need_close_section = true
repl
}
idx = body.rindex("</div>")
next if idx == nil
next if body[idx..-1].strip != "</div>"
body = body[0...idx]
body += "\n</section>\n\n" if need_close_section
File.open(infile, "w") { |f|
f.write body
}
}