weaver 0.9.9 → 0.9.10

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: f1fd8409e68051036b8d1f4744ab44b7370d22b8f407b504144587f63af10a20
4
- data.tar.gz: ac79870b5e8ef48d98d3e0d901c6c87719ac6096070e219d5ca3207fb3d45bb2
3
+ metadata.gz: 4303f00ba8bdc586f8634a5f88cab24bc63e6786d8ffc0fa6cddb9e2a92c9db0
4
+ data.tar.gz: 6b7f855c1edb7728a26dba236b3c6f0ecb6ac3cb132d26a550f0e369afa9f72f
5
5
  SHA512:
6
- metadata.gz: 8810e33d65bf2e81ff11ca83a48217952c7b275da326bbf4791c7416605fdf45ff6428b55816ebd9b0b4a1733f614479c07d79a281ca2f35d0c562f5263467c8
7
- data.tar.gz: b0427c0bc90823f6d57c8fa26f5d4ab19c5f314a13fe082e8c50284452e18cf748b014ab54b154d1b23991749b90526dd87e4615512a39e0348af3e35adc4288
6
+ metadata.gz: ae459746271b1ad28163cd2799bc4a7bdbd8a80c43c0dbabc946d78098090317697a45fe6f7bbba0dee2e97ce456db69817bf48d474cde7ef4451b4b8c18a847
7
+ data.tar.gz: 78a2565cde8e982cea6a8d029469a2545450b4f8a5fc0e6ddd6c766a78ee9dceea80a016d7dea027314944c883e72c8510aefc4a95342f6c002d094bc63b64a0
@@ -99,6 +99,29 @@ module Weaver
99
99
  @top_content = elem.generate
100
100
  end
101
101
 
102
+ MATH_MARKER = '$$$MATH$$$'
103
+
104
+ # MathJax is large and keeps fetching files as it runs, so only pages that
105
+ # actually contain math (see Elements#math) load it
106
+ def uses_math?
107
+ [@content, @top_content, @background.generate].any? { |html| html.to_s.include?(MATH_MARKER) }
108
+ end
109
+
110
+ def mathjax_scripts(mod)
111
+ return '' unless uses_math?
112
+
113
+ <<~MATHJAX
114
+ <script type="text/x-mathjax-config">
115
+ MathJax.Hub.Config({
116
+ asciimath2jax: {
117
+ delimiters: [['#{MATH_MARKER}','$$$ENDMATH$$$']]
118
+ }
119
+ });
120
+ </script>
121
+ <script src="#{mod}js/MathJax/MathJax.js?config=AM_HTMLorMML-full" async></script>
122
+ MATHJAX
123
+ end
124
+
102
125
  def generate_meta_tags
103
126
  content = ""
104
127
  @meta_tags.each do |x|
@@ -241,15 +264,7 @@ mixpanel.init("' + @global_settings[:mixpanel_token] + '");</script><!-- end Mix
241
264
  <script src="#{mod}js/bootstrap.min.js"></script>
242
265
  <script src="#{mod}js/plugins/metisMenu/jquery.metisMenu.js"></script>
243
266
  <script src="#{mod}js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
244
- <script type="text/x-mathjax-config">
245
- MathJax.Hub.Config({
246
- asciimath2jax: {
247
- delimiters: [['$$$MATH$$$','$$$ENDMATH$$$']]
248
- }
249
- });
250
- </script>
251
- <script src="#{mod}js/MathJax/MathJax.js?config=AM_HTMLorMML-full" async></script>
252
-
267
+ #{mathjax_scripts(mod)}
253
268
  #{extra_scripts}
254
269
 
255
270
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Weaver
4
- VERSION = '0.9.9'
4
+ VERSION = '0.9.10'
5
5
  end
data/spec/page_spec.rb CHANGED
@@ -15,4 +15,27 @@ describe Weaver::Page do
15
15
  it 'does not emit the non-standard contents attribute' do
16
16
  expect(html).not_to include('contents=')
17
17
  end
18
+
19
+ describe 'MathJax' do
20
+ def page_html(&block)
21
+ Weaver::EmptyPage.new('Title', { root: '/' }, {}, &block).generate(0)
22
+ end
23
+
24
+ it 'is left out of pages without math' do
25
+ html = page_html { p 'no maths here' }
26
+ expect(html).not_to include('MathJax')
27
+ end
28
+
29
+ it 'is loaded on pages that use math' do
30
+ html = page_html { math 'x^2 + y^2' }
31
+ expect(html).to include('$$$MATH$$$x^2 + y^2$$$ENDMATH$$$')
32
+ expect(html).to include('<script type="text/x-mathjax-config">')
33
+ expect(html).to include('js/MathJax/MathJax.js?config=AM_HTMLorMML-full')
34
+ end
35
+
36
+ it 'is loaded when math sits in a nested element' do
37
+ html = page_html { div { span { math '\\frac{1}{2}' } } }
38
+ expect(html).to include('js/MathJax/MathJax.js')
39
+ end
40
+ end
18
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weaver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Siaw
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-10-16 00:00:00.000000000 Z
11
+ date: 2026-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport