Skip to content

Commit

Permalink
Merge pull request gollum#379 from pipex/latex-dollar-sign
Browse files Browse the repository at this point in the history
[New] Support `$` and `$$` as formula delimiters.
  • Loading branch information
bootstraponline committed Jun 19, 2012
2 parents 9c40cbe + f9cd97e commit b53c961
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/gollum/markup.rb
Expand Up @@ -124,17 +124,30 @@ def process_headers(doc)
#
# 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
Expand Down

0 comments on commit b53c961

Please sign in to comment.