coradoc-html 1.1.13 → 1.1.14

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: d86ee1dfe0630fc0923c8bbaaf53a3a9653faf3a90f3fa6760e2abe765cc46a3
4
- data.tar.gz: 228cb361cb1b9a7dc64823788fac88afa87e5d972049064ffdd51d9909ad11a4
3
+ metadata.gz: 5217e76f323e6810ce042935550bc937bb0cebdd697a81cd2faa36c699f18139
4
+ data.tar.gz: 2a2ed099e968c197fd8a2b0c9f6e8c8a76fa43806160f9a0790b2c91e77b8356
5
5
  SHA512:
6
- metadata.gz: c219dbf71096377f684cd4ac7888e63248f1bf0ae279aec7e64923a1188bab59e57db330f4582cf5801155f2bfd061746c88dc4e61d79550130782459fd4b5e5
7
- data.tar.gz: db6bb17213127a330405a09785ae40a54c45c7ebfa5cf4f00709efeffe0534827401aa502e9fb10a3c6ab51c17cf257ad3129ffa7650d53c5a6f64c141954f50
6
+ metadata.gz: df38444fa4bc63f848ddc8ad42890f3a922885dfa43061c134bdb0fce28ec030462202e3f544a17f258b902e5773e48fd2c1fff9afd347cb2aa163106ff68484
7
+ data.tar.gz: dc61e5cbb6f946665745522aaa40a05a3dd11603ce25adb5d5dbb50e418a7e47874bb10aec691a8885f4df885a3a7d88b5a9f63773b12969ee92f2f6130079a6
@@ -70,8 +70,3 @@ module Coradoc
70
70
  end
71
71
  end
72
72
  end
73
-
74
- # Load DropFactory and all drops after Base is fully defined.
75
- # Each drop self-registers; DropFactory sorts by type specificity
76
- # so registration order doesn't matter.
77
- require_relative 'drop_factory'
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'base'
4
-
5
3
  module Coradoc
6
4
  module Html
7
5
  module Drop
@@ -51,23 +49,24 @@ module Coradoc
51
49
  end
52
50
  end
53
51
 
54
- # Load all drops — each self-registers with DropFactory
55
- require_relative 'annotation_drop'
56
- require_relative 'block_drop'
57
- require_relative 'list_block_drop'
58
- require_relative 'list_item_drop'
59
- require_relative 'table_drop'
60
- require_relative 'table_row_drop'
61
- require_relative 'table_cell_drop'
62
- require_relative 'image_drop'
63
- require_relative 'inline_element_drop'
64
- require_relative 'bibliography_entry_drop'
65
- require_relative 'bibliography_drop'
66
- require_relative 'toc_entry_drop'
67
- require_relative 'toc_drop'
68
- require_relative 'definition_item_drop'
69
- require_relative 'definition_list_drop'
70
- require_relative 'term_drop'
71
- require_relative 'footnote_drop'
72
- require_relative 'text_content_drop'
73
- require_relative 'document_drop'
52
+ # Load all drops — each self-registers with DropFactory.
53
+ # Registration order doesn't matter (sorted by ancestor depth).
54
+ require 'coradoc/html/drop/annotation_drop'
55
+ require 'coradoc/html/drop/block_drop'
56
+ require 'coradoc/html/drop/list_block_drop'
57
+ require 'coradoc/html/drop/list_item_drop'
58
+ require 'coradoc/html/drop/table_drop'
59
+ require 'coradoc/html/drop/table_row_drop'
60
+ require 'coradoc/html/drop/table_cell_drop'
61
+ require 'coradoc/html/drop/image_drop'
62
+ require 'coradoc/html/drop/inline_element_drop'
63
+ require 'coradoc/html/drop/bibliography_entry_drop'
64
+ require 'coradoc/html/drop/bibliography_drop'
65
+ require 'coradoc/html/drop/toc_entry_drop'
66
+ require 'coradoc/html/drop/toc_drop'
67
+ require 'coradoc/html/drop/definition_item_drop'
68
+ require 'coradoc/html/drop/definition_list_drop'
69
+ require 'coradoc/html/drop/term_drop'
70
+ require 'coradoc/html/drop/footnote_drop'
71
+ require 'coradoc/html/drop/text_content_drop'
72
+ require 'coradoc/html/drop/document_drop'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Drop namespace — manages Liquid drop layer for template rendering.
4
+ #
5
+ # Loading order matters: Base must load before DropFactory, and all
6
+ # concrete drops must load after DropFactory (they self-register).
7
+ # Each drop calls DropFactory.register at load time.
8
+ module Coradoc
9
+ module Html
10
+ module Drop
11
+ end
12
+ end
13
+ end
14
+
15
+ # Base must load first (DropFactory depends on it)
16
+ require 'coradoc/html/drop/base'
17
+ # DropFactory loads next
18
+ require 'coradoc/html/drop/drop_factory'
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'media_base'
4
-
5
3
  module Coradoc
