metanorma-standoc 2.5.0 → 2.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d6a56b88b9f58482764ff6aede297e389577151d0d112a215b2215d5cfb41cf
4
- data.tar.gz: cb0a1a1d73930e89169a27185bcce3d19130f1150a22fd7345da61a73dbd759f
3
+ metadata.gz: 20b6d6b6948c9eae42b87ef8c6c8a96fcbabdd64f44d3effd972285e5f30ec62
4
+ data.tar.gz: c048925049205b4fbbb2ce7883bc786b7ffd97970bae250226844fbf9801000f
5
5
  SHA512:
6
- metadata.gz: 158547c563e269b769f39123cbd03f749a4891f7e4c772e9462ea40a9221ee4b58839991b2580fc40d9a24007387866d2741867ee6a8f5f39770fa3d38a57138
7
- data.tar.gz: ba7b26ed9ebfae0f92dedc50750aad4e31c53b5e5b16defe3e2a2ea6583049fab738f07449846ac62aa74af06944d725389fed9d54357bf9ff9c33b3196cac2f
6
+ metadata.gz: 437c944d237d240b0efc821cc7b84e99dc919557f8474c07922c1dd688dbdb7838e13d523fcfe44b308bdf322c1b4a5405a7c95553ef633e12b7e99b28906714
7
+ data.tar.gz: f233558ba151d531f9c67c07e75e6b2c22aabc38054db61d594abb17b6445c4e31a52931129686156b53e11bec282ec256d964b1bd9b339eca64449a8109a75d
@@ -1,5 +1,6 @@
1
1
  require "metanorma-utils"
2
2
  require "digest"
3
+ require "addressable/uri"
3
4
 
4
5
  module Metanorma
5
6
  module Standoc
@@ -208,8 +209,8 @@ module Metanorma
208
209
 
209
210
  def link_cleanup(xmldoc)
210
211
  xmldoc.xpath("//link[@target]").each do |l|
211
- l["target"] = URI.parse(l["target"]).to_s
212
- rescue StandardError
212
+ l["target"] = Addressable::URI.parse(l["target"]).to_s
213
+ rescue Addressable::URI::InvalidURIError
213
214
  err = "Malformed URI: #{l['target']}"
214
215
  @log.add("Anchors", l, err)
215
216
  @fatalerror << err
@@ -12,7 +12,7 @@ require_relative "validate"
12
12
  require_relative "utils"
13
13
  require_relative "cleanup"
14
14
  require_relative "reqt"
15
- require_relative "./macros"
15
+ require_relative "macros"
16
16
 
17
17
  module Metanorma
18
18
  module Standoc
@@ -22,6 +22,7 @@ module Metanorma
22
22
  Asciidoctor::Extensions.register do
23
23
  preprocessor Metanorma::Standoc::EmbedIncludeProcessor
24
24
  preprocessor Metanorma::Standoc::NamedEscapePreprocessor
25
+ preprocessor Metanorma::Standoc::LinkProtectPreprocessor
25
26
  preprocessor Metanorma::Standoc::Datamodel::AttributesTablePreprocessor
26
27
  preprocessor Metanorma::Standoc::Datamodel::DiagramPreprocessor
27
28
  preprocessor Metanorma::Plugin::Datastruct::Json2TextPreprocessor
@@ -1,14 +1,14 @@
1
1
  require "uuidtools"
2
2
  require "yaml"
3
3
  require "csv"
4
- require_relative "./macros_inline"
5
- require_relative "./macros_plantuml"
6
- require_relative "./macros_terms"
7
- require_relative "./macros_form"
8
- require_relative "./macros_note"
9
- require_relative "./macros_embed"
10
- require_relative "./datamodel/attributes_table_preprocessor"
11
- require_relative "./datamodel/diagram_preprocessor"
4
+ require_relative "macros_inline"
5
+ require_relative "macros_plantuml"
6
+ require_relative "macros_terms"
7
+ require_relative "macros_form"
8
+ require_relative "macros_note"
9
+ require_relative "macros_embed"
10
+ require_relative "datamodel/attributes_table_preprocessor"
11
+ require_relative "datamodel/diagram_preprocessor"
12
12
  require "metanorma-plugin-datastruct"
13
13
  require "metanorma-plugin-glossarist"
14
14
  require "metanorma-plugin-lutaml"
@@ -22,7 +22,7 @@ module Metanorma
22
22
 
23
23
  def init_indent(line)
24
24
  /^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ line
25
- prefix = prefix.gsub(/\t/, "\u00a0\u00a0\u00a0\u00a0")
25
+ prefix = prefix.gsub("\t", "\u00a0\u00a0\u00a0\u00a0")
26
26
  .gsub(/ /, "\u00a0")
27
27
  prefix + suffix
28
28
  end
@@ -31,9 +31,9 @@ module Metanorma
31
31
  ignore = false
32
32
  lines.each_with_index do |l, i|
33
33
  /^(--+|====+|\|===|\.\.\.\.+|\*\*\*\*+|\+\+\+\++|````+|____\+)$/
34
- .match(l) && (ignore = !ignore)
35
- next if l.empty? || l.match(/ \+$/) || /^\[.*\]$/.match?(l) || ignore
36
- next if i == lines.size - 1 ||
34
+ .match(l) and (ignore = !ignore)
35
+ next if l.empty? || l.match(/ \+$/) || /^\[.*\]$/.match?(l) ||
36
+ ignore || i == lines.size - 1 ||
37
37
  (i < lines.size - 1 && lines[i + 1].empty?)
38
38
 
39
39
  lines[i] += " +"
@@ -60,5 +60,111 @@ module Metanorma
60
60
  ::Asciidoctor::Reader.new lines
61
61
  end
62
62
  end
63
+
64
+ # refer https://github.com/asciidoctor/asciidoctor/blob/main/lib/asciidoctor/substitutors.rb
65
+ # Not using TreeProcessor because that is still too close to
66
+ # inline expressions being processed on access (e.g. titles)
67
+ class LinkProtectPreprocessor < Asciidoctor::Extensions::Preprocessor
68
+ def init
69
+ pass = true # process as passthrough: init = true until
70
+ # hit end of doc header
71
+ is_delim = false # current line is a no-substititon block delimiter
72
+ pass_delim = false # current line is a passthrough delimiter
73
+ delimln = "" # delimiter line of current block(s);
74
+ # init value looks for end of doc header
75
+ { pass: pass, is_delim: is_delim, pass_delim: pass_delim,
76
+ delimln: delimln }
77
+ end
78
+
79
+ def process(_document, reader)
80
+ p = init
81
+ lines = reader.readlines.map do |t|
82
+ p = pass_status(p, t.rstrip)
83
+ !p[:pass] && t.include?(":") and t = inlinelinkmacro(inlinelink(t))
84
+ t
85
+ end
86
+ ::Asciidoctor::Reader.new lines
87
+ end
88
+
89
+ def pass_status(status, text)
90
+ text == "++++" && !status[:delimln] and status[:pass] = !status[:pass]
91
+ if status[:is_delim] && /^(-+|\*+|=+|_+)$/.match?(text)
92
+ status[:delimln] = text
93
+ status[:pass] = true
94
+ elsif status[:pass_delim]
95
+ status[:delimln] = "" # end of paragraph for paragraph with [pass]
96
+ elsif status[:delimln] && text == status[:delimln]
97
+ status[:pass] = false
98
+ status[:delimln] = nil
99
+ end
100
+ status[:is_delim] = /^\[(source|listing|literal|pass)\b/.match?(text)
101
+ status[:pass_delim] = /^\[(pass)\b/.match?(text)
102
+ status
103
+ end
104
+
105
+ PASS_INLINE_MACROS = %w(pass pass-format identifier std-link stem)
106
+ .join("|").freeze
107
+
108
+ PASS_INLINE_MACRO_STR = <<~REGEX.freeze
109
+ (
110
+ \\b(?<![-\\\\]) # word-separator, no hyphen or backslash
111
+ (?: # don't capture these!
112
+ (?:#{PASS_INLINE_MACROS}):[^\\s\\[]* | # macro name, :, second key. OR:
113
+ span:uri \\b [^\\s\\[]* # span:uri, third key
114
+ )
115
+ \\[.*?(?<!\\\\)\\] # [ ... ] not preceded by \\
116
+ )
117
+ REGEX
118
+ PASS_INLINE_MACRO_RX = /#{PASS_INLINE_MACRO_STR}/xo.freeze
119
+
120
+ def pass_inline_split(text)
121
+ text.split(PASS_INLINE_MACRO_RX).each.map do |x|
122
+ PASS_INLINE_MACRO_RX.match?(x) ? x : yield(x)
123
+ end
124
+ end
125
+
126
+ # InlineLinkRx = %r((^|link:|#{CG_BLANK}|&lt;|[>\(\)\[\];"'])(\\?(?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)\[(|#{CC_ALL}*?[^\\])\]|([^\s\[\]<]*([^\s,.?!\[\]<\)]))))m
127
+ #
128
+ InlineLinkRx = %r((^|(?<![-\\])\blink:(?!\+)|\p{Blank}|&lt;|[<>\(\)\[\];"'])((?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)(?:(\[(|.*?[^\\])\])|([^\s\[\]<]*([^\s,.?!\[\]<\)])))))m.freeze
129
+
130
+ def inlinelink(text)
131
+ text.include?("://") or return text
132
+ pass_inline_split(text) do |x|
133
+ inlinelink_escape(x)
134
+ end.join
135
+ end
136
+
137
+ def inlinelink_escape(text)
138
+ text.gsub(InlineLinkRx) do
139
+ body, suffix = $4.nil? ? [$3 + $6, "[]"] : [$3, ""]
140
+ p = $1 and s = $2 and b = $4
141
+ if p == "link:" then "#{p}++#{s}#{body}++#{b}#{suffix}"
142
+ elsif p == "<"
143
+ "#{p}link:++#{s}#{body.sub(/>$/, '')}++#{b}#{suffix}>"
144
+ else "#{p}link:++#{s}#{body}++#{b}#{suffix}"
145
+ end
146
+ end
147
+ end
148
+
149
+ # InlineLinkMacroRx = /\\?(?:link|(mailto)):(|[^:\s\[][^\s\[]*)\[(|#{CC_ALL}*?[^\\])\]/m
150
+ InlineLinkMacroRx1 = <<~REGEX.freeze
151
+ (\\\\?\\b(?<!-) # optional backslash, no hyphen, word boundary
152
+ (?:link|mailto):) # link: or mailto:
153
+ (?!\\+) # no link:+ passthrough
154
+ (|[^:\\s\\[][^\\s\\[]*) # link: ... up to [
155
+ (\\[(|.*?[^\\\\])\\]) # [ ... ], no ]
156
+ REGEX
157
+ InlineLinkMacroRx = /#{InlineLinkMacroRx1}/x.freeze
158
+
159
+ def inlinelinkmacro(text)
160
+ (text.include?("[") &&
161
+ ((text.include? "link:") || (text.include? "ilto:"))) or return text
162
+ pass_inline_split(text) do |x|
163
+ x.gsub(InlineLinkMacroRx) do
164
+ "#{$1}++#{$2}++#{$3}"
165
+ end
166
+ end.join
167
+ end
168
+ end
63
169
  end
64
170
  end
@@ -44,7 +44,7 @@ module Metanorma
44
44
  text = attr["text"]
45
45
  text = "((#{text}))" unless /^\(\(.+\)\)$/.match?(text)
46
46
  out = parent.sub_macros(text)
47
- out.sub(/<index>/, "<index to='#{target}'>")
47
+ out.sub("<index>", "<index to='#{target}'>")
48
48
  end
49
49
  end
50
50
 
@@ -148,7 +148,7 @@ module Metanorma
148
148
  content = CSV.parse_line(out).map do |x|
149
149
  x.sub!(/^(["'])(.+)\1/, "\\2")
150
150
  m = /^(.*?)(:\d+)?$/.match(x)
151
- %{<toc-xpath depth='#{m[2]&.sub(/:/, '') || 1}'>#{m[1]}</toc-xpath>}
151
+ %{<toc-xpath depth='#{m[2]&.sub(':', '') || 1}'>#{m[1]}</toc-xpath>}
152
152
  end.join
153
153
  "<toc>#{content}</toc>"
154
154
  end
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "2.5.0".freeze
22
+ VERSION = "2.5.2".freeze
23
23
  end
24
24
  end
@@ -28,10 +28,11 @@ Gem::Specification.new do |spec|
28
28
  end
29
29
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
30
30
 
31
+ spec.add_dependency "addressable", "~> 2.8.0"
31
32
  spec.add_dependency "asciidoctor", "~> 2.0.0"
32
33
  spec.add_dependency "iev", "~> 0.3.0"
33
34
  spec.add_dependency "isodoc", "~> 2.6.0"
34
- spec.add_dependency "metanorma", ">= 1.5.0"
35
+ spec.add_dependency "metanorma", ">= 1.6.0"
35
36
  spec.add_dependency "metanorma-plugin-datastruct", "~> 0.2.0"
36
37
  spec.add_dependency "metanorma-plugin-glossarist", "~> 0.1.1"
37
38
  spec.add_dependency "metanorma-plugin-lutaml"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-standoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-07 00:00:00.000000000 Z
11
+ date: 2023-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.8.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: asciidoctor
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +72,14 @@ dependencies:
58
72
  requirements:
59
73
  - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: 1.5.0
75
+ version: 1.6.0
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: 1.5.0
82
+ version: 1.6.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: metanorma-plugin-datastruct
71
85
  requirement: !ruby/object:Gem::Requirement