coradoc-html 1.1.19 → 1.1.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 +4 -4
- data/lib/coradoc/html/config.rb +4 -1
- data/lib/coradoc/html/converters.rb +1 -1
- data/lib/coradoc/html/drop/definition_item_drop.rb +17 -0
- data/lib/coradoc/html/reference_materializers/link.rb +44 -0
- data/lib/coradoc/html/reference_materializers/navigation.rb +77 -0
- data/lib/coradoc/html/reference_materializers.rb +22 -0
- data/lib/coradoc/html/version.rb +1 -1
- data/lib/coradoc/html.rb +4 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 78a6409c37e529e753bea5a39adc627dc5c2c059970feac19f0026fd3faf640b
|
|
4
|
+
data.tar.gz: e3edeb7c93d81f268f52919a36960061c9ea3c56c8aa31f0095d3c18708a6585
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a522853052a688ed9342752416eecb09118250e3c175191a8e3a88baa0ae1e4976f17446a5daddf82e849a9b34c6313258a6926e1f8efc2aa93725dcd086d275
|
|
7
|
+
data.tar.gz: addbcb3a1a19879f4dc4f83b68ae2f34cd5687488fa017d31a1367d847f2c693c7dcc639bdeb3445d4437ccfa9d958cf21d67428c8ec8992d4d8ab9aed854d31
|
data/lib/coradoc/html/config.rb
CHANGED
|
@@ -118,7 +118,10 @@ module Coradoc
|
|
|
118
118
|
attrs = {}
|
|
119
119
|
attrs[:class] = "language-#{language}" if language && !language.empty?
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
if options[:linenums] || options[:line_numbers]
|
|
122
|
+
attrs[:class] =
|
|
123
|
+
[attrs[:class], 'line-numbers'].compact.join(' ')
|
|
124
|
+
end
|
|
122
125
|
|
|
123
126
|
attrs
|
|
124
127
|
end
|
|
@@ -8,6 +8,17 @@ module Coradoc
|
|
|
8
8
|
Escape.escape_html(stripped_term)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
# All terms on this `<dt>`, escaped and id-stripped. Multi-term
|
|
12
|
+
# `<dt>`'s (AsciiDoc `term1::\nterm2::`) carry multiple entries;
|
|
13
|
+
# templates iterate this collection to emit one `<dt>` per term.
|
|
14
|
+
# Falls back to `[term]` for legacy callers that only set the
|
|
15
|
+
# singular `term` accessor.
|
|
16
|
+
def terms
|
|
17
|
+
raw = @model.terms
|
|
18
|
+
collection = raw.nil? || raw.empty? ? [@model.term.to_s] : raw.map(&:to_s)
|
|
19
|
+
collection.map { |t| Escape.escape_html(strip_term_id(t)) }
|
|
20
|
+
end
|
|
21
|
+
|
|
11
22
|
def term_id
|
|
12
23
|
match = term_text.match(/\A\[\[([^\]]+)\]\]/)
|
|
13
24
|
match&.[](1)
|
|
@@ -36,6 +47,12 @@ module Coradoc
|
|
|
36
47
|
def stripped_term
|
|
37
48
|
term_text.sub(/\A\[\[[^\]]+\]\]/, '')
|
|
38
49
|
end
|
|
50
|
+
|
|
51
|
+
# Strip a leading `[[id]]` anchor from a term string. Shared by
|
|
52
|
+
# `terms` (per-entry) and `stripped_term` (primary term).
|
|
53
|
+
def strip_term_id(text)
|
|
54
|
+
text.to_s.sub(/\A\[\[[^\]]+\]\]/, '')
|
|
55
|
+
end
|
|
39
56
|
end
|
|
40
57
|
|
|
41
58
|
DropFactory.register(CoreModel::DefinitionItem, DefinitionItemDrop)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Coradoc
|
|
4
|
+
module Html
|
|
5
|
+
module ReferenceMaterializers
|
|
6
|
+
# Render a hyperlink edge as a LinkElement with the URL as target.
|
|
7
|
+
# The catalog is not consulted — links are external by definition.
|
|
8
|
+
class Link < Coradoc::Reference::Materializer::Base
|
|
9
|
+
class << self
|
|
10
|
+
def kind
|
|
11
|
+
:link
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def presentation
|
|
15
|
+
:any
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def format
|
|
19
|
+
:html
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def materialize(edge:, **)
|
|
24
|
+
text = display_text(edge)
|
|
25
|
+
Coradoc::CoreModel::LinkElement.new(
|
|
26
|
+
target: edge.address.to_s,
|
|
27
|
+
content: text,
|
|
28
|
+
children: [
|
|
29
|
+
Coradoc::CoreModel::TextElement.new(content: text)
|
|
30
|
+
]
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def display_text(edge)
|
|
37
|
+
return edge.label if edge.label && !edge.label.empty?
|
|
38
|
+
|
|
39
|
+
edge.address.to_s
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Coradoc
|
|
4
|
+
module Html
|
|
5
|
+
module ReferenceMaterializers
|
|
6
|
+
# Render a navigation edge (:navigation kind) as an HTML-shaped
|
|
7
|
+
# CoreModel::LinkElement. The href is computed by asking the
|
|
8
|
+
# Presentation where the target lives (so the same edge renders
|
|
9
|
+
# to different hrefs under different presentations). Edges whose
|
|
10
|
+
# target lives on another page get a page-prefixed href.
|
|
11
|
+
class Navigation < Coradoc::Reference::Materializer::Base
|
|
12
|
+
class << self
|
|
13
|
+
def kind
|
|
14
|
+
:navigation
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def presentation
|
|
18
|
+
:any
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def format
|
|
22
|
+
:html
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def materialize(edge:, result:, node:, presentation:, pages:)
|
|
27
|
+
href = href_for(edge, result, node, presentation, pages)
|
|
28
|
+
text = display_text(edge, result)
|
|
29
|
+
Coradoc::CoreModel::LinkElement.new(
|
|
30
|
+
target: href,
|
|
31
|
+
content: text,
|
|
32
|
+
children: [
|
|
33
|
+
Coradoc::CoreModel::TextElement.new(content: text)
|
|
34
|
+
]
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def href_for(edge, result, node, presentation, pages)
|
|
41
|
+
return edge.address.to_s unless result.is_a?(Coradoc::Reference::Result::Resolved)
|
|
42
|
+
return edge.address.to_s unless presentation && pages
|
|
43
|
+
|
|
44
|
+
target_page = presentation.locate_page(edge, result.target, pages: pages)
|
|
45
|
+
return edge.address.to_s unless target_page
|
|
46
|
+
|
|
47
|
+
source_page = node && presentation.locate_page(edge, node, pages: pages)
|
|
48
|
+
build_href(target_page, source_page, result.target)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def build_href(target_page, source_page, target)
|
|
52
|
+
anchor = anchor_for(target)
|
|
53
|
+
cross_page = source_page && !source_page.equal?(target_page)
|
|
54
|
+
prefix = cross_page ? page_path(target_page) : ''
|
|
55
|
+
return "#{prefix}##{anchor}" if anchor
|
|
56
|
+
|
|
57
|
+
page_path(target_page)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def page_path(page)
|
|
61
|
+
page.id || '#'
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def anchor_for(target)
|
|
65
|
+
target.id if target.is_a?(Coradoc::CoreModel::Base) && target.id
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def display_text(edge, result)
|
|
69
|
+
return edge.label if edge.label && !edge.label.empty?
|
|
70
|
+
return result.target.title if result.is_a?(Coradoc::Reference::Result::Resolved) && result.target&.title
|
|
71
|
+
|
|
72
|
+
edge.address.to_s
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Coradoc
|
|
4
|
+
module Html
|
|
5
|
+
# Materializers rendering resolved reference Edges into
|
|
6
|
+
# HTML-shaped CoreModel nodes. They live in the format gem (not
|
|
7
|
+
# coradoc core) so format knowledge stays at the spoke of the
|
|
8
|
+
# hub-and-spoke architecture; registration is a load-time side
|
|
9
|
+
# effect via the Materializer registry's global extension point.
|
|
10
|
+
module ReferenceMaterializers
|
|
11
|
+
autoload :Navigation, 'coradoc/html/reference_materializers/navigation'
|
|
12
|
+
autoload :Link, 'coradoc/html/reference_materializers/link'
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Coradoc::Reference::Materializer::Registry.register_global(
|
|
18
|
+
Coradoc::Html::ReferenceMaterializers::Navigation
|
|
19
|
+
)
|
|
20
|
+
Coradoc::Reference::Materializer::Registry.register_global(
|
|
21
|
+
Coradoc::Html::ReferenceMaterializers::Link
|
|
22
|
+
)
|
data/lib/coradoc/html/version.rb
CHANGED
data/lib/coradoc/html.rb
CHANGED
|
@@ -237,3 +237,7 @@ end
|
|
|
237
237
|
Coradoc.register_format(:html, Coradoc::Html,
|
|
238
238
|
aliases: %w[html htm],
|
|
239
239
|
extensions: %w[.html .htm])
|
|
240
|
+
|
|
241
|
+
# Reference materializers for format: :html. Required (not autoloaded)
|
|
242
|
+
# because registration is a load-time side effect, like register_format.
|
|
243
|
+
require 'coradoc/html/reference_materializers'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: coradoc-html
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.21
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -190,6 +190,9 @@ files:
|
|
|
190
190
|
- lib/coradoc/html/plugin.rb
|
|
191
191
|
- lib/coradoc/html/plugins/plateau.rb
|
|
192
192
|
- lib/coradoc/html/postprocessor.rb
|
|
193
|
+
- lib/coradoc/html/reference_materializers.rb
|
|
194
|
+
- lib/coradoc/html/reference_materializers/link.rb
|
|
195
|
+
- lib/coradoc/html/reference_materializers/navigation.rb
|
|
193
196
|
- lib/coradoc/html/render_options.rb
|
|
194
197
|
- lib/coradoc/html/renderer.rb
|
|
195
198
|
- lib/coradoc/html/section_numberable.rb
|