Module: Asciidoctor::Standoc::Section
- Included in:
- Converter
- Defined in:
- lib/asciidoctor/standoc/section.rb
Constant Summary collapse
- SYMBOLS_TITLES =
["symbols and abbreviated terms", "symbols", "abbreviated terms"].freeze
Instance Method Summary collapse
- #abstract_parse(attrs, xml, node) ⇒ Object
- #acknowledgements_parse(attrs, xml, node) ⇒ Object
- #annex_parse(attrs, xml, node) ⇒ Object
- #bibliography_parse(attrs, xml, node) ⇒ Object
- #clause_parse(attrs, xml, node) ⇒ Object
- #foreword_parse(attrs, xml, node) ⇒ Object
- #in_biblio? ⇒ Boolean
- #in_norm_ref? ⇒ Boolean
- #in_terms? ⇒ Boolean
- #introduction_parse(attrs, xml, node) ⇒ Object
- #nonterm_symbols_parse(attrs, xml, node) ⇒ Object
- #nonterm_term_def_subclause_parse(attrs, xml, node) ⇒ Object
- #norm_ref_parse(attrs, xml, node) ⇒ Object
- #preamble(node) ⇒ Object
- #section(node) ⇒ Object
- #section_attributes(node) ⇒ Object
- #sectiontype(node, level = true) ⇒ Object
- #sectiontype_streamline(ret) ⇒ Object
- #set_obligation(attrs, node) ⇒ Object
- #symbols_parse(attr, xml, node) ⇒ Object
- #term_def_parse(attrs, xml, node, toplevel) ⇒ Object
-
#term_def_subclause_parse(attrs, xml, node) ⇒ Object
subclause contains subclauses.
- #term_def_subclause_parse1(attrs, xml, node) ⇒ Object
- #term_def_title(toplevel, node) ⇒ Object
Instance Method Details
#abstract_parse(attrs, xml, node) ⇒ Object
112 113 114 115 116 |
# File 'lib/asciidoctor/standoc/section.rb', line 112 def abstract_parse(attrs, xml, node) xml.abstract **attr_code(attrs) do |xml_section| xml_section << node.content end end |
#acknowledgements_parse(attrs, xml, node) ⇒ Object
250 251 252 253 254 255 256 |
# File 'lib/asciidoctor/standoc/section.rb', line 250 def acknowledgements_parse(attrs, xml, node) xml.acknowledgements **attr_code(attrs) do |xml_section| xml_section.title { |t| t << node.title || "Acknowledgements" } content = node.content xml_section << content end end |
#annex_parse(attrs, xml, node) ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/asciidoctor/standoc/section.rb', line 130 def annex_parse(attrs, xml, node) attrs["inline-header".to_sym] = node.option? "inline-header" set_obligation(attrs, node) xml.annex **attr_code(attrs) do |xml_section| xml_section.title { |name| name << node.title } xml_section << node.content end end |
#bibliography_parse(attrs, xml, node) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/asciidoctor/standoc/section.rb', line 139 def bibliography_parse(attrs, xml, node) node.attr("style") == "bibliography" or #warn "Section not marked up as [bibliography]!" @log.add("Asciidoctor Input", node, "Section not marked up as [bibliography]!") @biblio = true xml.references **attr_code(attrs) do |xml_section| title = node.level == 1 ? "Bibliography" : node.title xml_section.title { |t| t << title } xml_section << node.content end @biblio = false end |
#clause_parse(attrs, xml, node) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/asciidoctor/standoc/section.rb', line 118 def clause_parse(attrs, xml, node) attrs["inline-header".to_sym] = node.option? "inline-header" attrs[:bibitem] = true if node.option? "bibitem" attrs[:preface] = true if node.role == "preface" || node.attr("style") == "preface" attrs[:level] = node.attr("level") set_obligation(attrs, node) xml.send "clause", **attr_code(attrs) do |xml_section| xml_section.title { |n| n << node.title } unless node.title.nil? xml_section << node.content end end |
#foreword_parse(attrs, xml, node) ⇒ Object
242 243 244 245 246 247 248 |
# File 'lib/asciidoctor/standoc/section.rb', line 242 def foreword_parse(attrs, xml, node) xml.foreword **attr_code(attrs) do |xml_section| xml_section.title { |t| t << node.title } content = node.content xml_section << content end end |
#in_biblio? ⇒ Boolean
11 12 13 |
# File 'lib/asciidoctor/standoc/section.rb', line 11 def in_biblio? @biblio end |
#in_norm_ref? ⇒ Boolean
19 20 21 |
# File 'lib/asciidoctor/standoc/section.rb', line 19 def in_norm_ref? @norm_ref end |
#in_terms? ⇒ Boolean
15 16 17 |
# File 'lib/asciidoctor/standoc/section.rb', line 15 def in_terms? @term_def end |
#introduction_parse(attrs, xml, node) ⇒ Object
234 235 236 237 238 239 240 |
# File 'lib/asciidoctor/standoc/section.rb', line 234 def introduction_parse(attrs, xml, node) xml.introduction **attr_code(attrs) do |xml_section| xml_section.title { |t| t << "Introduction" } content = node.content xml_section << content end end |
#nonterm_symbols_parse(attrs, xml, node) ⇒ Object
152 153 154 155 156 |
# File 'lib/asciidoctor/standoc/section.rb', line 152 def nonterm_symbols_parse(attrs, xml, node) @definitions = false clause_parse(attrs, xml, node) @definitions = true end |
#nonterm_term_def_subclause_parse(attrs, xml, node) ⇒ Object
175 176 177 178 179 |
# File 'lib/asciidoctor/standoc/section.rb', line 175 def nonterm_term_def_subclause_parse(attrs, xml, node) @term_def = false clause_parse(attrs, xml, node) @term_def = true end |
#norm_ref_parse(attrs, xml, node) ⇒ Object
225 226 227 228 229 230 231 232 |
# File 'lib/asciidoctor/standoc/section.rb', line 225 def norm_ref_parse(attrs, xml, node) @norm_ref = true xml.references **attr_code(attrs) do |xml_section| xml_section.title { |t| t << "Normative References" } xml_section << node.content end @norm_ref = false end |
#preamble(node) ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/asciidoctor/standoc/section.rb', line 102 def preamble(node) noko do |xml| xml.foreword **attr_code(section_attributes(node)) do |xml_abstract| xml_abstract.title { |t| t << (node.blocks[0].title || "Foreword") } content = node.content xml_abstract << content end end.join("\n") end |
#section(node) ⇒ Object
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 |
# File 'lib/asciidoctor/standoc/section.rb', line 59 def section(node) a = section_attributes(node) noko do |xml| case sectiontype(node) when "introduction" then introduction_parse(a, xml, node) when "foreword" then foreword_parse(a, xml, node) when "normative references" then norm_ref_parse(a, xml, node) when "terms and definitions" @term_def = true term_def_parse(a, xml, node, true) @term_def = false when "symbols and abbreviated terms" symbols_parse(a, xml, node) when "acknowledgements" acknowledgements_parse(a, xml, node) when "bibliography" then bibliography_parse(a, xml, node) else if @term_def then term_def_subclause_parse(a, xml, node) elsif @definitions then symbols_parse(a, xml, node) elsif @biblio then bibliography_parse(a, xml, node) elsif node.attr("style") == "bibliography" bibliography_parse(a, xml, node) elsif node.attr("style") == "abstract" abstract_parse(a, xml, node) elsif node.attr("style") == "appendix" && node.level == 1 annex_parse(a, xml, node) else clause_parse(a, xml, node) end end end.join("\n") end |
#section_attributes(node) ⇒ Object
53 54 55 56 57 |
# File 'lib/asciidoctor/standoc/section.rb', line 53 def section_attributes(node) { id: Utils::anchor_or_uuid(node), language: node.attributes["language"], script: node.attributes["script"] } end |
#sectiontype(node, level = true) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/asciidoctor/standoc/section.rb', line 23 def sectiontype(node, level = true) ret = node&.attr("heading")&.downcase || node.title.gsub(/<[^>]+>/, "").downcase ret1 = sectiontype_streamline(ret) return ret1 if "symbols and abbreviated terms" == ret1 return nil unless !level || node.level == 1 return nil if @seen_headers.include? ret @seen_headers << ret ret1 end |
#sectiontype_streamline(ret) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/asciidoctor/standoc/section.rb', line 34 def sectiontype_streamline(ret) case ret when "terms and definitions", "terms, definitions, symbols and abbreviated terms", "terms, definitions, symbols and abbreviations", "terms, definitions and symbols", "terms, definitions and abbreviations", "terms, definitions and abbreviated terms" "terms and definitions" when "symbols and abbreviated terms", "symbols", "abbreviated terms", "abbreviations" "symbols and abbreviated terms" else ret end end |
#set_obligation(attrs, node) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/asciidoctor/standoc/section.rb', line 92 def set_obligation(attrs, node) attrs[:obligation] = if node.attributes.has_key?("obligation") node.attr("obligation") elsif node.parent.attributes.has_key?("obligation") node.parent.attr("obligation") else "normative" end end |
#symbols_parse(attr, xml, node) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/asciidoctor/standoc/section.rb', line 158 def symbols_parse(attr, xml, node) node.role == "nonterm" and return nonterm_symbols_parse(attr, xml, node) xml.definitions **attr_code(attr) do |xml_section| xml_section.title { |t| t << node.title } defs = @definitions termdefs = @term_def @definitions = true @term_def = false xml_section << node.content @definitions = defs @term_def = termdefs end end |
#term_def_parse(attrs, xml, node, toplevel) ⇒ Object
215 216 217 218 219 220 221 222 223 |
# File 'lib/asciidoctor/standoc/section.rb', line 215 def term_def_parse(attrs, xml, node, toplevel) xml.terms **attr_code(attrs) do |section| section.title { |t| t << term_def_title(toplevel, node) } (s = node.attr("source")) && s.split(/,/).each do |s1| section.termdocsource(nil, **attr_code(bibitemid: s1)) end section << node.content end end |
#term_def_subclause_parse(attrs, xml, node) ⇒ Object
subclause contains subclauses
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/asciidoctor/standoc/section.rb', line 182 def term_def_subclause_parse(attrs, xml, node) node.role == "nonterm" || sectiontype(node, false) == "terms and definitions" and return nonterm_term_def_subclause_parse(attrs, xml, node) return symbols_parse(attrs, xml, node) if @definitions sub = node.find_by(context: :section) { |s| s.level == node.level + 1 } sub.empty? || (return term_def_parse(attrs, xml, node, false)) sectiontype(node, false) == "symbols and abbreviated terms" and (return symbols_parse(attrs, xml, node)) term_def_subclause_parse1(attrs, xml, node) end |
#term_def_subclause_parse1(attrs, xml, node) ⇒ Object
194 195 196 197 198 199 |
# File 'lib/asciidoctor/standoc/section.rb', line 194 def term_def_subclause_parse1(attrs, xml, node) xml.term **attr_code(attrs) do |xml_section| xml_section.preferred { |name| name << node.title } xml_section << node.content end end |
#term_def_title(toplevel, node) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/asciidoctor/standoc/section.rb', line 201 def term_def_title(toplevel, node) return node.title unless toplevel sub = node.find_by(context: :section) do |s| SYMBOLS_TITLES.include? s.title.downcase end return "Terms and definitions" if sub.empty? sym = /symbol/i.match(node.title) abbrev = /abbreviat/i.match(node.title) sym && abbrev and return "Terms, definitions, symbols and abbreviated terms" sym and return "Terms, definitions and symbols" abbrev and return "Terms, definitions and abbreviated terms" "Terms, definitions, symbols and abbreviated terms" end |