metanorma-standoc 1.4.4 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +4 -9
  3. data/.github/workflows/ubuntu.yml +1 -5
  4. data/.github/workflows/windows.yml +2 -12
  5. data/.rubocop.yml +1 -1
  6. data/lib/asciidoctor/standoc/base.rb +11 -5
  7. data/lib/asciidoctor/standoc/base_structured_text_preprocessor.rb +123 -0
  8. data/lib/asciidoctor/standoc/basicdoc.rng +23 -0
  9. data/lib/asciidoctor/standoc/cleanup.rb +32 -12
  10. data/lib/asciidoctor/standoc/cleanup_amend.rb +54 -0
  11. data/lib/asciidoctor/standoc/cleanup_block.rb +0 -2
  12. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +11 -24
  13. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +0 -3
  14. data/lib/asciidoctor/standoc/cleanup_inline.rb +62 -1
  15. data/lib/asciidoctor/standoc/cleanup_ref.rb +10 -7
  16. data/lib/asciidoctor/standoc/cleanup_section.rb +91 -8
  17. data/lib/asciidoctor/standoc/cleanup_terms.rb +12 -2
  18. data/lib/asciidoctor/standoc/converter.rb +3 -3
  19. data/lib/asciidoctor/standoc/front.rb +0 -12
  20. data/lib/asciidoctor/standoc/front_contributor.rb +51 -10
  21. data/lib/asciidoctor/standoc/inline.rb +21 -31
  22. data/lib/asciidoctor/standoc/isodoc.rng +137 -21
  23. data/lib/asciidoctor/standoc/json2_text_preprocessor.rb +44 -0
  24. data/lib/asciidoctor/standoc/log.rb +10 -1
  25. data/lib/asciidoctor/standoc/macros.rb +45 -33
  26. data/lib/asciidoctor/standoc/ref.rb +45 -45
  27. data/lib/asciidoctor/standoc/section.rb +39 -30
  28. data/lib/asciidoctor/standoc/table.rb +3 -2
  29. data/lib/asciidoctor/standoc/utils.rb +18 -1
  30. data/lib/asciidoctor/standoc/validate.rb +30 -18
  31. data/lib/asciidoctor/standoc/validate_section.rb +1 -1
  32. data/lib/asciidoctor/standoc/views/datamodel/model_representation.adoc.erb +10 -10
  33. data/lib/asciidoctor/standoc/yaml2_text_preprocessor.rb +46 -0
  34. data/lib/liquid/custom_blocks/key_iterator.rb +21 -0
  35. data/lib/liquid/custom_filters/values.rb +7 -0
  36. data/lib/metanorma/standoc.rb +0 -5
  37. data/lib/metanorma/standoc/version.rb +20 -1
  38. data/metanorma-standoc.gemspec +4 -5
  39. data/spec/asciidoctor-standoc/base_spec.rb +140 -7
  40. data/spec/asciidoctor-standoc/blocks_spec.rb +275 -149
  41. data/spec/asciidoctor-standoc/cleanup_spec.rb +1372 -56
  42. data/spec/asciidoctor-standoc/inline_spec.rb +133 -6
  43. data/spec/asciidoctor-standoc/isobib_cache_spec.rb +9 -7
  44. data/spec/asciidoctor-standoc/macros_json2text_spec.rb +10 -0
  45. data/spec/asciidoctor-standoc/macros_spec.rb +43 -23
  46. data/spec/asciidoctor-standoc/macros_yaml2text_spec.rb +5 -560
  47. data/spec/asciidoctor-standoc/refs_dl_spec.rb +9 -7
  48. data/spec/asciidoctor-standoc/refs_spec.rb +43 -34
  49. data/spec/asciidoctor-standoc/section_spec.rb +42 -39
  50. data/spec/asciidoctor-standoc/table_spec.rb +119 -113
  51. data/spec/asciidoctor-standoc/validate_spec.rb +45 -1
  52. data/spec/assets/i18n.yaml +17 -2
  53. data/spec/examples/codes_table.html +1365 -1365
  54. data/spec/fixtures/macros_datamodel/address_class_profile.xml +46 -46
  55. data/spec/fixtures/macros_datamodel/address_component_profile.xml +21 -21
  56. data/spec/fixtures/macros_datamodel/blank_definition_profile.xml +21 -21
  57. data/spec/metanorma/processor_spec.rb +1 -2
  58. data/spec/spec_helper.rb +110 -109
  59. data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +629 -0
  60. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +71 -71
  61. data/spec/vcr_cassettes/isobib_get_123.yml +16 -16
  62. data/spec/vcr_cassettes/isobib_get_123_1.yml +36 -36
  63. data/spec/vcr_cassettes/isobib_get_123_2001.yml +16 -16
  64. data/spec/vcr_cassettes/isobib_get_124.yml +17 -17
  65. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
  66. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +39 -37
  67. metadata +29 -14
  68. data/lib/asciidoctor-yaml/i18n-en.yaml +0 -20
  69. data/lib/asciidoctor-yaml/i18n-fr.yaml +0 -13
  70. data/lib/asciidoctor-yaml/i18n-zh-Hans.yaml +0 -15
  71. data/lib/asciidoctor/standoc/i18n.rb +0 -39
  72. data/lib/asciidoctor/standoc/macros_yaml2text.rb +0 -165
  73. data/lib/metanorma/standoc/latexml_requirement.rb +0 -62
  74. data/lib/metanorma/standoc/requirement.rb +0 -13
