Class: Coradoc::ReverseAdoc::Plugin::Plateau
- Inherits:
-
Coradoc::ReverseAdoc::Plugin
- Object
- Coradoc::ReverseAdoc::Plugin
- Coradoc::ReverseAdoc::Plugin::Plateau
- Defined in:
- lib/coradoc/reverse_adoc/plugins/plateau.rb
Overview
This plugin enhances documents from the PLATEAU project to extract more data.
Usage: reverse_adoc -rcoradoc/reverse_adoc/plugins/plateau
--external-images -u raise --output _out/index.adoc index.html
Instance Attribute Summary
Attributes inherited from Coradoc::ReverseAdoc::Plugin
#asciidoc_string, #coradoc_tree, #html_tree
Instance Method Summary collapse
- #handle_headers(node, coradoc, state) ⇒ Object
- #handle_headers_h4(node, coradoc, state) ⇒ Object
- #name ⇒ Object
- #postprocess_asciidoc_string ⇒ Object
- #preprocess_html_tree ⇒ Object
Methods inherited from Coradoc::ReverseAdoc::Plugin
#html_tree_add_hook_post, #html_tree_add_hook_post_by_css, #html_tree_add_hook_pre, #html_tree_add_hook_pre_by_css, #html_tree_change_properties_by_css, #html_tree_change_tag_name_by_css, #html_tree_preview, #html_tree_process_to_adoc, #html_tree_process_to_coradoc, #html_tree_remove_by_css, #html_tree_replace_with_children_by_css, #html_tree_run_hooks, #initialize, new
Constructor Details
This class inherits a constructor from Coradoc::ReverseAdoc::Plugin
Instance Method Details
#handle_headers(node, coradoc, state) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/coradoc/reverse_adoc/plugins/plateau.rb', line 109 def handle_headers(node, coradoc, state) if coradoc.id.start_with?("toc0_") content = coradoc.content.map(&:content).join # Special content case content.strip when "はじめに" # Introduction coradoc.style = "abstract" # The older version document has ".preface" when "改定の概要" # Revision overview coradoc.style = "abstract" # The older version document has ".preface" when "参考文献" # Bibliography coradoc.style = "bibliography" when "改訂履歴" # Document history coradoc.style = "appendix" else warn "Unknown section #{coradoc.content.map(&:content).join.inspect}" end # Ensure they are generated as level 1 coradoc.level_int = 1 end # Remove numbers coradoc.content.first.content.sub!(/\A[\d\s.]+/, "") coradoc end |
#handle_headers_h4(node, coradoc, state) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/coradoc/reverse_adoc/plugins/plateau.rb', line 136 def handle_headers_h4(node, coradoc, state) case coradoc.content.first.content when /\A\(\d+\)(.*)/ coradoc.level_int = 4 coradoc.content.first.content = $1.strip coradoc when /\A\d+\)(.*)/ coradoc.level_int = 5 coradoc.content.first.content = $1.strip coradoc else ["// FIXME\n", coradoc] end end |
#name ⇒ Object
10 11 12 |
# File 'lib/coradoc/reverse_adoc/plugins/plateau.rb', line 10 def name "PLATEAU" end |
#postprocess_asciidoc_string ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/coradoc/reverse_adoc/plugins/plateau.rb', line 151 def postprocess_asciidoc_string str = self.asciidoc_string ### Custom indentation handling # If there's a step up, add [none] str = str.gsub(%r{\s+//-ENDPT2D\s+//-PT3D\s+}, "\n[none]\n") str = str.gsub(%r{\s+//-ENDPT2D\s+//-PT4D\s+}, "\n[none]\n") str = str.gsub(%r{\s+//-ENDPT3D\s+//-PT4D\s+}, "\n[none]\n") # Collapse blocks of text[2,3]data str = str.gsub(%r{\s+//-ENDPT[234]D\s+//-PT[234]D\s+}, "\n\n") # In the beginning, add [none] str = str.gsub(%r{\s+//-PT[234]D\s+}, "\n\n[none]\n") # If following with another list, ensure we readd styling str = str.gsub(%r{\s+//-ENDPT[234]D\s+\*}, "\n\n[disc]\n*") # Otherwise, clean up str = str.gsub(%r{\s+//-ENDPT[234]D\s+}, "\n\n") self.asciidoc_string = str end |
#preprocess_html_tree ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/coradoc/reverse_adoc/plugins/plateau.rb', line 14 def preprocess_html_tree # Let's simplify the tree by removing what's extraneous # html_tree_remove_by_css("script, style, img.container_imagebox:not([src])") # html_tree_replace_with_children_by_css("div.container_box") # html_tree_replace_with_children_by_css("div.col.col-12") # html_tree_replace_with_children_by_css(".tabledatatext, .tabledatatextY") # html_tree_replace_with_children_by_css("div.row") # # We can remove that, but it messes up the images and paragraphs. # Remove side menu, so we can generate TOC ourselves html_tree_remove_by_css(".sideMenu") # Correct non-semantic classes into semantic HTML tags html_tree_change_tag_name_by_css(".titledata", "h1") html_tree_change_tag_name_by_css(".subtitledata", "h2") html_tree_change_tag_name_by_css(".pitemdata", "h3") html_tree_change_tag_name_by_css(".sitemdata", "h4") html_tree_change_tag_name_by_css('td[bgcolor="#D0CECE"]', "th") # Remove some CSS ids that are not important to us html_tree_change_properties_by_css("#__nuxt", id: nil) html_tree_change_properties_by_css("#__layout", id: nil) html_tree_change_properties_by_css("#app", id: nil) # Convert table/img caption to become a caption html_tree.css(".imagedata").each do |e| table = e.parent.next&.children&.first if table&.name == "table" e.name = "caption" table.prepend_child(e) next end img = e.parent.previous&.children&.first if img&.name == "img" && img["src"] title = e.text.strip img["title"] = title e.remove next end end # Add hooks for H1, H2, H3, H4 html_tree_add_hook_post_by_css("h1, h2, h3", &method(:handle_headers)) html_tree_add_hook_post_by_css("h4", &method(:handle_headers_h4)) # Table cells aligned to center html_tree_change_properties_by_css(".tableTopCenter", align: "center") # Handle non-semantic lists and indentation html_tree_add_hook_pre_by_css ".text2data" do |node,| text = html_tree_process_to_adoc(node).strip next "" if text.empty? || text == "\u3000" if text.start_with?(/\d+\./) text = text.sub(/\A\d+.\s*/, "") ".. #{text}\n" else text = text.gsub(/^/, "** ") "\n\n//-PT2D\n#{text}\n//-ENDPT2D\n\n" end end html_tree_add_hook_pre_by_css ".text3data" do |node,| text = html_tree_process_to_adoc(node).strip next "" if text.empty? || text == "\u3000" text = text.strip.gsub(/^/, "*** ") "\n\n//-PT3D\n#{text}\n//-ENDPT3D\n\n" end html_tree_add_hook_pre_by_css ".text4data" do |node,| text = html_tree_process_to_adoc(node).strip next "" if text.empty? || text == "\u3000" text = text.strip.gsub(/^/, "**** ") "\n\n//-PT4D\n#{text}\n//-ENDPT4D\n\n" end html_tree_add_hook_pre_by_css ".text2data_point ul" do |node,| text = html_tree_process_to_adoc(node.children.first.children).strip "** #{text}\n" end html_tree_add_hook_pre_by_css ".text3data_point ul" do |node,| text = html_tree_process_to_adoc(node.children.first.children).strip "*** #{text}\n" end # html_tree_preview end |