6
4
  module Input
7
5
  module Html
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'positional_formatting'
4
-
5
3
  module Coradoc
6
4
  module Input
7
5
  module Html
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'positional_formatting'
4
-
5
3
  module Coradoc
6
4
  module Input
7
5
  module Html
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'media_base'
4
-
5
3
  module Coradoc
6
4
  module Input
7
5
  module Html
@@ -4,43 +4,51 @@ module Coradoc
4
4
  module Input
5
5
  module Html
6
6
  module Converters
7
- # Autoload converter classes - they will register themselves when first accessed
8
- autoload :Base, 'coradoc/html/input/converters/base'
9
- autoload :Markup, 'coradoc/html/input/converters/markup'
10
- autoload :A, 'coradoc/html/input/converters/a'
11
- autoload :Aside, 'coradoc/html/input/converters/aside'
12
- autoload :Audio, 'coradoc/html/input/converters/audio'
13
- autoload :Blockquote, 'coradoc/html/input/converters/blockquote'
14
- autoload :Br, 'coradoc/html/input/converters/br'
15
- autoload :Bypass, 'coradoc/html/input/converters/bypass'
16
- autoload :Code, 'coradoc/html/input/converters/code'
17
- autoload :Div, 'coradoc/html/input/converters/div'
18
- autoload :Dl, 'coradoc/html/input/converters/dl'
19
- autoload :Skip, 'coradoc/html/input/converters/drop'
20
- autoload :Em, 'coradoc/html/input/converters/em'
21
- autoload :Figure, 'coradoc/html/input/converters/figure'
22
- autoload :H, 'coradoc/html/input/converters/h'
23
- autoload :Head, 'coradoc/html/input/converters/head'
24
- autoload :Hr, 'coradoc/html/input/converters/hr'
25
- autoload :Img, 'coradoc/html/input/converters/img'
26
- autoload :Li, 'coradoc/html/input/converters/li'
27
- autoload :Mark, 'coradoc/html/input/converters/mark'
28
- autoload :Math, 'coradoc/html/input/converters/math'
29
- autoload :MediaBase, 'coradoc/html/input/converters/media_base'
30
- autoload :Ol, 'coradoc/html/input/converters/ol'
31
- autoload :P, 'coradoc/html/input/converters/p'
32
- autoload :PassThrough, 'coradoc/html/input/converters/pass_through'
33
- autoload :PositionalFormatting, 'coradoc/html/input/converters/positional_formatting'
34
- autoload :Pre, 'coradoc/html/input/converters/pre'
35
- autoload :Q, 'coradoc/html/input/converters/q'
36
- autoload :Strong, 'coradoc/html/input/converters/strong'
37
- autoload :Sup, 'coradoc/html/input/converters/sup'
38
- autoload :Sub, 'coradoc/html/input/converters/sub'
39
- autoload :Table, 'coradoc/html/input/converters/table'
40
- autoload :Td, 'coradoc/html/input/converters/td'
41
- autoload :Text, 'coradoc/html/input/converters/text'
42
- autoload :Tr, 'coradoc/html/input/converters/tr'
43
- autoload :Video, 'coradoc/html/input/converters/video'
7
+ # Autoload converter classes they self-register when loaded.
8
+ # Adding a new converter requires only adding one entry here.
9
+ CONVERTERS = {
10
+ Base: 'coradoc/html/input/converters/base',
11
+ Markup: 'coradoc/html/input/converters/markup',
12
+ A: 'coradoc/html/input/converters/a',
13
+ Aside: 'coradoc/html/input/converters/aside',
14
+ Audio: 'coradoc/html/input/converters/audio',
15
+ Blockquote: 'coradoc/html/input/converters/blockquote',
16
+ Br: 'coradoc/html/input/converters/br',
17
+ Bypass: 'coradoc/html/input/converters/bypass',
18
+ Code: 'coradoc/html/input/converters/code',
19
+ Div: 'coradoc/html/input/converters/div',
20
+ Dl: 'coradoc/html/input/converters/dl',
21
+ Skip: 'coradoc/html/input/converters/drop',
22
+ Em: 'coradoc/html/input/converters/em',
23
+ Figure: 'coradoc/html/input/converters/figure',
24
+ H: 'coradoc/html/input/converters/h',
25
+ Head: 'coradoc/html/input/converters/head',
26
+ Hr: 'coradoc/html/input/converters/hr',
27
+ Img: 'coradoc/html/input/converters/img',
28
+ Li: 'coradoc/html/input/converters/li',
29
+ Mark: 'coradoc/html/input/converters/mark',
30
+ Math: 'coradoc/html/input/converters/math',
31
+ MediaBase: 'coradoc/html/input/converters/media_base',
32
+ Ol: 'coradoc/html/input/converters/ol',
33
+ P: 'coradoc/html/input/converters/p',
34
+ PassThrough: 'coradoc/html/input/converters/pass_through',
35
+ PositionalFormatting: 'coradoc/html/input/converters/positional_formatting',
36
+ Pre: 'coradoc/html/input/converters/pre',
37
+ Q: 'coradoc/html/input/converters/q',
38
+ Strong: 'coradoc/html/input/converters/strong',
39
+ Sup: 'coradoc/html/input/converters/sup',
40
+ Sub: 'coradoc/html/input/converters/sub',
41
+ Table: 'coradoc/html/input/converters/table',
42
+ Td: 'coradoc/html/input/converters/td',
43
+ Text: 'coradoc/html/input/converters/text',
44
+ Tr: 'coradoc/html/input/converters/tr',
45
+ Video: 'coradoc/html/input/converters/video'
46
+ }.freeze
47
+ private_constant :CONVERTERS
48
+
49
+ CONVERTERS.each do |name, path|
50
+ autoload name, path
51
+ end
44
52
 
