Skip to content

Instantly share code, notes, and snippets.

@hyuki
Created July 6, 2021 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyuki/1adc0ece5e389e914fe3ca3cce9ad25c to your computer and use it in GitHub Desktop.
Save hyuki/1adc0ece5e389e914fe3ca3cce9ad25c to your computer and use it in GitHub Desktop.
commonmarker-test.rb
require 'commonmarker'
md = '$$\begin{align}x\\\\y\end{align}$$'
puts "BEFORE:" + md
puts "AFTER :" + CommonMarker.render_html(md)
@hyuki
Copy link
Author

hyuki commented Jul 6, 2021

BEFORE:$$\begin{align}x\\y\end{align}$$
AFTER :<p>$$\begin{align}x\y\end{align}$$</p>

@hyuki
Copy link
Author

hyuki commented Jul 6, 2021

require 'commonmarker'

md = '<div>$$\begin{align}x\\\\y\end{align}$$</div>'
puts "BEFORE:" + md
puts "AFTER :" + CommonMarker.render_html(md, [:UNSAFE])

==>

BEFORE:<div>$$\begin{align}x\\y\end{align}$$</div>
AFTER :<div>$$\begin{align}x\\y\end{align}$$</div>

@hyuki
Copy link
Author

hyuki commented Jul 6, 2021

# $$ ... $$ を <div>$$ ... $$</div> に変換する
def wrap_mathblock(s)
  t = ''
  while s.match(/(\$\$.+?\$\$)/m)
    pre, match, post = $`, $1, $'
    match.gsub!(/\n+/, "\n")
    t += "#{pre}\n<div>#{match}</div>"
    s = post
  end
  t + s
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment