Merge pull request #379 from pipex/latex-dollar-sign
[New] Support `$` and `$$` as formula delimiters.
This commit is contained in:
+14
-1
@@ -124,17 +124,30 @@ module Gollum
|
||||
#
|
||||
# Returns the placeholder'd String data.
|
||||
def extract_tex(data)
|
||||
# Random string to escape the `$` character (might be overkill)
|
||||
esc = "/%%/"
|
||||
data.gsub(/\\\[\s*(.*?)\s*\\\]/m) do
|
||||
tag = CGI.escapeHTML($1)
|
||||
id = Digest::SHA1.hexdigest(tag)
|
||||
@texmap[id] = [:block, tag]
|
||||
id
|
||||
end.gsub(/'\$/, esc). # Replace `'$` with the `esc` string in order to escape it
|
||||
gsub(/\$\$\s*(.*?)\s*\$\$/m) do
|
||||
tag = CGI.escapeHTML($1)
|
||||
id = Digest::SHA1.hexdigest(tag)
|
||||
@texmap[id] = [:block, tag]
|
||||
id
|
||||
end.gsub(/\\\(\s*(.*?)\s*\\\)/m) do
|
||||
tag = CGI.escapeHTML($1)
|
||||
id = Digest::SHA1.hexdigest(tag)
|
||||
@texmap[id] = [:inline, tag]
|
||||
id
|
||||
end
|
||||
end.gsub(/\$\s*(.*?)\s*\$/m) do # match inline $<formula>$
|
||||
tag = CGI.escapeHTML($1)
|
||||
id = Digest::SHA1.hexdigest(tag)
|
||||
@texmap[id] = [:inline, tag]
|
||||
id
|
||||
end.gsub(/#{esc}/, '$') # replace the `esc` string back to `$`
|
||||
end
|
||||
|
||||
# Process all TeX from the texmap and replace the placeholders with the
|
||||
|
||||
Reference in New Issue
Block a user