coradoc 2.0.19 → 2.0.21

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfb7ecfe3eb593e8a88dc23950b2e75fb5bafd4ea8f31ee7840c44e1cdaadd28
4
- data.tar.gz: 1835d0ac0defa944dc45d26c967d3e9ddb0d20a599f79c85657531689c67faf0
3
+ metadata.gz: a4ebd4f989cb1c3bc9c6adcede592e91c6013a29bf94c3d12319e03c5c42ab38
4
+ data.tar.gz: d321f36297bb31aac76fe30a6195aa9cd1456c840dfb1888405c0e36f474c4b7
5
5
  SHA512:
6
- metadata.gz: b1a73e74172ae6af0dd2a5426f520b546170c2a4f00910f91dd45211bccf448ca187d45b64ba94030549331008a50adaff283ca1ced17c39bb164d6a6cd9a032
7
- data.tar.gz: 57efec479b5c118c4c18d99d7e0b0090046ef1c42ed17b265804f044467775fb82781bec4a7c3a119b24a428ff46ec50c642e4557488471447f5e96af48d4572
6
+ metadata.gz: 1bba8d765b1af164d1713f16013eddbdbc906340f37d1918777fd3ec1c6f1ec784e869155ccae100b6d4a4306bea003c4031fbf6276890608471a97d5a407bd2
7
+ data.tar.gz: e76a4e152ebbc25ee03732c6870fbfbdf062d8a3e0af8423b4da9486d14483952a56a3af6b25c256a6350e60e475afa89112e25931b08b47209884ceb1e8089a
@@ -53,10 +53,16 @@ module Coradoc
53
53
  # @return [String, nil] language identifier for source code blocks
54
54
  attribute :language, :string
55
55
 
56
+ # @!attribute callouts
57
+ # @return [Array<Callout>] callout annotations attached to this
58
+ # block. Empty for most block types; populated by format gems
59
+ # when AsciiDoc-style `<N>` annotations follow a verbatim block.
60
+ attribute :callouts, Callout, collection: true, default: -> { [] }
61
+
56
62
  private
57
63
 
58
64
  def comparable_attributes
59
- super + %i[block_semantic_type content]
65
+ super + %i[block_semantic_type content callouts]
60
66
  end
61
67
  end
62
68
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module CoreModel
5
+ # A single callout annotation attached to a verbatim block.
6
+ #
7
+ # Callouts are the AsciiDoc convention for annotating individual lines
8
+ # of a source/listing block: `<1>` markers appear inside the code and
9
+ # matching `<1> explanation` lines follow the block. Markdown has no
10
+ # native equivalent, so each format gem decides how to render them.
11
+ #
12
+ # The CoreModel stores each annotation as a typed Callout on its parent
13
+ # block, with the in-code marker `<index>` preserved in the block's
14
+ # `content` for verbatim round-trip.
15
+ class Callout < Base
16
+ # @!attribute index
17
+ # @return [Integer, nil] 1-based callout number matching the
18
+ # `<N>` marker embedded in the parent block's content.
19
+ attribute :index, :integer
20
+
21
+ # @!attribute content
22
+ # @return [String, nil] human-readable annotation text.
23
+ attribute :content, :string
24
+
25
+ private
26
+
27
+ def comparable_attributes
28
+ super + %i[index content]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module CoreModel
5
+ # Shared helpers for rendering Callout-annotated verbatim blocks.
6
+ #
7
+ # Both the Markdown and HTML spokes need to (a) order callouts by their
8
+ # numeric index and (b) strip AsciiDoc-style `<N>` markers from the
9
+ # raw code so they don't leak as literal text in the output format.
10
+ # Centralizing these operations here keeps the behavior consistent
11
+ # across spokes and avoids copy-paste drift.
12
+ module CalloutText
13
+ module_function
14
+
15
+ def ordered(callouts)
16
+ Array(callouts).sort_by { |c| c.index || Float::INFINITY }
17
+ end
18
+
19
+ # Removes callout markers (`<N>`) from `code` for the indices
20
+ # referenced by `callouts`. Returns `code` unchanged when no
21
+ # callouts are provided or none carry a usable index, so literal
22
+ # `<N>` sequences in code without callouts are preserved.
23
+ def strip_markers(code, callouts)
24
+ list = Array(callouts)
25
+ return code if list.empty?
26
+
27
+ indices = list.filter_map(&:index).uniq
28
+ return code if indices.empty?
29
+
30
+ pattern = /<\s*(?:#{indices.join('|')})\s*>/
31
+ code.to_s.lines(chomp: true).map { |line| line.gsub(pattern, '').rstrip }.join("\n")
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module CoreModel
5
+ # Inline raw passthrough — content the source format marked as "do not
6
+ # process". AsciiDoc's `+++raw+++` is the canonical producer. Spokes
7
+ # that lack a passthrough concept (most of them) should emit the
8
+ # content verbatim, since the original author explicitly chose raw
9
+ # markup (often HTML) knowing it would be passed through.
10
+ class RawInlineElement < InlineElement
11
+ def self.format_type
12
+ 'raw_inline'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -12,6 +12,8 @@ module Coradoc
12
12
  # Autoload submodules lazily using relative paths
13
13
  autoload :Base, "#{__dir__}/core_model/base"
14
14
  autoload :ChildrenContent, "#{__dir__}/core_model/children_content"
15
+ autoload :Callout, "#{__dir__}/core_model/callout"
16
+ autoload :CalloutText, "#{__dir__}/core_model/callout_text"
15
17
  autoload :Block, "#{__dir__}/core_model/block"
16
18
  autoload :AnnotationBlock, "#{__dir__}/core_model/annotation_block"
17
19
  autoload :ListBlock, "#{__dir__}/core_model/list_block"
@@ -34,6 +36,7 @@ module Coradoc
34
36
  autoload :SpanElement, "#{__dir__}/core_model/inline_element"
35
37
  autoload :TermElement, "#{__dir__}/core_model/inline_element"
36
38
  autoload :LineBreakElement, "#{__dir__}/core_model/inline_element"
39
+ autoload :RawInlineElement, "#{__dir__}/core_model/raw_inline_element"
37
40
  autoload :StructuralElement, "#{__dir__}/core_model/structural_element"
38
41
  autoload :DocumentElement, "#{__dir__}/core_model/structural_element"
39
42
  autoload :SectionElement, "#{__dir__}/core_model/structural_element"
@@ -23,6 +23,11 @@ module Coradoc
23
23
  def passed?
24
24
  duration < threshold
25
25
  end
26
+
27
+ def format_line
28
+ status = passed? ? 'PASS' : 'FAIL'
29
+ " #{status} #{name}: #{duration.round(4)}s (threshold: #{threshold}s)"
30
+ end
26
31
  end
27
32
 
28
33
  ComparisonResult = Struct.new(:name, :duration, :baseline, keyword_init: true) do
@@ -31,6 +36,12 @@ module Coradoc
31
36
 
32
37
  (duration - baseline).abs / baseline > pct
33
38
  end
39
+
40
+ def format_line
41
+ status = regressed? ? 'WARN' : 'OK'
42
+ baseline_str = baseline ? "(baseline: #{baseline.round(4)}s)" : '(no baseline)'
43
+ " #{status} #{name}: #{duration.round(4)}s #{baseline_str}"
44
+ end
34
45
  end
35
46
 
36
47
  class << self
@@ -50,14 +61,15 @@ module Coradoc
50
61
  { results:, failed_count: failed, total: results.size }
51
62
  end
52
63
 
53
- def print_results(summary)
54
- results = summary[:results]
55
- results.each do |r|
56
- status = r.passed? ? 'PASS' : 'FAIL'
57
- puts " #{status} #{r.name}: #{r.duration.round(4)}s (threshold: #{r.threshold}s)"
64
+ def print_results(summary_or_results)
65
+ if summary_or_results.is_a?(Hash)
66
+ summary = summary_or_results
67
+ summary[:results].each { |r| puts r.format_line }
68
+ puts
69
+ puts "#{summary[:total] - summary[:failed_count]}/#{summary[:total]} passed"
70
+ else
71
+ Array(summary_or_results).each { |r| puts r.format_line }
58
72
  end
59
- puts
60
- puts "#{summary[:total] - summary[:failed_count]}/#{summary[:total]} passed"
61
73
  end
62
74
 
63
75
  def compare_with_baseline(baseline_path, iterations: 3)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Coradoc
4
- VERSION = '2.0.19'
4
+ VERSION = '2.0.21'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coradoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.19
4
+ version: 2.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -60,6 +60,8 @@ files:
60
60
  - lib/coradoc/core_model/bibliography.rb
61
61
  - lib/coradoc/core_model/bibliography_entry.rb
62
62
  - lib/coradoc/core_model/block.rb
63
+ - lib/coradoc/core_model/callout.rb
64
+ - lib/coradoc/core_model/callout_text.rb
63
65
  - lib/coradoc/core_model/children_content.rb
64
66
  - lib/coradoc/core_model/comment_block.rb
65
67
  - lib/coradoc/core_model/comment_line.rb
@@ -86,6 +88,7 @@ files:
86
88
  - lib/coradoc/core_model/paragraph_block.rb
87
89
  - lib/coradoc/core_model/pass_block.rb
88
90
  - lib/coradoc/core_model/quote_block.rb
91
+ - lib/coradoc/core_model/raw_inline_element.rb
89
92
  - lib/coradoc/core_model/reviewer_block.rb
90
93
  - lib/coradoc/core_model/sidebar_block.rb
91
94
  - lib/coradoc/core_model/source_block.rb