From 294a8e96428c7b1214fb3d1f0458ded7d012307c Mon Sep 17 00:00:00 2001 From: Felipe Lalanne Date: Mon, 11 Jun 2012 12:06:54 +0200 Subject: [PATCH 1/2] [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 `'`. --- lib/gollum/markup.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index bcc58906..dd4b4ad3 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -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 $$ + 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 From f9cd97edaa7af337db4eaf08e44352af451ae6b0 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne Date: Mon, 11 Jun 2012 20:18:22 +0200 Subject: [PATCH 2/2] [Fix] Replaced random escaping of `$` The `$` symbol is now escaped by replacing it with a static string. --- lib/gollum/markup.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index dd4b4ad3..e93df72e 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -125,13 +125,13 @@ 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)}@" + esc = "/%%/" 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 + 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) @@ -147,7 +147,7 @@ module Gollum id = Digest::SHA1.hexdigest(tag) @texmap[id] = [:inline, tag] id - end.gsub(/#{hash}/, '$') # replace the hash back to `$` + end.gsub(/#{esc}/, '$') # replace the `esc` string back to `$` end # Process all TeX from the texmap and replace the placeholders with the