[DRE-commits] [ruby-org] 255/303: Keep text within a code emphasis as is.
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:34:08 UTC 2013
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository ruby-org.
commit dde32372027abe3e6ba4f2826a551cbf2f1c8b84
Author: vonavi <ivvl82 at gmail.com>
Date: Thu Jan 31 20:52:44 2013 +0200
Keep text within a code emphasis as is.
---
lib/org-ruby/html_output_buffer.rb | 11 ++++----
lib/org-ruby/regexp_helper.rb | 48 ++++++++++++++++++++++-----------
lib/org-ruby/textile_output_buffer.rb | 11 ++++----
util/gen-special-replace.el | 2 ++
4 files changed, 47 insertions(+), 25 deletions(-)
diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 75eee18..27f1818 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -244,11 +244,11 @@ module Orgmode
# Applies inline formatting rules to a string.
def inline_formatting(str)
- str = @re_help.rewrite_emphasis(str) do |marker, s|
+ @re_help.rewrite_emphasis str do |marker, s|
"#{Tags[marker][:open]}#{s}#{Tags[marker][:close]}"
end
if @options[:use_sub_superscripts] then
- str = @re_help.rewrite_subp(str) do |type, text|
+ @re_help.rewrite_subp str do |type, text|
if type == "_" then
"<sub>#{text}</sub>"
elsif type == "^" then
@@ -256,10 +256,10 @@ module Orgmode
end
end
end
- str = @re_help.rewrite_images(str) do |link|
+ @re_help.rewrite_images str do |link|
"<a href=\"#{link}\"><img src=\"#{link}\" /></a>"
end
- str = @re_help.rewrite_links(str) do |link, text|
+ @re_help.rewrite_links str do |link, text|
text ||= link
link = link.sub(/^file:(.*)::(.*?)$/) do
@@ -289,13 +289,14 @@ module Orgmode
str.gsub!(/\s*\|\s*/, "</th><th>")
end
if @options[:export_footnotes] then
- str = @re_help.rewrite_footnote(str) do |name, defi|
+ @re_help.rewrite_footnote str do |name, defi|
# TODO escape name for url?
@footnotes[name] = defi if defi
"<sup><a class=\"footref\" name=\"fnr.#{name}\" href=\"#fn.#{name}\">#{name}</a></sup>"
end
end
Orgmode.special_symbols_to_html(str)
+ str = @re_help.restore_code_snippets str
str
end
diff --git a/lib/org-ruby/regexp_helper.rb b/lib/org-ruby/regexp_helper.rb
index 135c90e..6214c14 100644
--- a/lib/org-ruby/regexp_helper.rb
+++ b/lib/org-ruby/regexp_helper.rb
@@ -58,6 +58,7 @@ module Orgmode
@body_regexp = "#{@body_regexp}" +
"(?:\n#{@body_regexp}){0,#{@max_newlines}}" if @max_newlines > 0
@markers = "\\*\\/_=~\\+"
+ @code_snippet_stack = []
@logger = Logger.new(STDERR)
@logger.level = Logger::WARN
build_org_emphasis_regexp
@@ -95,23 +96,32 @@ module Orgmode
# replace "*bold*", "/italic/", and "=code=",
# respectively. (Clearly this sample string will use HTML-like
# syntax, assuming +map+ is defined appropriately.)
- def rewrite_emphasis(str)
- str.gsub(@org_emphasis_regexp) do |match|
- inner = yield $2, $3
+ def rewrite_emphasis str
+ # escape the percent signs for safe restoring code snippets
+ str.gsub!(/%/, "%%")
+ format_str = "%s"
+ str.gsub! @org_emphasis_regexp do |match|
+ # preserve the code snippet from further formatting
+ inner = if $2 == "=" or $2 == "~"
+ @code_snippet_stack.push $3
+ yield $2, format_str
+ else
+ yield $2, $3
+ end
"#{$1}#{inner}"
end
end
# rewrite subscript and superscript (_{foo} and ^{bar})
- def rewrite_subp(str) # :yields: type ("_" for subscript and "^" for superscript), text
- str.gsub(@org_subp_regexp) do |match|
+ def rewrite_subp str # :yields: type ("_" for subscript and "^" for superscript), text
+ str.gsub! @org_subp_regexp do |match|
yield $1, $2
end
end
# rewrite footnotes
- def rewrite_footnote(str) # :yields: name, definition or nil
- str.gsub(@org_footnote_regexp) do |match|
+ def rewrite_footnote str # :yields: name, definition or nil
+ str.gsub! @org_footnote_regexp do |match|
yield $1, $3
end
end
@@ -141,23 +151,31 @@ module Orgmode
# +http://www.hotmail.com+. In both cases, the block returns an
# HTML-style link, and that is how things will get recorded in
# +result+.
- def rewrite_links(str) # :yields: link, text
- str.gsub(@org_link_regexp) do |match|
+ def rewrite_links str # :yields: link, text
+ str.gsub! @org_link_regexp do |match|
yield $1, nil
- end.gsub(@org_link_text_regexp) do |match|
- yield $1, $2
- end.gsub(@org_angle_link_text_regexp) do |match|
- yield "#{$2}:#{$3}", nil
+ end
+ str.gsub! @org_link_text_regexp do |match|
+ yield $1, $2
+ end
+ str.gsub! @org_angle_link_text_regexp do |match|
+ yield "#{$2}:#{$3}", nil
end
end
# Rewrites all of the inline image tags.
- def rewrite_images(str) # :yields: image_link
- str.gsub(@org_img_regexp) do |match|
+ def rewrite_images str # :yields: image_link
+ str.gsub! @org_img_regexp do |match|
yield $1
end
end
+ def restore_code_snippets str
+ str = str % @code_snippet_stack
+ @code_snippet_stack = []
+ str
+ end
+
private
def build_org_emphasis_regexp
diff --git a/lib/org-ruby/textile_output_buffer.rb b/lib/org-ruby/textile_output_buffer.rb
index cdffe0e..c42e7f9 100644
--- a/lib/org-ruby/textile_output_buffer.rb
+++ b/lib/org-ruby/textile_output_buffer.rb
@@ -43,29 +43,30 @@ module Orgmode
# Handles inline formatting for textile.
def inline_formatting(input)
- input = @re_help.rewrite_emphasis(input) do |marker, body|
+ @re_help.rewrite_emphasis input do |marker, body|
m = TextileMap[marker]
"#{m}#{body}#{m}"
end
- input = @re_help.rewrite_subp(input) do |type, text|
+ @re_help.rewrite_subp input do |type, text|
if type == "_" then
"~#{text}~"
elsif type == "^" then
"^#{text}^"
end
end
- input = @re_help.rewrite_links(input) do |link, text|
+ @re_help.rewrite_links input do |link, text|
text ||= link
- link = link.gsub(/ /, "%20")
+ link = link.gsub(/ /, "%%20")
"\"#{text}\":#{link}"
end
- input = @re_help.rewrite_footnote(input) do |name, defi|
+ @re_help.rewrite_footnote input do |name, defi|
# textile only support numerical names! Use hash as a workarround
name = name.hash.to_s unless name.to_i.to_s == name # check if number
@footnotes[name] = defi if defi
"[#{name}]"
end
Orgmode.special_symbols_to_textile(input)
+ input = @re_help.restore_code_snippets input
input
end
diff --git a/util/gen-special-replace.el b/util/gen-special-replace.el
index fa7746d..8ac7951 100644
--- a/util/gen-special-replace.el
+++ b/util/gen-special-replace.el
@@ -17,6 +17,8 @@
(let ((symb (nth to entity)))
;; escape backslashes and quotation marks
(setq symb (replace-regexp-in-string "\\(\\\\\\|\\\"\\)" "\\\\\\&" symb))
+ ;; escape percent marks from further formatting
+ (setq symb (replace-regexp-in-string "%" "%%" symb))
(insert "\n \"" (car entity) "\" => \"" symb "\","))))
;; remove last comma from the sequence
(search-backward ",")
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-org.git
More information about the Pkg-ruby-extras-commits
mailing list