class HTML::Pipeline::SVGTeX::PreFilter
Constants
- BLOCK_SVGTEX
- FENCED_CODE
- INDENTED_CODE
- INLINE_CODE
- INLINE_SVGTEX
Public Class Methods
new(text, context = nil, result = nil)
click to toggle source
Calls superclass method
# File lib/html/pipeline/svgtex.rb, line 17 def initialize(text, context = nil, result = nil) super text, context, result @text = @text.gsub "\r", '' @inline = {} @codemap = {} end
Public Instance Methods
call()
click to toggle source
# File lib/html/pipeline/svgtex.rb, line 24 def call extract_fenced_code! extract_indented_code! @text.gsub!(BLOCK_SVGTEX) do "\n\n```mathjax\n\\displaystyle{#{$1}}\n```\n\n" end extract_fenced_code! extract_inline_code! @text.gsub!(INLINE_SVGTEX) do "`{mathjax} #{$1}`" end reinsert_code! @text end
extract_fenced_code!()
click to toggle source
Code taken from gollum (github.com/github/gollum)
# File lib/html/pipeline/svgtex.rb, line 57 def extract_fenced_code! @text.gsub!(FENCED_CODE) do id = Digest::SHA1.hexdigest($2) @codemap[id] = { :lang => $1, :code => $2 } id end end
extract_indented_code!()
click to toggle source
# File lib/html/pipeline/svgtex.rb, line 47 def extract_indented_code! @text.gsub!(INDENTED_CODE) do code = $2.gsub(/^(\t|\s{4})/, '').sub(/\r?\n\Z/, '') id = Digest::SHA1.hexdigest(code) @codemap[id] = { :code => code } "\n#{id}" end end
extract_inline_code!()
click to toggle source
# File lib/html/pipeline/svgtex.rb, line 39 def extract_inline_code! @text.gsub!(INLINE_CODE) do id = Digest::SHA1.hexdigest($1) @inline[id] = $1 id end end
reinsert_code!()
click to toggle source
# File lib/html/pipeline/svgtex.rb, line 65 def reinsert_code! @inline.each do |id, code| @text.gsub!(id) { "`#{code}`" } end @codemap.each do |id, spec| @text.gsub!(id) { "```#{spec[:lang]}\n#{spec[:code]}\n```" } end end