45
53
  @converters = {}
46
54
  @converters_loaded = false
@@ -57,12 +65,7 @@ module Coradoc
57
65
  return if @converters_loaded
58
66
 
59
67
  @converters_loaded = true
60
-
61
- [
62
- Base, Markup, A, Aside, Audio, Blockquote, Br, Bypass, Code, Div, Dl,
63
- Skip, Em, Figure, H, Head, Hr, Img, Li, Mark, Math, Ol, P,
64
- PassThrough, Pre, Q, Strong, Sup, Sub, Table, Td, Text, Tr, Video
65
- ].each { |converter| _ = converter }
68
+ CONVERTERS.each_key { |name| const_get(name) }
66
69
  end
67
70
 
68
71
  def self.lookup(tag_name)
@@ -65,13 +65,6 @@ module Coradoc
65
65
  Coradoc::Html::Input::Converters.process_coradoc(tree, state)
66
66
  end
67
67
 
68
- def html_tree_preview
69
- Tempfile.open(%w[coradoc .html]) do |i|
70
- i << html_tree.to_html
71
- system 'chromium-browser', '--no-sandbox', i.path
72
- end
73
- end
74
-
75
68
  # define preprocess_html_tree to process HTML trees
76
69
 
77
70
  # Creates a hook to be called instead of converting an element
