Skip to content
Browse files

Update HTML generation for new verson of dicsount.

Move TOC generation and cleanup to an external script that's easier to maintain.
  • Loading branch information...
1 parent ce9057c commit e9e6b6c62d0110eec55cd74c55b913ae33ba7330 @theory committed Feb 26, 2011
Showing with 58 additions and 5 deletions.
  1. +1 −0 .gitattributes
  2. +2 −3 Makefile
  3. +2 −2 doc/pgtap.md
  4. +53 −0 tocgen
View
1 .gitattributes
@@ -1,2 +1,3 @@
.gitignore export-ignore
.gitattributes export-ignore
+tocgen export-ignore
View
5 Makefile
@@ -161,8 +161,7 @@ test: test/setup.sql
pg_prove --pset tuples_only=1 $(TESTS)
html:
- /usr/local/discount-1.6.7/bin/markdown -F 0x1000 doc/pgtap.md > doc/pgtap.html
- perl -ne 'BEGIN { $$prev = 0; $$lab = ""; print "<h1>Contents</h1>\n<ul>\n" } if (m{<h([123])\s+id="(?:`([^(]+)(?:[^"]+)|([^"]+))">((<code>[^(]+)?.+?)</h\1>}) { next if $$lab && $$lab eq $$5; $$lab = $$5; if ($$prev) { if ($$1 != $$prev) { print $$1 > $$prev ? $$1 - $$prev > 1 ? "<ul><li><ul>" : "<ul>\n" : $$prev - $$1 > 1 ? "</li></ul></li></ul></li>\n" : "</li></ul></li>\n"; $$prev = $$1; } else { print "</li>\n" } } else { $$prev = $$1; } print qq{<li><a href="#} . ($$2 || $$3) . q{">} . ($$5 ? "$$5()</code>" : $$4) . "</a>" } END { print "</li>\n</ul>\n" }' doc/pgtap.html > doc/toc.html
- perl -pi -e 'BEGIN { my %seen }; s{(<h[123]\s+id=")`([^(]+)[^"]+}{"$$1$$2" . ($$seen{$$2}++ || "")}ge;' doc/pgtap.html
+ markdown -ftoc doc/pgtap.md > doc/pgtap.html
+ ./tocgen doc/pgtap.html 2> doc/toc.html
perl -MPod::Simple::XHTML -E "my \$$p = Pod::Simple::XHTML->new; \$$p->html_header_tags('<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">'); \$$p->strip_verbatim_indent(sub { (my \$$i = \$$_[0]->[0]) =~ s/\\S.*//; \$$i }); \$$p->parse_from_file('`perldoc -l pg_prove`')" > doc/pg_prove.html
View
4 doc/pgtap.md
@@ -3835,12 +3835,12 @@ discouraged:
We recommend that you pick one style or another of TODO to be on the safe
side.
-### todo_end() ###
+### `todo_end()` ###
Stops running tests as TODO tests. This function is fatal if called without a
preceding `todo_start()` method call.
-### in_todo() ###
+### `in_todo()` ###
Returns true if the test is currently inside a TODO block.
View
53 tocgen
@@ -0,0 +1,53 @@
+#!/usr/bin/env perl -n -pi
+
+our $prevn;
+our $previd;
+our %seen;
+
+BEGIN {
+ $prevn = 0;
+ $previd = '';
+ print STDERR "<h1>Contents</h1>\n<ul>\n";
+}
+
+if (m{
+ <h([123])\s+id=" # 1. hn
+ (?:
+ L[.]code[.+]([^.]+)(?:[^"]+) # 2. funcname
+ | ([^"]+) # 3. id
+ )
+ ">
+ ( # 4. header
+ (<code>[^(]+)?.+? # 5. label
+ )
+ </h\1>
+}x) {
+ # Clean up the ID a bit.
+ my ($hn, $func, $id, $val, $label) = ($1, $2, $3, $4, $5);
+ $id = $func || $id;
+ if ($id) {
+ $id =~ s{L?[.]code[.]}{}g;
+ $id =~ s{[.]{2,}}{.}g;
+ }
+ if ($previd ne $id) {
+ $previd = $id;
+ if ($prevn) {
+ if ($hn != $prevn) {
+ print STDERR $hn > $prevn
+ ? $hn - $prevn > 1
+ ? "<ul><li><ul>" : "<ul>\n" : $prevn - $hn > 1
+ ? "</li></ul></li></ul></li>\n" : "</li></ul></li>\n";
+ $prevn = $hn;
+ } else {
+ print STDERR "</li>\n"
+ }
+ } else {
+ $prevn = $hn;
+ }
+ print STDERR qq{<li><a href="#} . ($func || $id) . q{">} . ($5 ? "$5()</code>" : $val) . "</a>";
+ }
+
+ $_ = qq{<h$hn id="$id} . ($seen{$id}++ || '') . qq{">$val</h$hn>\n};
+}
+
+END { print STDERR "</li>\n</ul>\n" }

0 comments on commit e9e6b6c

Please sign in to comment.
Something went wrong with that request. Please try again.