thredded-markdown_katex 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/generators/thredded/markdown_katex/install_generator.rb +4 -2
- data/lib/thredded/markdown_katex/demo.md +19 -0
- data/lib/thredded/markdown_katex/email_transformer.rb +19 -0
- data/lib/thredded/markdown_katex/kramdown/katex_converter.rb +1 -0
- data/lib/thredded/markdown_katex/mathml_whitelist.rb +1 -0
- data/lib/thredded/markdown_katex/railtie.rb +1 -0
- data/lib/thredded/markdown_katex/version.rb +2 -1
- data/lib/thredded/markdown_katex.rb +10 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcfb6aeece4696f4f76012adaf93f88e8e8839da
|
4
|
+
data.tar.gz: b2ca950bd98eb68f02159ccb869d3aae0594c333
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4f5a99451b15b93cee120050dbfae9b1a0abec0ea3b9484480ef0a4127d19bfea962dd9a3e71ce5ce07d5ce11d7eb0a1684aca7708c3ad392ceabb98cf3cd1f
|
7
|
+
data.tar.gz: ea2a32af10928ae268c1ef9f17831949d68f7637ade2905acd5d789d9dac44a3103c45082a82543443294d0fe1f1a0f79896a15f6328d82664056f52446d8b94
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Thredded
|
3
4
|
module MarkdownKatex
|
4
5
|
# Installs Thredded Katex plugin
|
@@ -7,8 +8,9 @@ module Thredded
|
|
7
8
|
public_task :install
|
8
9
|
|
9
10
|
def install # rubocop:disable Metrics/MethodLength
|
10
|
-
|
11
|
-
|
11
|
+
%w(application.scss _deps.scss).each do |scss_file|
|
12
|
+
scss_path = File.join('app', 'assets', 'stylesheets', scss_file)
|
13
|
+
next unless File.exist? scss_path
|
12
14
|
append_to_file scss_path, "\n" + '@import "_katex";' + "\n"
|
13
15
|
end
|
14
16
|
sass_path = 'app/assets/stylesheets/application.sass'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#### Math
|
2
|
+
|
3
|
+
$$f(n) = \begin{cases}
|
4
|
+
\frac{n}{2}, & \text{if } n \text{ is even} \\
|
5
|
+
3n+1, & \text{if } n \text{ is odd}
|
6
|
+
\end{cases}
|
7
|
+
$$
|
8
|
+
|
9
|
+
The code for the example above is:
|
10
|
+
|
11
|
+
```
|
12
|
+
$$f(n) = \begin{cases}
|
13
|
+
\frac{n}{2}, & \text{if } n \text{ is even} \\
|
14
|
+
3n+1, & \text{if } n \text{ is odd}
|
15
|
+
\end{cases}
|
16
|
+
$$
|
17
|
+
```
|
18
|
+
|
19
|
+
Both inline and display modes are [supported](https://kramdown.gettalong.org/syntax.html#math-blocks). Powered by [KaTeX](https://github.com/Khan/KaTeX).
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thredded/email_transformer/base'
|
4
|
+
module Thredded
|
5
|
+
module MarkdownKatex
|
6
|
+
# Replaces Katex blocks with their `<math>` content and makes them visible,
|
7
|
+
# because most email clients do not support webfonts, and webfonts are
|
8
|
+
# required for the non-`<math>` version.
|
9
|
+
class EmailTransformer < Thredded::EmailTransformer::Base
|
10
|
+
def call
|
11
|
+
doc.css('.katex').each do |katex|
|
12
|
+
math = katex.at('math')
|
13
|
+
math.remove_attribute('class')
|
14
|
+
katex.swap math
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'thredded/markdown_katex/version'
|
3
4
|
require 'katex'
|
4
5
|
require 'thredded/markdown_katex/railtie' if defined?(Rails)
|
5
6
|
require 'thredded/markdown_katex/mathml_whitelist'
|
7
|
+
require 'thredded/markdown_katex/email_transformer'
|
6
8
|
|
7
9
|
module Thredded
|
8
10
|
# Adds TeX math support to Thredded markdown via KaTeX.
|
@@ -17,7 +19,7 @@ module Thredded
|
|
17
19
|
class << self
|
18
20
|
attr_reader :options
|
19
21
|
|
20
|
-
def setup!
|
22
|
+
def setup! # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
21
23
|
if pipeline_contains?(KRAMDOWN_FILTER_CLASS_NAME)
|
22
24
|
require 'thredded/markdown_katex/kramdown/katex_converter'
|
23
25
|
Thredded::HtmlPipeline::KramdownFilter.options.update(options)
|
@@ -27,6 +29,13 @@ module Thredded
|
|
27
29
|
end
|
28
30
|
|
29
31
|
configure_whitelist!
|
32
|
+
|
33
|
+
Thredded::EmailTransformer.transformers <<
|
34
|
+
Thredded::MarkdownKatex::EmailTransformer
|
35
|
+
|
36
|
+
Thredded::FormattingDemoContent.parts.unshift File.read(
|
37
|
+
File.join(File.dirname(__FILE__), 'markdown_katex', 'demo.md')
|
38
|
+
)
|
30
39
|
end
|
31
40
|
|
32
41
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thredded-markdown_katex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gleb Mazovetskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: katex
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.11.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.11.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,6 +119,8 @@ files:
|
|
119
119
|
- README.md
|
120
120
|
- lib/generators/thredded/markdown_katex/install_generator.rb
|
121
121
|
- lib/thredded/markdown_katex.rb
|
122
|
+
- lib/thredded/markdown_katex/demo.md
|
123
|
+
- lib/thredded/markdown_katex/email_transformer.rb
|
122
124
|
- lib/thredded/markdown_katex/kramdown/katex_converter.rb
|
123
125
|
- lib/thredded/markdown_katex/mathml_whitelist.rb
|
124
126
|
- lib/thredded/markdown_katex/railtie.rb
|
@@ -143,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
145
|
version: '0'
|
144
146
|
requirements: []
|
145
147
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.6.
|
148
|
+
rubygems_version: 2.6.11
|
147
149
|
signing_key:
|
148
150
|
specification_version: 4
|
149
151
|
summary: Adds TeX math support to Thredded markup via KaTeX.
|