lib/github/mandoc.rb
def filter(source, path = "")
				@doc = Nokogiri::HTML(source, &:noblanks)
				@path = path
				@doc.css("table.head, table.foot").remove

				# Replace unwanted or superfluous elements with their contents
				@doc.css(".Nd, .permalink, .selflink, table + br").each { |el| unwrap el }

				fix_implicit_paragraphs
				fix_synopses
				fix_anchors
				replace_unwhitelisted_tags
				fix_double_nested_tags %w[code b]
				fix_broken_references

				# Merge adjacent <code> elements
				gsub({
					%r{</code\s*>\s+<code[^>]*>}i => " ",
					%r{</code\s*><code[^>]*>}i    => "",
					%r{(?>\R[ \t]*)+</pre>\s*}    => "\n</pre>"
				})

				# Strip empty paragraph nodes
				@doc.css("p").each { |p| p.remove unless p.content =~ /\S/ }

				# Make indented regions more conspicuous
				fix_displays

				# Clean up whitespace for more consistent testing
				squash_empty_lines
				@doc.css("h1, h2, h3, h4, h5, h6, p, a").each { |el| normalise_whitespace el }
				gsub %r{<p(?=\s|>)[^>]*>\K +| +(?=</p>)}

				# Finally, strip anything doomed to be filtered by GitHub's HTML sanitiser
				%w[class style title].each { |attr| @doc.css("[#{attr}]").remove_attr(attr) }
				@doc.css("section[id]").each { |el| el.name = "div" }
				@doc.css("section").each { |el| unwrap el }
				gsub %r{\s*<div(?!.*?\sid=")[^>]*>\s*</div\s*>\s*}i, ""
			end
# Optimise the output of `mandoc -Thtml`
Optimise the output of `mandoc -Thtml`
Optimise the output of ` mandoc - Thtml `
def filter(source, path = "")
				@doc = Nokogiri::HTML(source, &:noblanks)
				@path = path
				@doc.css("table.head, table.foot").remove
				@doc.css(".Nd, .permalink, .selflink, table + br").each { |el| unwrap el }
				fix_implicit_paragraphs
				fix_synopses
				fix_anchors
				replace_unwhitelisted_tags
				fix_double_nested_tags %w[code b]
				fix_broken_references
				gsub({
					%r{</code\s*>\s+<code[^>]*>}i => " ",
					%r{</code\s*><code[^>]*>}i    => "",
					%r{(?>\R[ \t]*)+</pre>\s*}    => "\n</pre>"
				})
				@doc.css("p").each { |p| p.remove unless p.content =~ /\S/ }
				fix_displays
				squash_empty_lines
				@doc.css("h1, h2, h3, h4, h5, h6, p, a").each { |el| normalise_whitespace el }
				gsub %r{<p(?=\s|>)[^>]*>\K +| +(?=</p>)}
				%w[class style title].each { |attr| @doc.css("[#{attr}]").remove_attr(attr) }
				@doc.css("section[id]").each { |el| el.name = "div" }
				@doc.css("section").each { |el| unwrap el }
				gsub %r{\s*<div(?!.*?\sid=")[^>]*>\s*</div\s*>\s*}i, ""
			end
def filter ( source , path = "" ) @doc = Nokogiri :: HTML ( source , & :noblanks ) @path = path @doc . css ( "table.head, table.foot" ) . remove @doc . css ( ".Nd, .permalink, .selflink, table + br" ) . each { | el | unwrap el } fix_implicit_paragraphs fix_synopses fix_anchors replace_unwhitelisted_tags fix_double_nested_tags %w[ code b ] fix_broken_references gsub ( { %r{ </code \s *> \s +<code[^>]*> }i => " " , %r{ </code \s *><code[^>]*> }i => "" , %r{ (?> \R [  \t ]*)+</pre> \s * } => "\n</pre>" } ) @doc . css ( "p" ) . each { | p | p . remove unless p . content =~ / \S / } fix_displays squash_empty_lines @doc . css ( "h1, h2, h3, h4, h5, h6, p, a" ) . each { | el | normalise_whitespace el } gsub %r{ <p(?= \s |>)[^>]*> \K  +| +(?=</p>) } %w[ class style title ] . each { | attr | @doc . css ( "[#{attr}]" ) . remove_attr ( attr ) } @doc . css ( "section[id]" ) . each { | el | el . name = "div" } @doc . css ( "section" ) . each { | el | unwrap el } gsub %r{ \s *<div(?!.*? \s id=")[^>]*> \s *</div \s *> \s * }i , "" end
Optimise the output of `mandoc -Thtml`
Optimise the output of ` mandoc - Thtml `
# Replace unwanted or superfluous elements with their contents # Merge adjacent <code> elements # Strip empty paragraph nodes # Make indented regions more conspicuous # Clean up whitespace for more consistent testing # Finally, strip anything doomed to be filtered by GitHub's HTML sanitiser
source
path