| @@ -4,29 +4,115 @@ module Docs · 3 unmodified lines |
| 4 | def call | 4 | def call |
| 5 | | 5 | |
| 6 | # remove unwanted elements | 6 | # remove unwanted elements |
| 7 | css('#footer', '#package-header', '#module-header', '#synopsis', '.link', '#table-of-contents', '.empty', '.package').remove | 7 | css('#footer', '#package-header', '#module-header', '#synopsis', '.link', '#table-of-contents', '.show .empty', '.package').remove |
| | 8 | |
| | 9 | css('pre').each do |node| |
| | 10 | node.add_css_class('example') |
| | 11 | end |
| | 12 | |
| | 13 | # cpations in tables are h3 |
| | 14 | css('table .caption').each do |node| |
| | 15 | node.name = 'h3' |
| | 16 | end |
| 8 | | 17 | |
| 9 | # turn captions into real headers | 18 | # turn captions into real headers |
| 10 | css('.caption').each do |node| | 19 | css('.caption').each do |node| |
| | 20 | node.name = 'h1' |
| | 21 | end |
| | 22 | |
| | 23 | css('.top > .caption').each do |node| |
| 11 | node.name = 'h2' | 24 | node.name = 'h2' |
| 12 | end | 25 | end |
| 13 | | 26 | |
| 14 | css('table .caption').each do |node| | 27 | # subsections |
| | 28 | css('.top > .subs > .caption', '.fields > .caption').each do |node| |
| 15 | node.name = 'h3' | 29 | node.name = 'h3' |
| 16 | end | 30 | end |
| 17 | | 31 | |
| 18 | # # turn source listing in to pre | 32 | # subsubsections |
| 19 | css('.src').each do |node| | 33 | css('.top > .subs > .subs > .caption').each do |node| |
| 20 | node.name = 'pre' | 34 | node.name = 'h4' |
| 21 | end | 35 | end |
| 22 | | 36 | |
| | 37 | css('.top > .subs > .subs > .subs > .caption').each do |node| |
| | 38 | node.name = 'h5' |
| | 39 | end |
| | 40 | |
| | 41 | css('.top > .subs > .subs > .subs > .subs > .caption').each do |node| |
| | 42 | node.name = 'h6' |
| | 43 | end |
| | 44 | |
| | 45 | # turn source listing in to pre |
| | 46 | css('.src').each do |node| |
| | 47 | if node.name == "td" |
| | 48 | # pre = doc.create_element 'pre' |
| | 49 | # pre.children = node.children |
| | 50 | # node.children = [pre] |
| | 51 | else |
| | 52 | node.name = 'pre' |
| | 53 | end |
| | 54 | end |
| 23 | | 55 | |
| 24 | if at_css('h1') && at_css('h1').content == 'Haskell Hierarchical Libraries' | 56 | if at_css('h1') && at_css('h1').content == 'Haskell Hierarchical Libraries' |
| 25 | css('h1').remove | 57 | css('h1').remove |
| 26 | end | 58 | end |
| 27 | | 59 | |
| | 60 | css('a').each do |node| |
| | 61 | if node['name'] |
| | 62 | node['id'] = node['name'] |
| | 63 | end |
| | 64 | end |
| | 65 | |
| | 66 | css('.caption').each do |node| |
| | 67 | if node.content == 'Arguments' |
| | 68 | node.remove |
| | 69 | end |
| | 70 | end |
| | 71 | |
| | 72 | # add some informational boxes |
| | 73 | css('em').each do |node| |
| | 74 | if node.content == 'Deprecated.' |
| | 75 | # Make deprecated messages red. |
| | 76 | node.parent.add_css_class('warning') |
| | 77 | elsif node.content =~ /O\(.*\)/ |
| | 78 | # this is big_O notation, but only apply the class if this is not |
| | 79 | # inside running text (it must be at the start of a paragraph) |
| | 80 | # from: |
| | 81 | # <p><em>O(n)</em>. Koel ok</p> |
| | 82 | # to: |
| | 83 | # <p class="with-complexity"> |
| | 84 | # <span class="complexity">O(n)</span> |
| | 85 | # <span>Koel ok</span> |
| | 86 | # </p> |
| | 87 | if node.previous == nil |
| | 88 | node.add_css_class('complexity') # add css class |
| | 89 | node.name="span" # just make it div |
| | 90 | node.next.content = node.next.content.gsub(/^. /, "") # remove . if directly after em |
| | 91 | node.content = node.content.gsub(/\.$/, "") # remove trailing . if it's inside em |
| | 92 | |
| | 93 | # reparent the nodes |
| | 94 | cont = doc.document.create_element "p", :class => "with-complexity" |
| | 95 | node.parent.previous = cont |
| | 96 | par = node.parent |
| | 97 | node.parent = cont |
| | 98 | par.parent = cont |
| | 99 | par.name = "span" |
| | 100 | end |
| | 101 | elsif node.content =~ /Since: .*/ |
| | 102 | # add box to 'Since:' annotations |
| | 103 | node.add_css_class('added') |
| | 104 | end |
| | 105 | end |
| | 106 | |
| 28 | doc | 107 | doc |
| 29 | end | 108 | end |
| 30 | end | 109 | end |
| 31 | end | 110 | end |
| 32 | end | 111 | end |
| | 112 | |
| | 113 | class Nokogiri::XML::Node |
| | 114 | def add_css_class( *classes ) |
| | 115 | existing = (self['class'] || "").split(/\s+/) |
| | 116 | self['class'] = existing.concat(classes).uniq.join(" ") |
| | 117 | end |
| | 118 | end |