[New] Support $ and $$ as formula delimiters.
Although the standard formula delimiters for latex formulas is currently `\(` and `\[`, the `$` syntax has an advantage from the point of view of writing speed, very important if we intend to use *gollum* as a writing tool. The code includes support for escaping of the `$` symbol by using the gollum syntax `'`.
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)
|
||||
hash = "@#{rand(36**5).to_s(36)}@"
|
||||
data.gsub(/\\\[\s*(.*?)\s*\\\]/m) do
|
||||
tag = CGI.escapeHTML($1)
|
||||
id = Digest::SHA1.hexdigest(tag)
|
||||
@texmap[id] = [:block, tag]
|
||||
id
|
||||
end.gsub(/'\$/, hash). # Replace `'$` by the hash generated earlier 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(/#{hash}/, '$') # replace the hash back to `$`
|
||||
end
|
||||
|
||||
# Process all TeX from the texmap and replace the placeholders with the
|
||||
|
||||
Reference in New Issue
Block a user