coradoc-html 1.1.14 → 1.1.15
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/asset_resolver.rb +193 -0
- data/lib/coradoc/html/config.rb +18 -358
- data/lib/coradoc/html/converter_base.rb +41 -2
- data/lib/coradoc/html/drop/block_drop.rb +2 -13
- data/lib/coradoc/html/drop/inline_element_drop.rb +1 -20
- data/lib/coradoc/html/drop/list_block_drop.rb +1 -5
- data/lib/coradoc/html/drop/table_cell_drop.rb +1 -1
- data/lib/coradoc/html/layout_renderer.rb +38 -36
- data/lib/coradoc/html/render_options.rb +40 -0
- data/lib/coradoc/html/renderer.rb +12 -11
- data/lib/coradoc/html/spa.rb +8 -25
- data/lib/coradoc/html/static.rb +11 -36
- data/lib/coradoc/html/tag_mapping.rb +104 -0
- data/lib/coradoc/html/toc_builder.rb +5 -4
- data/lib/coradoc/html/toc_serializer.rb +4 -3
- data/lib/coradoc/html/transform/from_core_model.rb +2 -0
- data/lib/coradoc/html/transform/to_core_model.rb +2 -0
- data/lib/coradoc/html/version.rb +1 -1
- data/lib/coradoc/html.rb +3 -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: c53a89e3da72cb478d6debd077616fd21ffe9b733b4c3b723d11fc5b7eec7456
|
|
4
|
+
data.tar.gz: 905368b78f848476bfe07f72036b787415758852ccd23be0edc873524b895875
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0db9761c8aba4af684d545f37397179c31ea7234c32677ef55034dcc7efc3dcf730157566914c50663c75cd94a963a1c6a836c078ce2df12f103d2123d450628
|
|
7
|
+
data.tar.gz: f553cdb6793c1a2a0693a7ccb345830548a7f27e438abc48b171ecdda4931c28a081dc0d7e776e822a0f42b37471d8053c6fb58b0a2292b634f3299c44cae92d
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'nokogiri'
|
|
4
|
+
|
|
5
|
+
module Coradoc
|
|
6
|
+
module Html
|
|
7
|
+
module AssetResolver
|
|
8
|
+
class << self
|
|
9
|
+
def stylesheet_path(options = {})
|
|
10
|
+
css_theme = options[:css_theme] || Config::DEFAULT_OPTIONS[:css_theme]
|
|
11
|
+
stylesheet = "#{css_theme}.css"
|
|
12
|
+
stylesdir = options[:stylesdir] || Config::DEFAULT_OPTIONS[:stylesdir]
|
|
13
|
+
|
|
14
|
+
if stylesdir && stylesdir != '.'
|
|
15
|
+
File.join(stylesdir, stylesheet)
|
|
16
|
+
else
|
|
17
|
+
stylesheet
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def embedded_stylesheet(options = {})
|
|
22
|
+
css_theme = options[:css_theme] || Config::DEFAULT_OPTIONS[:css_theme]
|
|
23
|
+
stylesheet_name = "#{css_theme}.css"
|
|
24
|
+
|
|
25
|
+
themes_path = File.join(__dir__, 'assets', 'themes', stylesheet_name)
|
|
26
|
+
asset_path = if File.exist?(themes_path)
|
|
27
|
+
themes_path
|
|
28
|
+
else
|
|
29
|
+
File.join(__dir__, 'assets', stylesheet_name)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
css_content = if File.exist?(asset_path)
|
|
33
|
+
File.read(asset_path)
|
|
34
|
+
else
|
|
35
|
+
default_path = File.join(__dir__, 'assets', 'coradoc.css')
|
|
36
|
+
File.exist?(default_path) ? File.read(default_path) : ''
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
resolve_css_imports(css_content, File.dirname(asset_path))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def resolve_css_imports(css_content, base_dir)
|
|
43
|
+
css_content.gsub(/@import\s+(?:url\()?['"]([^'"]+)['"]\)?;?/) do
|
|
44
|
+
import_path = ::Regexp.last_match(1)
|
|
45
|
+
full_path = File.join(base_dir, import_path)
|
|
46
|
+
|
|
47
|
+
if File.exist?(full_path)
|
|
48
|
+
imported_content = File.read(full_path)
|
|
49
|
+
resolve_css_imports(imported_content, File.dirname(full_path))
|
|
50
|
+
else
|
|
51
|
+
::Regexp.last_match(0)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def css_link_tag(options = {})
|
|
57
|
+
href = stylesheet_path(options)
|
|
58
|
+
doc = Nokogiri::HTML::Document.new
|
|
59
|
+
node = Nokogiri::XML::Node.new('link', doc)
|
|
60
|
+
node['rel'] = 'stylesheet'
|
|
61
|
+
node['href'] = href
|
|
62
|
+
node.to_html
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def css_style_tag(options = {})
|
|
66
|
+
css_content = embedded_stylesheet(options)
|
|
67
|
+
custom_css = options[:custom_css]
|
|
68
|
+
|
|
69
|
+
content = css_content
|
|
70
|
+
content += "\n\n#{custom_css}" if custom_css && !custom_css.empty?
|
|
71
|
+
|
|
72
|
+
build_text_element('style', content)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def custom_css_tag(custom_css)
|
|
76
|
+
return '' unless custom_css && !custom_css.empty?
|
|
77
|
+
|
|
78
|
+
build_text_element('style', custom_css)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def embed_css?(options = {})
|
|
82
|
+
!options.fetch(:linkcss, Config::DEFAULT_OPTIONS[:linkcss]) ||
|
|
83
|
+
options.fetch(:embedded, Config::DEFAULT_OPTIONS[:embedded])
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def css_tags(options = {})
|
|
87
|
+
tags = []
|
|
88
|
+
|
|
89
|
+
if embed_css?(options)
|
|
90
|
+
tags << css_style_tag(options)
|
|
91
|
+
else
|
|
92
|
+
tags << css_link_tag(options)
|
|
93
|
+
tags << custom_css_tag(options[:custom_css]) if options[:custom_css]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
tags.join("\n")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def embed_js?(options = {})
|
|
100
|
+
!options.fetch(:linkjs, Config::DEFAULT_OPTIONS[:linkjs]) ||
|
|
101
|
+
options.fetch(:embedded, Config::DEFAULT_OPTIONS[:embedded]) ||
|
|
102
|
+
!options.fetch(:linkcss, Config::DEFAULT_OPTIONS[:linkcss])
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def javascript_path(options = {})
|
|
106
|
+
javascript = options[:javascript] || Config::DEFAULT_OPTIONS[:javascript]
|
|
107
|
+
jsdir = options[:jsdir] || Config::DEFAULT_OPTIONS[:jsdir]
|
|
108
|
+
|
|
109
|
+
if jsdir && jsdir != '.'
|
|
110
|
+
File.join(jsdir, javascript)
|
|
111
|
+
else
|
|
112
|
+
javascript
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def embedded_javascript(options = {})
|
|
117
|
+
javascript_name = options[:javascript] || Config::DEFAULT_OPTIONS[:javascript]
|
|
118
|
+
asset_path = File.join(__dir__, 'assets', 'js', javascript_name)
|
|
119
|
+
|
|
120
|
+
File.exist?(asset_path) ? File.read(asset_path) : ''
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def js_link_tag(options = {})
|
|
124
|
+
src = javascript_path(options)
|
|
125
|
+
doc = Nokogiri::HTML::Document.new
|
|
126
|
+
node = Nokogiri::XML::Node.new('script', doc)
|
|
127
|
+
node['src'] = src
|
|
128
|
+
node['defer'] = ''
|
|
129
|
+
node.to_html
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def js_script_tag(options = {})
|
|
133
|
+
js_content = embedded_javascript(options)
|
|
134
|
+
return '' if js_content.empty?
|
|
135
|
+
|
|
136
|
+
build_text_element('script', js_content)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def js_tags(options = {})
|
|
140
|
+
return '' if options[:javascript] == false
|
|
141
|
+
|
|
142
|
+
tags = []
|
|
143
|
+
|
|
144
|
+
tags << if embed_js?(options)
|
|
145
|
+
js_script_tag(options)
|
|
146
|
+
else
|
|
147
|
+
js_link_tag(options)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
tags.join("\n")
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def syntax_highlighter_tags(options = {})
|
|
154
|
+
highlighter = options[:source_highlighter]
|
|
155
|
+
return '' unless highlighter
|
|
156
|
+
|
|
157
|
+
case highlighter.to_sym
|
|
158
|
+
when :highlightjs, :highlight_js, :'highlight.js'
|
|
159
|
+
highlightjs_tags(options)
|
|
160
|
+
else
|
|
161
|
+
''
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def highlightjs_tags(options = {})
|
|
166
|
+
theme = options[:highlightjs_theme] || Config::DEFAULT_OPTIONS[:highlightjs_theme]
|
|
167
|
+
doc = Nokogiri::HTML::Document.new
|
|
168
|
+
|
|
169
|
+
link_node = Nokogiri::XML::Node.new('link', doc)
|
|
170
|
+
link_node['rel'] = 'stylesheet'
|
|
171
|
+
link_node['href'] = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/#{theme}.min.css"
|
|
172
|
+
|
|
173
|
+
script_node = Nokogiri::XML::Node.new('script', doc)
|
|
174
|
+
script_node['src'] = 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js'
|
|
175
|
+
|
|
176
|
+
init_node = Nokogiri::XML::Node.new('script', doc)
|
|
177
|
+
init_node.content = 'hljs.highlightAll();'
|
|
178
|
+
|
|
179
|
+
[link_node.to_html, script_node.to_html, init_node.to_html].join("\n")
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
private
|
|
183
|
+
|
|
184
|
+
def build_text_element(tag_name, content)
|
|
185
|
+
doc = Nokogiri::HTML::Document.new
|
|
186
|
+
node = Nokogiri::XML::Node.new(tag_name, doc)
|
|
187
|
+
node.content = content
|
|
188
|
+
node.to_html
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|