Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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