@@ -49,7 +49,13 @@ module Coradoc
49
49
  end
50
50
 
51
51
  def render_html5(document, **options)
52
- @section_numbers = compute_section_numbers(document, options)
52
+ builder = TocBuilder.from_options(options)
53
+ @toc, @section_numbers = if document.is_a?(CoreModel::StructuralElement)
54
+ builder.build_with_numbers(document)
55
+ else
56
+ [nil, {}]
57
+ end
58
+
53
59
  body_html = render(document)
54
60
 
55
61
  if options[:layout] == :spa
@@ -73,33 +79,21 @@ module Coradoc
73
79
 
74
80
  private
75
81
 
76
- def build_toc(_document, options)
77
- TocBuilder.from_options(options)
78
- end
79
-
80
- def compute_section_numbers(document, options)
81
- if options[:section_numbers] && document.is_a?(CoreModel::StructuralElement)
82
- build_toc(document, options).section_number_map(document)
83
- else
84
- {}
85
- end
86
- end
87
-
88
- def render_toc_for(document, options)
89
- toc = build_toc(document, options).build(document)
90
- render(toc)
91
- end
92
-
93
82
  def render_static_layout(document, body_html, options)
94
- if options[:toc] && document.is_a?(CoreModel::StructuralElement)
95
- toc_html = render_toc_for(document, options)
83
+ if options[:toc] && @toc
84
+ toc_html = render(@toc)
96
85
  body_html = "#{toc_html}\n#{body_html}" unless toc_html.empty?
97
86
  end
98
87
  @layout_renderer.render_static(document, body_html, options)
99
88
  end
100
89
 
101
90
  def render_spa_layout(document, body_html, options)
102
- toc_data = TocSerializer.new.build_json(document, options)
91
+ numbered = options[:section_numbers] == true
92
+ toc_data = if @toc
93
+ { entries: TocSerializer.new.serialize_entries(@toc.entries), numbered: numbered }
94
+ else
95
+ { entries: [], numbered: false }
96
+ end
103
97
  @layout_renderer.render_spa(document, options, body_html, toc_data)
104
98
  end
105
99
 
@@ -123,11 +117,12 @@ module Coradoc
123
117
  resolved = TitleText.resolve(drop.model)
124
118
  text = resolved ? Escape.escape_html(resolved) : ''
125
119
 
126
- doc = Nokogiri::HTML::Document.new
127
- fragment = Nokogiri::HTML::Builder.with(doc) do |builder|
128
- builder.div(class: "element element-#{type}") { builder.text text }
129
- end
130
- fragment.at_css('div').to_html
120
+ fragment = Nokogiri::HTML.fragment
121
+ div = Nokogiri::XML::Node.new('div', fragment.document)
122
+ div['class'] = "element element-#{type}"
123
+ div.content = text
124
+ fragment.add_child(div)
125
+ fragment.to_html
131
126
  end
132
127
 
133
128
  def normalize_dirs(dirs)
@@ -31,31 +31,31 @@ module Coradoc
31
31
  # @param document [CoreModel::StructuralElement] the root document
32
32
  # @return [CoreModel::Toc] the built TOC with entries and section numbers
33
33
  def build(document)
34
- entries = []
35
- counters = [0]
36
- collect_entries(document.children, entries, 1, counters) if document.children
37
-
38
- CoreModel::Toc.new(
39
- entries: entries,
40
- min_level: 1,
41
- max_level: @max_level,
42
- numbered: @numbered
43
- )
34
+ toc, = build_with_numbers(document)
35
+ toc
44
36
  end
45
37
 
