html-pipeline-linuxfr 0.14.14 → 0.14.15
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 +4 -4
- data/README.md +1 -0
- data/html-pipeline-linuxfr.gemspec +1 -0
- data/lib/html/pipeline.rb +1 -0
- data/lib/html/pipeline/linuxfr.rb +3 -1
- data/lib/html/pipeline/markdown_filter.rb +0 -9
- data/lib/html/pipeline/svgtex.rb +77 -0
- data/lib/html/pipeline/syntax_highlight_filter.rb +1 -1
- data/lib/html/pipeline/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 222d2b8194550b2a465246236b25b25edd27b04e
|
4
|
+
data.tar.gz: 9834df883b5faf5bd3e3f24ad43a91c5f6327cbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45892b9b29759d4ed53ade7e51fadf105a8bc4dbcd40e032ba8cb047d734276db4bfb8b2e5bfd70bc77d4b25a1868bd910b3b702ebaa94dbd5abdbff2403b27a
|
7
|
+
data.tar.gz: 6e9bfba0ca96191212bafd5bc95d35a17d697b11bb6eecf6adf229c80b53740fc5637158fbf0fef61ff4a3dcd1158887bafec230d61b81e29bcede9d332cadc1
|
data/README.md
CHANGED
@@ -9,6 +9,7 @@ the standard markdown:
|
|
9
9
|
* words with several underscores are left unchanged (no italics)
|
10
10
|
* PHP Markdown Extra-style tables are supported
|
11
11
|
* external images are proxified
|
12
|
+
* `$ eqn $` and `$$ eqn $$` are transformed to SVG (TeX maths support)
|
12
13
|
* and some other extensions
|
13
14
|
|
14
15
|
To do that, I hacked the html-pipeline from Github to remove some
|
data/lib/html/pipeline.rb
CHANGED
@@ -29,6 +29,7 @@ module HTML
|
|
29
29
|
autoload :TextFilter, 'html/pipeline/text_filter'
|
30
30
|
autoload :MarkdownFilter, 'html/pipeline/markdown_filter'
|
31
31
|
autoload :TableOfContentsFilter, 'html/pipeline/toc_filter'
|
32
|
+
autoload :SVGTeX, 'html/pipeline/svgtex'
|
32
33
|
autoload :SyntaxHighlightFilter, 'html/pipeline/syntax_highlight_filter'
|
33
34
|
autoload :RelativeLinksFilter, 'html/pipeline/relative_links_filter'
|
34
35
|
autoload :CustomLinksFilter, 'html/pipeline/custom_links_filter'
|
@@ -6,17 +6,19 @@ module HTML
|
|
6
6
|
CONTEXT = {
|
7
7
|
toc_minimal_length: 5000,
|
8
8
|
toc_header: "<h2 class=\"sommaire\">Sommaire</h2>\n",
|
9
|
+
svgtex_url: "http://localhost:16000",
|
9
10
|
host: "linuxfr.org"
|
10
11
|
}
|
11
12
|
|
12
13
|
def self.render(text)
|
13
14
|
pipeline = HTML::Pipeline.new [
|
15
|
+
HTML::Pipeline::SVGTeX::PreFilter,
|
14
16
|
HTML::Pipeline::MarkdownFilter,
|
15
17
|
HTML::Pipeline::TableOfContentsFilter,
|
18
|
+
HTML::Pipeline::SVGTeX::PostFilter,
|
16
19
|
HTML::Pipeline::SyntaxHighlightFilter,
|
17
20
|
HTML::Pipeline::RelativeLinksFilter,
|
18
21
|
HTML::Pipeline::CustomLinksFilter,
|
19
|
-
HTML::Pipeline::SanitizationFilter
|
20
22
|
], CONTEXT
|
21
23
|
result = pipeline.call text
|
22
24
|
result[:output].to_s
|
@@ -7,8 +7,6 @@ module HTML
|
|
7
7
|
|
8
8
|
# LinuxFr Flavored Markdown
|
9
9
|
class LFMarkdown < Redcarpet::Render::HTML
|
10
|
-
attr_accessor :image_class
|
11
|
-
|
12
10
|
PARSER_OPTIONS = {
|
13
11
|
:no_intra_emphasis => true,
|
14
12
|
:tables => true,
|
@@ -62,13 +60,6 @@ module HTML
|
|
62
60
|
#
|
63
61
|
# This filter does not write any additional information to the context hash.
|
64
62
|
class MarkdownFilter < TextFilter
|
65
|
-
def initialize(text, context = nil, result = nil)
|
66
|
-
super text, context, result
|
67
|
-
@text = @text.gsub "\r", ''
|
68
|
-
end
|
69
|
-
|
70
|
-
# Convert Markdown to HTML using the best available implementation
|
71
|
-
# and convert into a DocumentFragment.
|
72
63
|
def call
|
73
64
|
lfm = Redcarpet::Markdown.new LFMarkdown, LFMarkdown::PARSER_OPTIONS
|
74
65
|
lfm.render @text
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'base64'
|
3
|
+
require 'digest/sha1'
|
4
|
+
require 'patron'
|
5
|
+
|
6
|
+
module HTML
|
7
|
+
class Pipeline
|
8
|
+
class SVGTeX
|
9
|
+
|
10
|
+
class PreFilter < TextFilter
|
11
|
+
def initialize(text, context = nil, result = nil)
|
12
|
+
super text, context, result
|
13
|
+
@text = @text.gsub "\r", ''
|
14
|
+
@codemap = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
extract_code!
|
19
|
+
@text.gsub!(/^\$\$([^$]+)\$\$\s*$/) do
|
20
|
+
"\n\n```mathjax\n\\displaystyle{#{$1.gsub "\\", "\\\\\\\\"}}\n```\n\n"
|
21
|
+
end
|
22
|
+
extract_code!
|
23
|
+
@text.gsub!(/\$([^$\n]+)\$/) do
|
24
|
+
"`{mathjax} #{$1}`"
|
25
|
+
end
|
26
|
+
reinsert_code!
|
27
|
+
@text
|
28
|
+
end
|
29
|
+
|
30
|
+
# Code taken from gollum (http://github.com/github/gollum)
|
31
|
+
def extract_code!
|
32
|
+
@text.gsub!(/^``` ?(.+?)\r?\n(.+?)\r?\n```\r?$/m) do
|
33
|
+
id = Digest::SHA1.hexdigest($2)
|
34
|
+
@codemap[id] = { :lang => $1, :code => $2 }
|
35
|
+
id
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def reinsert_code!
|
40
|
+
@codemap.each do |id, spec|
|
41
|
+
@text.gsub!(id, "```#{spec[:lang]}\n#{spec[:code]}\n```")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class PostFilter < Filter
|
47
|
+
def call
|
48
|
+
doc.search('code.mathjax').each do |node|
|
49
|
+
eqn = node.inner_text
|
50
|
+
rsp = session.post(context[:svgtex_url], :q => eqn)
|
51
|
+
if rsp.status == 200
|
52
|
+
node.parent.replace rsp.body.gsub(/margin-(left|right): 0px; /, "")
|
53
|
+
else
|
54
|
+
node.remove_attribute 'class'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
doc.search('code:not([class])').each do |node|
|
58
|
+
eqn = node.inner_text
|
59
|
+
next unless eqn.sub!(/\A\{mathjax\} /, '')
|
60
|
+
rsp = session.post(context[:svgtex_url], :q => eqn)
|
61
|
+
if rsp.status == 200
|
62
|
+
node.replace "<img src='data:image/svg+xml;base64,#{Base64.encode64 rsp.body}' alt='#{CGI.escape_html eqn}' />"
|
63
|
+
else
|
64
|
+
node.inner_text = eqn
|
65
|
+
end
|
66
|
+
end
|
67
|
+
doc
|
68
|
+
end
|
69
|
+
|
70
|
+
def session
|
71
|
+
@session ||= Patron::Session.new
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html-pipeline-linuxfr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Tomayko
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-03-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nokogiri
|
@@ -96,6 +96,20 @@ dependencies:
|
|
96
96
|
- - "~>"
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '3.0'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: patron
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0.4'
|
106
|
+
type: :runtime
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - "~>"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0.4'
|
99
113
|
description: LinuxFr.org HTML processing filters and utilities, adapted from those
|
100
114
|
of GitHub
|
101
115
|
email:
|
@@ -122,6 +136,7 @@ files:
|
|
122
136
|
- lib/html/pipeline/markdown_filter.rb
|
123
137
|
- lib/html/pipeline/relative_links_filter.rb
|
124
138
|
- lib/html/pipeline/sanitization_filter.rb
|
139
|
+
- lib/html/pipeline/svgtex.rb
|
125
140
|
- lib/html/pipeline/syntax_highlight_filter.rb
|
126
141
|
- lib/html/pipeline/text_filter.rb
|
127
142
|
- lib/html/pipeline/toc_filter.rb
|
@@ -157,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
172
|
version: '0'
|
158
173
|
requirements: []
|
159
174
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.2.
|
175
|
+
rubygems_version: 2.2.2
|
161
176
|
signing_key:
|
162
177
|
specification_version: 4
|
163
178
|
summary: Helpers for processing content through a chain of filters
|