#!/usr/bin/ruby -w require 'cgi' def escapeTextLineToHtml(line) $_ = CGI.escapeHTML(line.chomp()) # Embolden filenames: $_.gsub!(/^([^[:space:]\/]\S*): /, "\\1: ") # Try to detect where martind has quoted a whole paragraph # with a single "> " at the start. # For example, in revision 445 of terminator. $_.gsub!(/^> (.{80,})$/, "
\\1
") # Try to detect quoted text (either traditional Unix mail style or # wiki-like leading whitespace): $_.gsub!(/^(?:>| ) (.*)$/) { |text| " #{text.gsub(' ', ' ')} " } # Turn URLs into links. This regex is very loose, but other implementation I've seen have been too tight, or incorrect. # We could do to revisit this, perhaps using the BNF here as a source: # http://www.w3.org/Addressing/URL/url-spec.txt $_.gsub!(/(http:\/\/\S+)/, "\\1") # Make slight typographical improvements: $_.gsub!(/ -- /, " – ") $_.gsub!(/ --- /, " — ") # Each input line gets a line-break in the HTML: return "#{$_}
\n" end