jekyll-katex 0.2.1 → 0.3.0

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: 3f8555cfba1bff00546aa0efe7d14400dceaa5ef15ef213b711b931be779e9e6
4
- data.tar.gz: d79b83fce0fce8b81493890c811b6c10963f104b561d6601649741a15ea54fbd
3
+ metadata.gz: e5f8bbfb06ad51bf7782cdad251226adc466b011e805786e4378ffcb1cfb1ab2
4
+ data.tar.gz: de2ef5092e27eb79891320b0aaa04f31adbe0b76118c09baa9cce59126e49e42
5
5
  SHA512:
6
- metadata.gz: 9ef2b92701cfe49965afc1bc40ab6df000dbf20d51454f3d7834fabd9da5d73f1622c0c432d54db1ba26e08963f02ff2229d1c7a1888e0bf7098b2d11b1f96fc
7
- data.tar.gz: 2307ffc5f8c2b24d46ed3dd180c0348fb17f2da9b5ff5122536d43154472356134573785ae6cef3d1495bac8557bcf7ce7c89cfe1bd7ad2b0dacf4c3e7f2ab78
6
+ metadata.gz: 4e434cb16965dd70fc3440b33d6a05f93d9b1db7bf2d5889ef9eb98a2fccc0c127419f3f58cd4b4e0fde9a7fd0400c7ec1bd8a89275f7b6d38df37434a65ccc6
7
+ data.tar.gz: 652891ab56be42eeaa49841d0eb3b4ff77a0b31bc2927837cd37cfd6221d70c83c0cd3badac31335d8c85a0b290e75295c8b6599e3b67e56c11677c0261c9e17
data/README.md CHANGED
@@ -53,6 +53,10 @@ katex:
53
53
 
54
54
  ## Usage
55
55
 
56
+ There are two liquid tags: `katex` and `katexmm`.
57
+
58
+ ### katex
59
+
56
60
  Use the `katex` liquid tag for LaTeX math equations like so:
57
61
 
58
62
  ```latex
@@ -69,6 +73,22 @@ c = \pm\sqrt{a^2 + b^2}
69
73
  {% endkatex %}
70
74
  ```
71
75
 
76
+ ### katexmm
77
+
78
+ The `katex` liquid tag can be cumbersome, particularly if you have many inline blocks, which would need to be opened
79
+ and closed repeatedly, cluttering the source text. `katexmm` is an alternative that supports fenced math mode blocks
80
+ similar to standard latex:
81
+
82
+ ```latex
83
+ {% katexmm %}
84
+ This is a mixed environment where you can have text and normal text and $c = \pm\sqrt{a^2 + b^2}$ fenced math. \$!
85
+ {% endkatexmm %}
86
+ ```
87
+
88
+ * `$` for inline
89
+ * `$$` for display mode
90
+ * `\$` to escape `$` anywhere within the `katexmm` environment
91
+
72
92
  ## Development
73
93
 
