coradoc 2.0.19 → 2.0.20
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 +4 -4
- data/lib/coradoc/core_model/block.rb +7 -1
- data/lib/coradoc/core_model/callout.rb +32 -0
- data/lib/coradoc/core_model/callout_text.rb +35 -0
- data/lib/coradoc/core_model.rb +2 -0
- data/lib/coradoc/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 05f1c48e0de6edb3f2473ab0e1c0cdb4747c513bf805820b8456846888b86c37
|
|
4
|
+
data.tar.gz: caaadd87ea878292673070688c08c8a7bfb7c39c58173f928e1960eb5af397ad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86f2108a83a94d30b5660586c5b83085b1b9f1ebd0ab470d21292f258cc0473d4769eb266394082d335a7d39ed2499297f0d4d1f1e2ac517c42f3d5b3bbe3527
|
|
7
|
+
data.tar.gz: aa4241a2a9c0ae8cec854b747b76a709bb8954b9bbbf6a3c15b3ebaad77f7b1dea199fc57129541fadcce94bee957cde48f7c3bda906379a5095a4893efdd0e1
|
|
@@ -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
|
data/lib/coradoc/core_model.rb
CHANGED
|
@@ -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"
|
data/lib/coradoc/version.rb
CHANGED
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.
|
|
4
|
+
version: 2.0.20
|
|
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
|