jekyll-mathjax-csp 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +44 -1
  3. data/lib/jekyll-mathjax-csp.rb +37 -3
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54af556ecbe1f41c2faa2a2ddae7f0ad301c97d6fea42d5f17177489d149bed3
4
- data.tar.gz: 4143fc563c8892118a7f2b36acfb57c945c918a4e77d55ff731c63143c3d9f96
3
+ metadata.gz: b2eb60248118f9651e899564a7948241f0d53fbd3467880d53fbd2a449978436
4
+ data.tar.gz: 9bfcfe90f271fb0630c02604c222a4b0c591c061cbee6edccf685ce33dde8b7f
5
5
  SHA512:
6
- metadata.gz: 77d6050e0afc22b614e4bb3a477fafef9ee3dff37902e3f3f0de3c063f03f0ab3b4ea9d23d871da4fc910cf9627fd4bf448866f7c3d0d23cd838f50fd75abd14
7
- data.tar.gz: 5990880a46e9bbbb26f20227737c1295be15f3ed8368d9519e08bc3507bfa08884db3376f72be6c2be396c16e6bfb8d3959a1ed0ab5a44a8fe8494757ad824d7
6
+ metadata.gz: a74cb169542c4160f95991190f8352cd6f30f3903afb76e64f96866a0d3f5a14ba7bb4429adcfb0bf68583fc7addfc2189071502895eb9b574a4a1778972c929
7
+ data.tar.gz: 970b4eeea9f8022e4bcd83f480773ec86552d688f12dd255aaf21a20c88d520c691944bfac5a40fbca259a8c3eb6a3719ba21c4d68dfe824f2d7e1e37b4191bb
data/README.md CHANGED
@@ -45,6 +45,24 @@ The plugin runs the output of Jekyll's markdown parser [kramdown](http://kramdow
45
45
 
46
46
  ## Configuration
47
47
 
48
+ The following fields can be set in `_config.yml`; their default values are given in the sample below.
49
+
50
+ ```yaml
51
+ mathjax_csp:
52
+ linebreaks: false
53
+ single_dollars: false
54
+ format: AsciiMath,TeX,MathML
55
+ font: TeX
56
+ semantics: false
57
+ notexthints: false
58
+ output: SVG
59
+ eqno: none
60
+ ex_size: 6
61
+ width: 100
62
+ extensions: ""
63
+ font_url: "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/fonts/HTML-CSS"
64
+ strip_css: false
65
+ ```
48
66
  'mathjax-node-page' adds a fixed inline stylesheet to every page containing math. If you want to serve this stylesheet as an external `.css`, you can advise the plugin to strip it from the output by adding the following lines to your `_config.yml`:
49
67
 
50
68
  ```yaml
@@ -52,6 +70,23 @@ mathjax_csp:
52
70
  strip_css: true
53
71
  ```
54
72
 
73
+ Configuration for 'mathjax-node-page' is also available:
74
+
75
+ | Key | Description | Default |
76
+ | ---------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
77
+ | `linebreaks` | Perform automatic line-breaking | `false` |
78
+ | `single_dollars` | Allow single-dollar delimiters for inline math | `false` |
79
+ | `format` | Input format(s) to look for | `AsciiMath,TeX,MathML` |
80
+ | `font` | Web font to use in SVG output | `TeX` |
81
+ | `semantics` | For TeX or Asciimath source and MathML output, add input in `<semantics>` tag | `false` |
82
+ | `notexthints` | For TeX input and MathML output, don't add TeX-specific classes | `false` |
83
+ | `output` | Output format: SVG, CommonHTML, or MML | `SVG` |
84
+ | `eqno` | Equation number style (none, AMS, or all) | `none` |
85
+ | `ex_size` | Ex-size, in pixels | `6` |
86
+ | `width` | Width of equation container in `ex`. Used for line-breaking | `100` |
87
+ | `extensions` | Extra MathJax extensions (e.g. `Safe,Tex/noUndefined`) | `""` |
88
+ | `font_url` | URL to use for web fonts | `https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/fonts/HTML-CSS` |
89
+
55
90
  ## Local testing
56
91
 
57
92
  If you want to try out your CSP locally, you can specify headers in your `_config.yml`:
@@ -63,7 +98,15 @@ webrick:
63
98
  default-src 'none'; script-src ...
64
99
  ```
65
100
 
66
- It is unfortunately not possible to have Liquid tags in `_config.yml`, so you will have to update your CSP manually. Don't forget to restart `jekyll` for it to pick up the config changes.
101
+ It is unfortunately not possible to have Liquid tags in `_config.yml`, so with this approach, you will have to update your CSP manually. Don't forget to restart `jekyll` for it to pick up the config changes.
102
+
103
+ Another possibility is using a [`meta` tag with `http-equiv`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta#attr-http-equiv), placed in your pages' `<head>` element:
104
+
105
+ ```html
106
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src ...">
107
+ ```
108
+
109
+ Note that this cannot be used with frame-ancestors, report-uri, or sandbox.
67
110
 
68
111
  ## License
69
112
 
@@ -40,6 +40,25 @@ module Jekyll
40
40
  class Mathifier
41
41
  MATH_TAG_REGEX = /<script[^>]*type="math\/tex/i
42
42
 
43
+ FIELDS = {
44
+ "format" => "--format",
45
+ "font" => "--font",
46
+ "ouput" => "--output",
47
+ "equation_number" => "--eqno",
48
+ "output" => "--output",
49
+ "eqno" => "--eqno",
50
+ "ex_size" => "--ex",
51
+ "width" => "--width",
52
+ "extensions" => "--extensions",
53
+ "font_url" => "--fontURL"
54
+ }
55
+ FLAGS = {
56
+ "linebreaks" => "--linebreaks",
57
+ "single_dollars" => "--dollars",
58
+ "semantics" => "--semantics",
59
+ "notexthints" => "--notexthints"
60
+ }
61
+
43
62
  class << self
44
63
  attr_accessor :csp_hashes
45
64
 
@@ -78,11 +97,26 @@ module Jekyll
78
97
  end
79
98
 
80
99
  # Run mathjax-node-page on a String containing an HTML doc
81
- def run_mjpage(output)
100
+ def run_mjpage(config, output)
82
101
  mathified = ""
83
102
  exit_status = 0
103
+
104
+ command = "node_modules/mathjax-node-page/bin/mjpage"
105
+
106
+ FIELDS.each do |name, flag|
107
+ unless config[name].nil?
108
+ command << " " << flag << " " << config[name].to_s
109
+ end
110
+ end
111
+
112
+ FLAGS.each do |name, flag|
113
+ unless config[name].nil?
114
+ command << " " << flag
115
+ end
116
+ end
117
+
84
118
  begin
85
- Open3.popen2("node_modules/mathjax-node-page/bin/mjpage") {|i,o,t|
119
+ Open3.popen2(command) {|i,o,t|
86
120
  i.print output
87
121
  i.close
88
122
  o.each {|line|
@@ -110,7 +144,7 @@ module Jekyll
110
144
  Jekyll.logger.abort_with "", "due to a misconfiguration or server-side style injection."
111
145
  end
112
146
 
113
- mjpage_output = run_mjpage(doc.output)
147
+ mjpage_output = run_mjpage(config, doc.output)
114
148
  parsed_doc = Nokogiri::HTML::Document.parse(mjpage_output)
115
149
  last_child = parsed_doc.at_css("head").last_element_child()
116
150
  if last_child.name == "style"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-mathjax-csp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabian Henneke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-28 00:00:00.000000000 Z
11
+ date: 2018-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html-pipeline