@@ -3,7 +3,8 @@ require "htmlentities"
3
3
  require "unicode2latex"
4
4
  require "mime/types"
5
5
  require "base64"
6
- require 'English'
6
+ require "English"
7
+ require "latexmath"
7
8
 
8
9
  module Asciidoctor
9
10
  module Standoc
@@ -32,18 +33,28 @@ module Asciidoctor
32
33
  end
33
34
 
34
35
  def inline_anchor_xref(node)
35
- m = /^(?<case>capital%|lowercase%)?(?<fn>fn(:\s*(?<text>.*))?)?$/.match node.text
36
- casing = m.nil? ? nil : m[:case]&.sub(/%$/, "")
37
- f = (m.nil? || m[:fn].nil?) ? "inline" : "footnote"
38
- c = (!m.nil? && (!m[:fn].nil? || !m[:case].nil?)) ? m[:text] : node.text
39
- t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2")
40
36
  noko do |xml|
41
- xml.xref **attr_code(target: t, type: f, case: casing) do |x|
37
+ attrs = inline_anchor_xref_attrs(node)
38
+ c = attrs[:text]
39
+ attrs.delete(:text) unless c.nil?
40
+ xml.xref **attr_code(attrs) do |x|
42
41
  x << c
43
42
  end
44
43
  end.join
45
44
  end
46
45
 
46
+ def inline_anchor_xref_attrs(node)
47
+ m = /^(?<drop>droploc%)?(?<case>capital%|lowercase%)?(?<drop2>droploc%)?
48
+ (?<fn>fn(:\s*(?<text>.*))?)?$/x.match node.text
49
+ casing = m.nil? ? nil : m[:case]&.sub(/%$/, "")
50
+ droploc = m.nil? ? nil : ((m[:drop].nil? && m[:drop2].nil?) ? nil: true)
51
+ f = (m.nil? || m[:fn].nil?) ? "inline" : "footnote"
52
+ c = (!m.nil? && (%i[case fn drop drop2].any? { |x| !m[x].nil? })) ?
53
+ m[:text] : node.text
54
+ t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2")
55
+ { target: t, type: f, case: casing, droploc: droploc, text: c }
56
+ end
57
+
47
58
  def inline_anchor_link(node)
48
59
  contents = node.text
49
60
  contents = "" if node.target.gsub(%r{^mailto:}, "") == node.text
@@ -105,33 +116,12 @@ module Asciidoctor
105
116
  HTMLEntities.new.encode(text, :basic, :hexadecimal).
106
117
  gsub(/&amp;gt;/, ">").gsub(/\&amp;lt;/, "<").gsub(/&amp;amp;/, "&").
107
118
  gsub(/&gt;/, ">").gsub(/&lt;/, "<").gsub(/&amp;/, "&").
