thredded-markdown_katex 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/thredded/markdown_katex/install_generator.rb +1 -1
- data/lib/thredded/markdown_katex.rb +16 -5
- data/lib/thredded/markdown_katex/mathml_whitelist.rb +50 -50
- data/lib/thredded/markdown_katex/svg_whitelist.rb +64 -0
- data/lib/thredded/markdown_katex/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4049c976b9da68b8a080bcf3ddb6356cb4de8168
|
4
|
+
data.tar.gz: 7c3d7083093f31e7a56b26175e429c4d41e65a63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a07a5b670d90505c618a973270a0a1ae57c5f35ae468dc129dd2d65cc3a00232927e13041aa28e7f13022c8c5ff54dd3edeacf17caa86507beb7948d3492e88
|
7
|
+
data.tar.gz: a4e06c91dad0ba06ff9261dc887ba1dee7ca83ed10d0db2a30db3583a84196597d02b44c5e6370d67fc0e3abe93d6344f9fb80ee812c3ab86d271a70420e59b6
|
@@ -8,7 +8,7 @@ module Thredded
|
|
8
8
|
public_task :install
|
9
9
|
|
10
10
|
def install # rubocop:disable Metrics/MethodLength
|
11
|
-
%w
|
11
|
+
%w[application.scss _deps.scss].each do |scss_file|
|
12
12
|
scss_path = File.join('app', 'assets', 'stylesheets', scss_file)
|
13
13
|
next unless File.exist? scss_path
|
14
14
|
append_to_file scss_path, "\n" + '@import "_katex";' + "\n"
|
@@ -4,6 +4,7 @@ require 'thredded/markdown_katex/version'
|
|
4
4
|
require 'katex'
|
5
5
|
require 'thredded/markdown_katex/railtie' if defined?(Rails)
|
6
6
|
require 'thredded/markdown_katex/mathml_whitelist'
|
7
|
+
require 'thredded/markdown_katex/svg_whitelist'
|
7
8
|
require 'thredded/markdown_katex/email_transformer'
|
8
9
|
|
9
10
|
module Thredded
|
@@ -47,16 +48,17 @@ module Thredded
|
|
47
48
|
def configure_whitelist!
|
48
49
|
whitelist_katex_html!
|
49
50
|
whitelist_mathml!
|
51
|
+
whitelist_svg!
|
50
52
|
end
|
51
53
|
|
52
54
|
def whitelist_katex_html!
|
53
|
-
whitelist_element! 'span', %w
|
55
|
+
whitelist_element! 'span', %w[class style aria-hidden]
|
54
56
|
Thredded::ContentFormatter.whitelist[:css] ||= {}
|
55
57
|
Thredded::ContentFormatter.whitelist[:css][:properties] ||= []
|
56
|
-
Thredded::ContentFormatter.whitelist[:css][:properties] += %w
|
57
|
-
color
|
58
|
-
top
|
59
|
-
|
58
|
+
Thredded::ContentFormatter.whitelist[:css][:properties] += %w[
|
59
|
+
background-color border-color color width min-width height min-height
|
60
|
+
vertical-align margin-left margin-right font-size top
|
61
|
+
]
|
60
62
|
end
|
61
63
|
|
62
64
|
def whitelist_mathml!
|
@@ -70,6 +72,15 @@ module Thredded
|
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
75
|
+
def whitelist_svg!
|
76
|
+
attrs = SVGWhitelist::SVG_ATTRIBUTES.map(&:downcase)
|
77
|
+
SVGWhitelist::SVG_ELEMENTS.each do |tag|
|
78
|
+
whitelist_element! tag, attrs
|
79
|
+
end
|
80
|
+
Thredded::ContentFormatter.whitelist[:css][:properties] +=
|
81
|
+
SVGWhitelist::SVG_ALLOWED_STYLE_PROPERTIES
|
82
|
+
end
|
83
|
+
|
73
84
|
def whitelist_element!(tag, attributes)
|
74
85
|
whitelist_el = Thredded::ContentFormatter.whitelist[:elements]
|
75
86
|
whitelist_el << tag unless whitelist_el.include?(tag)
|
@@ -8,35 +8,35 @@ module Thredded
|
|
8
8
|
# https://www.w3.org/Math/draft-spec/appendixa.html
|
9
9
|
|
10
10
|
# Attributes common to all MathML elements
|
11
|
-
COMMON_ATT = %w
|
11
|
+
COMMON_ATT = %w[id xref class style href].freeze
|
12
12
|
# Attributes common to presentational elements
|
13
|
-
COMMON_PRES_ATT = %w
|
13
|
+
COMMON_PRES_ATT = %w[mathcolor mathbackground].freeze
|
14
14
|
# Attributes common to token elements
|
15
|
-
TOKEN_ATT = %w
|
15
|
+
TOKEN_ATT = %w[mathvariant mathsize dir].freeze
|
16
16
|
# Attributes common to elements that can be indented
|
17
|
-
INDENT_ATT = %w
|
17
|
+
INDENT_ATT = %w[
|
18
18
|
indentalign indentshift indenttarget indentalignfirst indentshiftfirst
|
19
19
|
indentalignlast indentshiftlast
|
20
|
-
|
20
|
+
].freeze
|
21
21
|
# Attributes common to definition elements
|
22
|
-
DEF_ENC_ATT = %w
|
22
|
+
DEF_ENC_ATT = %w[definitionURL encoding].freeze
|
23
23
|
|
24
24
|
# All of these elements have MATHML_COMMON_PRES_ATT.
|
25
25
|
PRESENTATION_WHITELIST = {
|
26
|
-
'maction' => %w
|
27
|
-
'menclose' => %w
|
28
|
-
'merror' => %w
|
29
|
-
'mfenced' => %w
|
26
|
+
'maction' => %w[actiontype selection],
|
27
|
+
'menclose' => %w[notation],
|
28
|
+
'merror' => %w[],
|
29
|
+
'mfenced' => %w[open close separators],
|
30
30
|
'mfrac' =>
|
31
|
-
%w
|
32
|
-
'mglyph' => %w
|
31
|
+
%w[bevelled denomalign linethickness numalign],
|
32
|
+
'mglyph' => %w[src width height valign alt],
|
33
33
|
'mpadded' =>
|
34
|
-
%w
|
35
|
-
'mphantom' => %w
|
36
|
-
'mroot' => %w
|
37
|
-
'mrow' => %w
|
38
|
-
'msqrt' => %w
|
39
|
-
'mstyle' => INDENT_ATT + %w
|
34
|
+
%w[height depth width lspace voffset],
|
35
|
+
'mphantom' => %w[],
|
36
|
+
'mroot' => %w[],
|
37
|
+
'mrow' => %w[dir],
|
38
|
+
'msqrt' => %w[],
|
39
|
+
'mstyle' => INDENT_ATT + %w[
|
40
40
|
scriptlevel displaystyle scriptsizemultiplier scriptminsize
|
41
41
|
infixlinebreakstyle decimalpoint accent accentunder align
|
42
42
|
alignmentscope bevelled charalign charspacing close columnalign
|
@@ -50,53 +50,53 @@ module Thredded
|
|
50
50
|
rowalign rowlines rowspacing rowspan rquote rspace selection
|
51
51
|
separator separators shift side stackalign stretchy
|
52
52
|
subscriptshift superscriptshift symmetric valign width
|
53
|
-
|
53
|
+
],
|
54
54
|
'mi' => TOKEN_ATT,
|
55
55
|
'mn' => TOKEN_ATT,
|
56
56
|
'mo' => TOKEN_ATT + INDENT_ATT +
|
57
|
-
%w
|
57
|
+
%w[form fence separator lspace rspace stretchy symmetric minsize
|
58
58
|
maxsize largeop movablelimits accent linebreak lineleading
|
59
|
-
linebreakstyle linebreakmultchar
|
60
|
-
'ms' => TOKEN_ATT + %w
|
59
|
+
linebreakstyle linebreakmultchar],
|
60
|
+
'ms' => TOKEN_ATT + %w[lquote rquote],
|
61
61
|
'mspace' => TOKEN_ATT + INDENT_ATT +
|
62
|
-
%w
|
62
|
+
%w[width height depth linebreak],
|
63
63
|
'mtext' => TOKEN_ATT,
|
64
|
-
'maligngroup' => %w
|
65
|
-
'malignmark' => %w
|
66
|
-
'mlabeledtr' => %w
|
67
|
-
'mtable' => %w
|
64
|
+
'maligngroup' => %w[groupalign],
|
65
|
+
'malignmark' => %w[edge],
|
66
|
+
'mlabeledtr' => %w[rowalign columnalign groupalign],
|
67
|
+
'mtable' => %w[
|
68
68
|
align rowalign columnalign groupalign alignmentscope columnwidth
|
69
69
|
width rowspacing columnspacing rowlines columnlines frame
|
70
70
|
framespacing equalrows equalcolumns displaystyle side
|
71
71
|
minlabelspacing
|
72
|
-
|
73
|
-
'mtd' => %w
|
74
|
-
'mtr' => %w
|
75
|
-
'mmultiscripts' => %w
|
76
|
-
'msub' => %w
|
77
|
-
'msup' => %w
|
78
|
-
'msubsup' => %w
|
79
|
-
'munder' => %w
|
80
|
-
'mover' => %w
|
81
|
-
'munderover' => %w
|
82
|
-
'mlongdiv' => %w
|
83
|
-
'mscarries' => %w
|
84
|
-
'mscarry' => %w
|
85
|
-
'msgroup' => %w
|
72
|
+
],
|
73
|
+
'mtd' => %w[rowspan columnspan rowalign columnalign groupalign],
|
74
|
+
'mtr' => %w[rowalign columnalign groupalign],
|
75
|
+
'mmultiscripts' => %w[superscriptshift subscriptshift],
|
76
|
+
'msub' => %w[subscriptshift],
|
77
|
+
'msup' => %w[superscriptshift],
|
78
|
+
'msubsup' => %w[superscriptshift subscriptshift],
|
79
|
+
'munder' => %w[accentunder align],
|
80
|
+
'mover' => %w[accent align],
|
81
|
+
'munderover' => %w[accent accentunder align],
|
82
|
+
'mlongdiv' => %w[position shift longdivstyle],
|
83
|
+
'mscarries' => %w[position location crossout scriptsizemultiplier],
|
84
|
+
'mscarry' => %w[location crossout],
|
85
|
+
'msgroup' => %w[position shift],
|
86
86
|
'msline' =>
|
87
|
-
%w
|
88
|
-
'none' => %w
|
89
|
-
'mprescripts' => %w
|
90
|
-
'msrow' => %w
|
91
|
-
'mstack' => %w
|
87
|
+
%w[position length leftoverhang rightoverhang mslinethickness],
|
88
|
+
'none' => %w[],
|
89
|
+
'mprescripts' => %w[],
|
90
|
+
'msrow' => %w[position],
|
91
|
+
'mstack' => %w[align stackalign charalign charspacing]
|
92
92
|
}.freeze
|
93
93
|
|
94
94
|
OTHER_WHITELIST = {
|
95
|
-
'math' => %w
|
96
|
-
altimg-height altimg-valign alttext cdgroup
|
95
|
+
'math' => %w[xmlns display maxwidth overflow altimg altimg-width
|
96
|
+
altimg-height altimg-valign alttext cdgroup],
|
97
97
|
'semantics' => DEF_ENC_ATT,
|
98
|
-
'annotation' => %w
|
99
|
-
'annotation-xml' => %w
|
98
|
+
'annotation' => %w[cd name src] + DEF_ENC_ATT,
|
99
|
+
'annotation-xml' => %w[cd name src] + DEF_ENC_ATT
|
100
100
|
}.freeze
|
101
101
|
end
|
102
102
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thredded
|
4
|
+
module MarkdownKatex
|
5
|
+
module SVGWhitelist
|
6
|
+
# All the non-script SVG elements and attributes.
|
7
|
+
|
8
|
+
SVG_ELEMENTS = %w[
|
9
|
+
a animate animateColor animateMotion animateTransform
|
10
|
+
circle clipPath defs desc ellipse feGaussianBlur filter font-face
|
11
|
+
font-face-name font-face-src foreignObject
|
12
|
+
g glyph hkern linearGradient line marker mask metadata missing-glyph
|
13
|
+
mpath path polygon polyline radialGradient rect set stop svg switch
|
14
|
+
text textPath title tspan use
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
SVG_ATTRIBUTES = %w[
|
18
|
+
accent-height accumulate additive alphabetic
|
19
|
+
arabic-form ascent attributeName attributeType baseProfile bbox begin
|
20
|
+
by calcMode cap-height class clip-path clip-rule color
|
21
|
+
color-interpolation-filters color-rendering content cx cy d dx
|
22
|
+
dy descent display dur end fill fill-opacity fill-rule
|
23
|
+
filterRes filterUnits font-family
|
24
|
+
font-size font-stretch font-style font-variant font-weight from fx fy g1
|
25
|
+
g2 glyph-name gradientUnits hanging height horiz-adv-x horiz-origin-x id
|
26
|
+
ideographic k keyPoints keySplines keyTimes lang marker-end
|
27
|
+
marker-mid marker-start markerHeight markerUnits markerWidth
|
28
|
+
maskContentUnits maskUnits mathematical max method min name offset
|
29
|
+
opacity orient origin overline-position overline-thickness panose-1 path
|
30
|
+
pathLength patternContentUnits patternTransform patternUnits points
|
31
|
+
preserveAspectRatio primitiveUnits r refX refY repeatCount repeatDur
|
32
|
+
requiredExtensions requiredFeatures restart rotate rx ry slope spacing
|
33
|
+
startOffset stdDeviation stemh
|
34
|
+
stemv stop-color stop-opacity strikethrough-position
|
35
|
+
strikethrough-thickness stroke stroke-dasharray stroke-dashoffset
|
36
|
+
stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity
|
37
|
+
stroke-width systemLanguage target text-anchor to transform type u1
|
38
|
+
u2 underline-position underline-thickness unicode unicode-range
|
39
|
+
units-per-em values version viewBox visibility width widths x
|
40
|
+
x-height x1 x2 xlink:actuate xlink:arcrole xlink:href xlink:role
|
41
|
+
xlink:show xlink:title xlink:type xml:base xml:lang xml:space xmlns
|
42
|
+
xmlns:xlink y y1 y2 zoomAndPan
|
43
|
+
].freeze
|
44
|
+
|
45
|
+
SVG_ALLOWED_STYLE_PROPERTIES = %w[
|
46
|
+
fill fill-opacity fill-rule stroke
|
47
|
+
stroke-width stroke-linecap stroke-linejoin stroke-opacity
|
48
|
+
].freeze
|
49
|
+
|
50
|
+
# TODO: The whitelists below are not applied yet.
|
51
|
+
|
52
|
+
SVG_ATTR_VAL_ALLOWS_REF = %w[
|
53
|
+
clip-path color-profile cursor fill
|
54
|
+
filter marker marker-start marker-mid marker-end mask stroke
|
55
|
+
].freeze
|
56
|
+
|
57
|
+
SVG_ALLOW_LOCAL_HREF = %w[
|
58
|
+
altGlyph animate animateColor animateMotion
|
59
|
+
animateTransform cursor feImage filter linearGradient pattern
|
60
|
+
radialGradient textpath tref set use
|
61
|
+
].freeze
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
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.
|
4
|
+
version: 0.2.0
|
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-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: katex
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- lib/thredded/markdown_katex/kramdown/katex_converter.rb
|
125
125
|
- lib/thredded/markdown_katex/mathml_whitelist.rb
|
126
126
|
- lib/thredded/markdown_katex/railtie.rb
|
127
|
+
- lib/thredded/markdown_katex/svg_whitelist.rb
|
127
128
|
- lib/thredded/markdown_katex/version.rb
|
128
129
|
homepage: https://github.com/thredded/thredded-markdown_katex
|
129
130
|
licenses:
|
@@ -145,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
146
|
version: '0'
|
146
147
|
requirements: []
|
147
148
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.6.
|
149
|
+
rubygems_version: 2.6.12
|
149
150
|
signing_key:
|
150
151
|
specification_version: 4
|
151
152
|
summary: Adds TeX math support to Thredded markup via KaTeX.
|