74
94
  ```bash
data/gems.locked CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-katex (0.2.0)
4
+ jekyll-katex (0.3.0)
5
5
  execjs (~> 2.7)
6
6
  jekyll (~> 3.8)
7
7
 
@@ -25,7 +25,7 @@ GEM
25
25
  http_parser.rb (0.6.0)
26
26
  i18n (0.9.5)
27
27
  concurrent-ruby (~> 1.0)
28
- jekyll (3.8.3)
28
+ jekyll (3.8.4)
29
29
  addressable (~> 2.4)
30
30
  colorator (~> 1.0)
31
31
  em-websocket (~> 0.5)
@@ -51,31 +51,31 @@ GEM
51
51
  ruby_dep (~> 1.2)
52
52
  mercenary (0.3.6)
53
53
  parallel (1.12.1)
54
- parser (2.5.1.0)
54
+ parser (2.5.1.2)
55
55
  ast (~> 2.4.0)
56
56
  pathutil (0.16.1)
57
57
  forwardable-extended (~> 2.6)
58
- powerpack (0.1.1)
59
- public_suffix (3.0.2)
58
+ powerpack (0.1.2)
59
+ public_suffix (3.0.3)
60
60
  rainbow (3.0.0)
61
61
  rake (12.3.1)
62
62
  rb-fsevent (0.10.3)
63
63
  rb-inotify (0.9.10)
64
64
  ffi (>= 0.5.0, < 2)
65
- rouge (3.1.1)
66
- rspec (3.7.0)
67
- rspec-core (~> 3.7.0)
68
- rspec-expectations (~> 3.7.0)
69
- rspec-mocks (~> 3.7.0)
70
- rspec-core (3.7.1)
71
- rspec-support (~> 3.7.0)
72
- rspec-expectations (3.7.0)
65
+ rouge (3.2.1)
66
+ rspec (3.8.0)
67
+ rspec-core (~> 3.8.0)
68
+ rspec-expectations (~> 3.8.0)
69
+ rspec-mocks (~> 3.8.0)
70
+ rspec-core (3.8.0)
71
+ rspec-support (~> 3.8.0)
72
+ rspec-expectations (3.8.1)
73
73
  diff-lcs (>= 1.2.0, < 2.0)
74
- rspec-support (~> 3.7.0)
75
- rspec-mocks (3.7.0)
74
+ rspec-support (~> 3.8.0)
75
+ rspec-mocks (3.8.0)
76
76
  diff-lcs (>= 1.2.0, < 2.0)
77
- rspec-support (~> 3.7.0)
78
- rspec-support (3.7.1)
77
+ rspec-support (~> 3.8.0)
78
+ rspec-support (3.8.0)
79
79
  rubocop (0.56.0)
80
80
  parallel (~> 1.10)
81
81
  parser (>= 2.5)
@@ -83,10 +83,10 @@ GEM
83
83
  rainbow (>= 2.2.2, < 4.0)
84
84
  ruby-progressbar (~> 1.7)
85
85
  unicode-display_width (~> 1.0, >= 1.0.1)
86
- ruby-progressbar (1.9.0)
86
+ ruby-progressbar (1.10.0)
87
87
  ruby_dep (1.5.0)
88
88
  safe_yaml (1.0.4)
89
- sass (3.5.6)
89
+ sass (3.6.0)
90
90
  sass-listen (~> 4.0.0)
91
91
  sass-listen (4.0.0)
92
92
  rb-fsevent (~> 0.9, >= 0.9.4)
@@ -110,4 +110,4 @@ DEPENDENCIES
110
110
  simplecov (~> 0.16)
111
111
 
112
112
  BUNDLED WITH
113
- 1.16.2
113
+ 1.16.3
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'execjs'
4
3
  require 'jekyll-katex/configuration'
4
+ require 'jekyll-katex/katex_js'
5
5
 
6
6
  module Jekyll
7
7
  module Tags
@@ -11,7 +11,7 @@ module Jekyll
11
11
  # {% endkatex %}
12
12
  class Katex < Liquid::Block
13
13
  LOG_TOPIC = 'Katex Block:'
14
- KATEX ||= ExecJS.compile(File.open(Jekyll::Katex::Configuration.js_path).read)
14
+ KATEX ||= Jekyll::Katex::KATEX_JS
15
15
 
16
16
  def initialize(tag_name, markup, tokens)
17
17
  super
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll-katex/configuration'
4
+ require 'jekyll-katex/katex_js'
5
+
6
+ module Jekyll
7
+ module Tags
8
+ # Defines the custom Liquid tag for compile-time rendering of KaTeX math.
9
+ # This differs from the katex tag in that it allows use of `$` and `$$` fencing to mark math mode blocks similar to
10
+ # standard latex.
11
+ # {% katexmm %}
12
+ # This is a mixed environment where you can write text as normal but fence off latex math using `$`. Escape
13
+ # using `\$`. For example.
14
+ # $latex math with \$$
15
+ # $$display mode latex$$
16
+ # {% endkatexmm %}
17
+ class KatexMathMode < Liquid::Block
18
+ LOG_TOPIC = 'KatexMathMode:'
19
+ KATEX ||= Jekyll::Katex::KATEX_JS
20
+ LATEX_TOKEN_PATTERN = /(?<!\\)([$]{2}|[$]{1})(.+?)(?<!\\)\1/m
21
+
22
+ def initialize(tag_name, markup, tokens)
23
+ super
24
+ @markup = markup
25
+ @tokens = tokens
26
+ @display_mode_rendering = Jekyll::Katex::Configuration.global_rendering_options.merge(displayMode: true)
27
+ @inline_mode_rendering = Jekyll::Katex::Configuration.global_rendering_options.merge(displayMode: false)
28
+ end
29
+
30
+ def render(context)
31
+ enclosed_block = super
32
+ rendered_str = enclosed_block.to_s.gsub(LATEX_TOKEN_PATTERN) do |match|
33
+ display_mode = match.to_s.start_with? '$$'
34
+ rendering_options = display_mode ? @display_mode_rendering : @inline_mode_rendering
35
+ Jekyll.logger.debug LOG_TOPIC, "Rendering matched block - #{match}"
36
+ KATEX.call('katex.renderToString', Regexp.last_match(2), rendering_options)
37
+ end
38
+ # KaTeX should fix escaped `$` within fenced blocks, this addresses instances outside of math mode
39
+ rendered_str.to_s.gsub(/\\[$]/, '$').to_s
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'jekyll'
4
+ require 'jekyll-katex/lib_root'
4
5
 
5
6
  module Jekyll
6
7
  module Katex
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'execjs'
4
+ require 'jekyll-katex/configuration'
5
+
6
+ # Holds reference to the katex.min.js lib
7
+ module Jekyll
8
+ # Katex fast math rendering, see https://github.com/Khan/KaTeX
9
+ module Katex
10
+ KATEX_JS ||= ExecJS.compile(File.open(Jekyll::Katex::Configuration.js_path).read)
11
+ end
12
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Katex
5
- VERSION = '0.2.1'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
data/lib/jekyll-katex.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'jekyll'
4
-
5
- require 'jekyll-katex/version'
6
- require 'jekyll-katex/lib_root'
7
4
  require 'jekyll/tags/katex'
5
+ require 'jekyll/tags/katex_math_mode'
8
6
 
9
7
  Liquid::Template.register_tag('katex', Jekyll::Tags::Katex)
8
+ Liquid::Template.register_tag('katexmm', Jekyll::Tags::KatexMathMode)
data/yarn.lock CHANGED
@@ -5,9 +5,11 @@
5
5
  katex@^0.9.0:
6
6
  version "0.9.0"
7
7
  resolved "https://registry.yarnpkg.com/katex/-/katex-0.9.0.tgz#26a7d082c21d53725422d2d71da9b2d8455fbd4a"
8
+ integrity sha512-lp3x90LT1tDZBW2tjLheJ98wmRMRjUHwk4QpaswT9bhqoQZ+XA4cPcjcQBxgOQNwaOSt6ZeL/a6GKQ1of3LFxQ==
8
9
  dependencies:
9
10
  match-at "^0.1.1"
10
11
 
11
12
  match-at@^0.1.1:
12
13
  version "0.1.1"
13
14
  resolved "https://registry.yarnpkg.com/match-at/-/match-at-0.1.1.tgz#25d040d291777704d5e6556bbb79230ec2de0540"
15
+ integrity sha512-h4Yd392z9mST+dzc+yjuybOGFNOZjmXIPKWjxBd1Bb23r4SmDOsk2NYCU2BMUBGbSpZqwVsZYNq26QS3xfaT3Q==
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-katex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerry Lin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-01 00:00:00.000000000 Z
11
+ date: 2018-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -129,9 +129,11 @@ files:
129
129
  - lib/assets/js/katex.min.js
130
130
  - lib/jekyll-katex.rb
131
131
  - lib/jekyll-katex/configuration.rb
132
+ - lib/jekyll-katex/katex_js.rb
132
133
  - lib/jekyll-katex/lib_root.rb
133
134
  - lib/jekyll-katex/version.rb
134
135
  - lib/jekyll/tags/katex.rb
136
+ - lib/jekyll/tags/katex_math_mode.rb
135
137
  - package.json
136
138
  - yarn.lock
137
139
  homepage: https://github.com/linjer/jekyll-katex