108
- gsub(/&quot;/, '"').gsub(/&#xa;/, "\n")
109
- end
110
-
111
- def latex_run1(lxm_input, cmd)
112
- IO.popen(cmd, "r+", external_encoding: "UTF-8") do |io|
113
- io.write(lxm_input)
114
- io.close_write
115
- io.read
116
- end
117
- end
118
-
119
- def latex_run(lxm_input)
120
- results = nil
121
- Metanorma::Standoc::Requirements[:latexml].cmd.each_with_index do |cmd, i|
122
- warn "Retrying with #{cmd}" if i > 0
123
- results = latex_run1(lxm_input, cmd)
124
- if $CHILD_STATUS.to_i.zero?
125
- warn "Success!" if i > 0
126
- break
127
- end
128
- end
129
- $CHILD_STATUS.to_i.zero? ? results : nil
119
+ gsub(/&quot;/, '"').gsub(/&#xa;/, "\n").gsub(/&amp;#/, "&#")
130
120
  end
131
121
 
132
122
  def latex_parse(text)
133
123
  lxm_input = Unicode2LaTeX.unicode2latex(HTMLEntities.new.decode(text))
134
- results = latex_run(lxm_input)
124
+ results = Latexmath.parse(lxm_input).to_mathml
135
125
  results.nil? and
136
126
  @log.add('Math', nil,
137
127
  "latexmlmath failed to process equation:\n#{lxm_input}")
@@ -151,7 +141,7 @@ module Asciidoctor
151
141
  s.parent.children = math
152
142
  end
153
143
  else
154
- xml.stem text, **{ type: "AsciiMath" }
144
+ xml.stem text&.gsub(/\&amp;#/, "&#"), **{ type: "AsciiMath" }
155
145
  end
156
146
  end
157
147
 
@@ -42,8 +42,11 @@
42
42
  </define>
43
43
  <define name="xref">
44
44
  <element name="xref">
45
+ <!-- attribute target { xsd:IDREF }, -->
45
46
  <attribute name="target">
46
- <data type="IDREF"/>
47
+ <data type="string">
48
+ <param name="pattern">\i\c*|\c+#\c+</param>
49
+ </data>
47
50
  </attribute>
48
51
  <optional>
49
52
  <attribute name="type">
@@ -61,6 +64,11 @@
61
64
  </choice>
62
65
  </attribute>
63
66
  </optional>
67
+ <optional>
68
+ <attribute name="droploc">
69
+ <data type="boolean"/>
70
+ </attribute>
71
+ </optional>
64
72
  <text/>
65
73
  </element>
66
74
  </define>
@@ -578,6 +586,8 @@
578
586
  <ref name="ol"/>
579
587
  <ref name="dl"/>
580
588
  <ref name="formula"/>
589
+ <ref name="quote"/>
590
+ <ref name="sourcecode"/>
581
591
  </choice>
582
592
  </oneOrMore>
583
593
  </element>
@@ -661,6 +671,16 @@
661
671
  </choice>
662
672
  </attribute>
663
673
  </optional>
674
+ <optional>
675
+ <attribute name="valign">
676
+ <choice>
677
+ <value>top</value>
678
+ <value>middle</value>
679
+ <value>bottom</value>
680
+ <value>baseline</value>
681
+ </choice>
682
+ </attribute>
683
+ </optional>
664
684
  <choice>
665
685
  <zeroOrMore>
666
686
  <choice>
@@ -697,6 +717,16 @@
697
717
  </choice>
698
718
  </attribute>
699
719
  </optional>
720
+ <optional>
721
+ <attribute name="valign">
722
+ <choice>
723
+ <value>top</value>
724
+ <value>middle</value>
725
+ <value>bottom</value>
726
+ <value>baseline</value>
727
+ </choice>
728
+ </attribute>
729
+ </optional>
700
730
  <choice>
701
731
  <zeroOrMore>
702
732
  <choice>
@@ -834,6 +864,13 @@
834
864
  </define>
835
865
  <define name="standard-document">
836
866
  <element name="standard-document">
867
+ <attribute name="version"/>
868
+ <attribute name="type">
869
+ <choice>
870
+ <value>semantic</value>
871
+ <value>presentation</value>
872
+ </choice>
873
+ </attribute>
837
874
  <ref name="bibdata"/>
838
875
  <optional>
839
876
  <ref name="boilerplate"/>
@@ -855,7 +892,7 @@
855
892
  <oneOrMore>
856
893
  <choice>
857
894
  <ref name="content"/>
858
- <ref name="preface_abstract"/>
895
+ <ref name="abstract"/>
859
896
  <ref name="foreword"/>
860
897
  <ref name="introduction"/>
861
898
  <ref name="acknowledgements"/>
@@ -922,6 +959,9 @@
922
959
  <optional>
923
960
  <attribute name="script"/>
924
961
  </optional>
962
+ <optional>
963
+ <attribute name="type"/>
964
+ </optional>
925
965
  <optional>
926
966
  <attribute name="obligation">
927
967
  <choice>
@@ -961,9 +1001,6 @@
961
1001
  </define>
962
1002
  <define name="content-subsection">
963
1003
  <element name="clause">
964
- <optional>
965
- <attribute name="type"/>
966
- </optional>
967
1004
  <ref name="Content-Section"/>
968
1005
  </element>
969
1006
  </define>
@@ -992,6 +1029,9 @@
992
1029
  </choice>
993
1030
  </attribute>
994
1031
  </optional>
1032
+ <optional>
1033
+ <attribute name="type"/>
1034
+ </optional>
995
1035
  <optional>
996
1036
  <ref name="section-title"/>
997
1037
  </optional>
@@ -1011,9 +1051,6 @@
1011
1051
  </define>
1012
1052
  <define name="clause">
1013
1053
  <element name="clause">
1014
- <optional>
1015
- <attribute name="type"/>
1016
- </optional>
1017
1054
  <ref name="Clause-Section"/>
1018
1055
  </element>
1019
1056
  </define>
@@ -1042,18 +1079,24 @@
1042
1079
  </choice>
1043
1080
  </attribute>
1044
1081
  </optional>
1082
+ <optional>
1083
+ <attribute name="type"/>
1084
+ </optional>
1045
1085
  <optional>
1046
1086
  <ref name="section-title"/>
1047
1087
  </optional>
1048
1088
  <group>
1049
- <group>
1050
- <zeroOrMore>
1051
- <ref name="BasicBlock"/>
1052
- </zeroOrMore>
1053
- <zeroOrMore>
1054
- <ref name="note"/>
1055
- </zeroOrMore>
1056
- </group>
1089
+ <choice>
1090
+ <group>
1091
+ <zeroOrMore>
1092
+ <ref name="BasicBlock"/>
1093
+ </zeroOrMore>
1094
+ <zeroOrMore>
1095
+ <ref name="note"/>
1096
+ </zeroOrMore>
1097
+ </group>
1098
+ <ref name="amend"/>
1099
+ </choice>
1057
1100
  <zeroOrMore>
1058
1101
  <choice>
1059
1102
  <ref name="clause-subsection"/>
@@ -1180,6 +1223,9 @@
1180
1223
  <optional>
1181
1224
  <attribute name="script"/>
1182
1225
  </optional>
1226
+ <optional>
1227
+ <attribute name="type"/>
1228
+ </optional>
1183
1229
  <optional>
1184
1230
  <attribute name="obligation">
1185
1231
  <choice>
@@ -1447,11 +1493,6 @@
1447
1493
  </optional>
1448
1494
  </element>
1449
1495
  </define>
1450
- <define name="preface_abstract">
1451
- <element name="abstract">
1452
- <ref name="Basic-Section"/>
1453
- </element>
1454
- </define>
1455
1496
  <define name="term-clause">
1456
1497
  <element name="clause">
1457
1498
  <optional>
@@ -1501,4 +1542,79 @@
1501
1542
  <ref name="CitationType"/>
1502
1543
  </element>
1503
1544
  </define>
1545
+ <define name="amend">
1546
+ <element name="amend">
1547
+ <optional>
1548
+ <attribute name="id">
1549
+ <data type="ID"/>
1550
+ </attribute>
1551
+ </optional>
1552
+ <attribute name="change">
1553
+ <choice>
1554
+ <value>add</value>
1555
+ <value>modify</value>
1556
+ <value>delete</value>
1557
+ </choice>
1558
+ </attribute>
1559
+ <optional>
1560
+ <attribute name="path"/>
1561
+ </optional>
1562
+ <optional>
1563
+ <attribute name="path_end"/>
1564
+ </optional>
1565
+ <optional>
1566
+ <attribute name="title"/>
1567
+ </optional>
1568
+ <optional>
1569
+ <element name="location">
1570
+ <zeroOrMore>
1571
+ <ref name="locality"/>
1572
+ </zeroOrMore>
1573
+ </element>
1574
+ </optional>
1575
+ <zeroOrMore>
1576
+ <ref name="autonumber"/>
1577
+ </zeroOrMore>
1578
+ <optional>
1579
+ <element name="description">
1580
+ <zeroOrMore>
1581
+ <ref name="BasicBlock"/>
1582
+ </zeroOrMore>
1583
+ </element>
1584
+ </optional>
1585
+ <optional>
1586
+ <element name="newcontent">
1587
+ <zeroOrMore>
1588
+ <ref name="BasicBlock"/>
1589
+ </zeroOrMore>
1590
+ </element>
1591
+ </optional>
1592
+ <optional>
1593
+ <element name="description">
1594
+ <zeroOrMore>
1595
+ <ref name="BasicBlock"/>
1596
+ </zeroOrMore>
1597
+ </element>
1598
+ </optional>
1599
+ </element>
1600
+ </define>
1601
+ <define name="autonumber">
1602
+ <element name="autonumber">
1603
+ <attribute name="type">
1604
+ <choice>
1605
+ <value>requirement</value>
1606
+ <value>recommendation</value>
1607
+ <value>permission</value>
1608
+ <value>table</value>
1609
+ <value>figure</value>
1610
+ <value>admonition</value>
1611
+ <value>formula</value>
1612
+ <value>sourcecode</value>
1613
+ <value>example</value>
1614
+ <value>note</value>
1615
+ </choice>
1616
+ </attribute>
1617
+ <text/>
1618
+ </element>
1619
+ </define>
1504
1620
  </grammar>
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "asciidoctor/standoc/base_structured_text_preprocessor"
4
+
5
+ module Asciidoctor
6
+ module Standoc
7
+ class Json2TextPreprocessor < BaseStructuredTextPreprocessor
8
+ # search document for block `yaml2text`
9
+ # after that take template from block and read file into this template
10
+ # example:
11
+ # [yaml2text,foobar.yaml]
12
+ # ----
13
+ # === {item.name}
14
+ # {item.desc}
15
+ #
16
+ # {item.symbol}:: {item.symbol_def}
17
+ # ----
18
+ #
19
+ # with content of `foobar.yaml` file equal to:
20
+ # - name: spaghetti
21
+ # desc: wheat noodles of 9mm diameter
22
+ # symbol: SPAG
23
+ # symbol_def: the situation is message like spaghetti at a kid's
24
+ #
25
+ # will produce:
26
+ # === spaghetti
27
+ # wheat noodles of 9mm diameter
28
+ #
29
+ # SPAG:: the situation is message like spaghetti at a kid's meal
30
+
31
+ def initialize(config = {})
32
+ super
33
+ @config[:block_name] = "json2text"
34
+ end
35
+
36
+ protected
37
+
38
+ def content_from_file(document, file_path)
39
+ JSON.parse(File.read(relative_file_path(document, file_path),
40
+ encoding: "UTF-8"))
41
+ end
42
+ end
43
+ end
44
+ end
@@ -8,7 +8,8 @@ module Asciidoctor
8
8
  def add(category, loc, msg)
9
9
  return if @novalid
10
10
  @log[category] = [] unless @log[category]
11
- @log[category] << { location: current_location(loc), message: msg }
11
+ @log[category] << { location: current_location(loc), message: msg,
12
+ context: context(loc) }
12
13
  loc = loc.nil? ? "" : "(#{current_location(loc)}): "
13
14
  warn "#{category}: #{loc}#{msg}"
14
15
  end
@@ -31,6 +32,13 @@ module Asciidoctor
31
32
  "??"
32
33
  end
33
34
 
35
+ def context(n)
36
+ return nil if n.is_a? String
37
+ n.respond_to?(:to_xml) and return n.to_xml
38
+ n.respond_to?(:to_s) and return n.to_s
39
+ nil
40
+ end
41
+
34
42
  def write(file)
35
43
  File.open(file, "w:UTF-8") do |f|
36
44
  f.puts "#{file} errors"
@@ -41,6 +49,7 @@ module Asciidoctor
41
49
  end.each do |n|
42
50
  loc = n[:location] ? "(#{n[:location]}): " : ""
43
51
  f.puts "#{loc}#{n[:message]}"
52
+ n[:context]&.split(/\n/)&.first(5)&.each { |l| f.puts "\t#{l}" }
44
53
  end
45
54
  end
46
55
  end
@@ -1,11 +1,12 @@
1
1
  require "asciidoctor/extensions"
2
2
  require "fileutils"
3
3
  require "uuidtools"
4
- require 'yaml'
5
- require_relative './macros_plantuml.rb'
6
- require_relative './datamodel/attributes_table_preprocessor.rb'
7
- require_relative './datamodel/diagram_preprocessor.rb'
8
- require_relative './macros_yaml2text.rb'
4
+ require "yaml"
5
+ require_relative "./macros_plantuml.rb"
6
+ require_relative "./datamodel/attributes_table_preprocessor.rb"
7
+ require_relative "./datamodel/diagram_preprocessor.rb"
8
+ require_relative "./yaml2_text_preprocessor.rb"
9
+ require_relative "./json2_text_preprocessor.rb"
9
10
 
10
11
  module Asciidoctor
11
12
  module Standoc
@@ -61,17 +62,17 @@ module Asciidoctor
61
62
  use_dsl
62
63
  named :concept
63
64
  name_positional_attributes "id", "word", "term"
64
- #match %r{concept:(?<target>[^\[]*)\[(?<content>|.*?[^\\])\]$}
65
+ # match %r{concept:(?<target>[^\[]*)\[(?<content>|.*?[^\\])\]$}
65
66
  match /\{\{(?<content>|.*?[^\\])\}\}/
66
67
  using_format :short
67
68
 
68
69
  # deal with locality attrs and their disruption of positional attrs
69
70
  def preprocess_attrs(attrs)
70
- attrs.delete("term") if attrs["term"] and !attrs["word"]
71
+ attrs.delete("term") if attrs["term"] && !attrs["word"]
71
72
  attrs.delete(3) if attrs[3] == attrs["term"]
72
- a = attrs.keys.reject { |k| k.is_a? String or [1, 2].include? k }
73
- attrs["word"] ||= attrs[a[0]] if a.length() > 0
74
- attrs["term"] ||= attrs[a[1]] if a.length() > 1
73
+ a = attrs.keys.reject { |k| k.is_a?(String) || [1, 2].include?(k) }
74
+ attrs["word"] ||= attrs[a[0]] if !a.empty?
75
+ attrs["term"] ||= attrs[a[1]] if a.length > 1
75
76
  attrs
76
77
  end
77
78
 
@@ -94,30 +95,30 @@ module Asciidoctor
94
95
 
95
96
  def init_indent(s)
96
97
  /^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ s
97
- prefix = prefix.gsub(/\t/, "\u00a0\u00a0\u00a0\u00a0").
98
- gsub(/ /, "\u00a0")
98
+ prefix = prefix.gsub(/\t/, "\u00a0\u00a0\u00a0\u00a0")
99
+ .gsub(/ /, "\u00a0")
99
100
  prefix + suffix
100
101
  end
101
102
 
102
103
  def supply_br(lines)
103
104
  ignore = false
104
105
  lines.each_with_index do |l, i|
105
- /^(--+|====+|\|===|\.\.\.\.+|\*\*\*\*+|\+\+\+\++|\`\`\`\`+|____\+)$/.match(l) and
106
- ignore = !ignore
106
+ /^(--+|====+|\|===|\.\.\.\.+|\*\*\*\*+|\+\+\+\++|\`\`\`\`+|____\+)$/.match(l) &&
107
+ (ignore = !ignore)
107
108
  next if l.empty? || l.match(/ \+$/)
108
109
  next if /^\[.*\]$/.match(l)
109
110
  next if ignore
110
- next if i == lines.size - 1 || i < lines.size - 1 && lines[i+1].empty?
111
+ next if i == lines.size - 1 || i < lines.size - 1 && lines[i + 1].empty?
111
112
  lines[i] += " +"
112
113
  end
113
114
  lines
114
115
  end
115
116
 
116
- def process parent, reader, attrs
117
- attrs['role'] = 'pseudocode'
117
+ def process(parent, reader, attrs)
118
+ attrs["role"] = "pseudocode"
118
119
  lines = reader.lines.map { |m| init_indent(m) }
119
120
  ret = create_block(parent, :example, supply_br(lines),
120
- attrs, content_model: :compound)
121
+ attrs, content_model: :compound)
121
122
  ret
122
123
  end
123
124
  end
@@ -128,19 +129,19 @@ module Asciidoctor
128
129
  parse_content_as :text
129
130
  option :pos_attrs, %w(rpbegin rt rpend)
130
131
 
131
- def process(parent, target, attributes)
132
- rpbegin = '('
133
- rpend = ')'
134
- if attributes.size == 1 and attributes.key?("text")
132
+ def process(_parent, target, attributes)
133
+ rpbegin = "("
134
+ rpend = ")"
135
+ if (attributes.size == 1) && attributes.key?("text")
135
136
  rt = attributes["text"]
136
- elsif attributes.size == 2 and attributes.key?(1) and
137
- attributes.key?("rpbegin")
137
+ elsif (attributes.size == 2) && attributes.key?(1) &&
138
+ attributes.key?("rpbegin")
138
139
  # for example, html5ruby:楽聖少女[がくせいしょうじょ]
139
140
  rt = attributes[1] || ""
140
141
  else
141
- rpbegin = attributes['rpbegin']
142
- rt = attributes['rt']
143
- rpend = attributes['rpend']
142
+ rpbegin = attributes["rpbegin"]
143
+ rt = attributes["rt"]
144
+ rpend = attributes["rpend"]
144
145
  end
145
146
 
146
147
  "<ruby>#{target}<rp>#{rpbegin}</rp><rt>#{rt}</rt>"\
@@ -153,16 +154,16 @@ module Asciidoctor
153
154
  named :TODO
154
155
  on_contexts :example, :paragraph
155
156
 
156
- def process parent, reader, attrs
157
- attrs['name'] = 'todo'
158
- attrs['caption'] = 'TODO'
157
+ def process(parent, reader, attrs)
158
+ attrs["name"] = "todo"
159
+ attrs["caption"] = "TODO"
159
160
  create_block parent, :admonition, reader.lines, attrs,
160
- content_model: :compound
161
+ content_model: :compound
161
162
  end
162
163
  end
163
164
 
164
165
  class ToDoInlineAdmonitionBlock < Extensions::Treeprocessor
165
- def process document
166
+ def process(document)
166
167
  (document.find_by context: :paragraph).each do |para|
167
168
  next unless /^TODO: /.match para.lines[0]
168
169
  parent = para.parent
@@ -170,10 +171,21 @@ module Asciidoctor
170
171
  para.set_attr("caption", "TODO")
171
172
  para.lines[0].sub!(/^TODO: /, "")
172
173
  todo = Block.new parent, :admonition, attributes: para.attributes,
173
- source: para.lines, content_model: :compound
174
+ source: para.lines, content_model: :compound
174
175
  parent.blocks[parent.blocks.index(para)] = todo
175
176
  end
176
177
  end
177
178
  end
179
+
180
+ class AutonumberInlineMacro < Extensions::InlineMacroProcessor
181
+ use_dsl
182
+ named :autonumber
183
+ parse_content_as :text
184
+
185
+ def process(parent, target, attrs)
186
+ out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
187
+ %{<autonumber type=#{target}>#{out}</autonumber>}
188
+ end
189
+ end
178
190
  end
179
191
  end