46
- # Compute a mapping of section_id => section_number_string.
47
- # Always computes numbers regardless of the +numbered+ flag,
48
- # since this is used for heading annotation in the body.
38
+ # Build TOC and section number map in a single tree walk.
49
39
  #
50
40
  # @param document [CoreModel::StructuralElement] the root document
51
- # @return [Hash{String => String}] mapping of section ID to number (e.g., "2.1")
52
- def section_number_map(document)
53
- map = {}
41
+ # @return [Array(CoreModel::Toc, Hash)] tuple of TOC model and section number map
42
+ def build_with_numbers(document)
54
43
  entries = []
55
44
  counters = [0]
56
45
  collect_entries(document.children, entries, 1, counters, always_number: true) if document.children
46
+
47
+ map = {}
57
48
  flatten_numbers(entries, map)
58
- map
49
+
50
+ strip_numbers(entries) unless @numbered
51
+
52
+ toc = CoreModel::Toc.new(
53
+ entries: entries,
54
+ min_level: 1,
55
+ max_level: @max_level,
56
+ numbered: @numbered
57
+ )
58
+ [toc, map]
59
59
  end
60
60
 
61
61
  private
@@ -93,6 +93,13 @@ module Coradoc
93
93
  end
94
94
  end
95
95
 
96
+ def strip_numbers(entries)
97
+ entries.each do |entry|
98
+ entry.number = nil
99
+ strip_numbers(entry.children) if entry.children
100
+ end
101
+ end
102
+
96
103
  def entry_title(section)
97
104
  TitleText.resolve(section.title)
98
105
  end
@@ -15,8 +15,6 @@ module Coradoc
15
15
  { entries: serialize_entries(toc.entries), numbered: numbered }
16
16
  end
17
17
 
18
- private
19
-
20
18
  def serialize_entries(entries)
21
19
  entries.map do |entry|
22
20
  {
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Coradoc
4
4
  module Html
5
- VERSION = '1.1.13'
5
+ VERSION = '1.1.14'
6
6
  end
7
7
  end
data/lib/coradoc/html.rb CHANGED
@@ -26,11 +26,8 @@ module Coradoc
26
26
  autoload :TemplateCaching, 'coradoc/html/template_caching'
27
27
  autoload :TitleText, 'coradoc/html/title_text'
28
28
 
29
- # Autoload Drop namespace (DropFactory loads Base + all drops)
30
- module Drop
31
- autoload :DropFactory, 'coradoc/html/drop/drop_factory'
32
- autoload :Base, 'coradoc/html/drop/base'
33
- end
29
+ # Drop layer self-registering drops loaded via parent namespace file
30
+ require 'coradoc/html/drop'
34
31
 
35
32
  # Autoload HTML output converters
36
33
  autoload :ConverterBase, 'coradoc/html/converter_base'
@@ -42,7 +39,8 @@ module Coradoc
42
39
  autoload :Theme, 'coradoc/html/theme'
43
40
  autoload :TemplateLocator, 'coradoc/html/template_locator'
44
41
  autoload :TemplateConfig, 'coradoc/html/template_config'
45
- autoload :TemplateFilters, 'coradoc/html/template_helpers'
42
+ # Side-effect: registers Liquid filters on load
43
+ require 'coradoc/html/template_helpers'
46
44
  autoload :Renderer, 'coradoc/html/renderer'
47
45
  autoload :LayoutRenderer, 'coradoc/html/layout_renderer'
48
46
  autoload :TocSerializer, 'coradoc/html/toc_serializer'
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.13
4
+ version: 1.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -119,6 +119,7 @@ files:
119
119
  - lib/coradoc/html.rb
120
120
  - lib/coradoc/html/config.rb
121
121
  - lib/coradoc/html/converter_base.rb
122
+ - lib/coradoc/html/drop.rb
122
123
  - lib/coradoc/html/drop/annotation_drop.rb
123
124
  - lib/coradoc/html/drop/base.rb
124
125
  - lib/coradoc/html/drop/bibliography_drop.rb