diff --git a/lib/rocco.rb b/lib/rocco.rb index 6d05e9b..2debdee 100644 --- a/lib/rocco.rb +++ b/lib/rocco.rb @@ -77,7 +77,8 @@ protected # Combine all code blocks into a single big stream and run through # pygments. We `popen` a pygmentize process and then fork off a # writer process. - open("|pygmentize -l ruby -f html", 'rw') do |fd| + code_html = nil + open("|pygmentize -l ruby -f html", 'r+') do |fd| fork { fd.close_read fd.write code_blocks.join("\n# DIVIDER\n") @@ -86,10 +87,18 @@ protected } fd.close_write - code_html = fd.read.split(/\n*# DIVIDER<\/span>\n*/m) + code_html = fd.read fd.close_read end + # Do some post-processing on the pygments output to remove + # partial `
` blocks. We'll add these back when we build to main
+    # document.
+    code_html = code_html.
+      split(/\n*# DIVIDER<\/span>\n*/m).
+      map { |code| code.sub(/\n?
/m, '') }.
+      map { |code| code.sub(/\n?<\/pre><\/div>\n/m, '') }
+
     # Combine the docs and code lists into the same sections style list we
     # started with.
     docs_html.zip(code_html)
@@ -99,11 +108,15 @@ public
   def to_html
     buf = []
     buf << ""
-    buf << ""
+    buf << ""
+    buf << ""
+    buf << ""
+    buf << ""
+    buf << "
" @sections.each do |docs,code| buf << "" - buf << "" - buf << "" + buf << "" + buf << "" buf << "" end buf << "
#{docs}#{code}#{docs}
#{code}
"