[DRE-commits] [ruby-org] 277/303: Transfers @<text> into <text> for HTML output.
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:34:12 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 ed347dc2a95bb3526b51e7b2a790a36c50f50172
Author: vonavi <ivvl82 at gmail.com>
Date: Mon Feb 4 21:47:36 2013 +0200
Transfers @<text> into <text> for HTML output.
---
lib/org-ruby/html_output_buffer.rb | 74 ++++++++++++++++++++----------------
lib/org-ruby/regexp_helper.rb | 4 +-
spec/html_examples/footnotes.html | 6 +--
3 files changed, 46 insertions(+), 38 deletions(-)
diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index f0b20df..c37c966 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -110,7 +110,7 @@ module Orgmode
strip_code_block! if mode_is_code? current_mode
# NOTE: CodeRay and Pygments already escape the html once, so
- # no need to escape_buffer!
+ # no need to escape_string!(@buffer)
case
when (current_mode == :src and defined? Pygments)
lang = normalize_lang @block_lang
@@ -138,7 +138,7 @@ module Orgmode
@buffer.gsub!(/\A\n/, "") if @new_paragraph == :start
@new_paragraph = true
else
- escape_buffer!
+ escape_string! @buffer
end
# Whitespace is significant in :code mode. Always output the
@@ -151,7 +151,6 @@ module Orgmode
else
@buffer.lstrip!
- escape_buffer!
@new_paragraph = nil
@logger.debug "FLUSH ==========> #{current_mode}"
@@ -199,7 +198,7 @@ module Orgmode
@footnotes.each do |name, defi|
@output << "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.#{name}\" href=\"#fnr.#{name}\">#{name}</a></sup>" \
<< inline_formatting(defi) \
- << "\n</p>\n"
+ << "</p>\n"
end
@output << "</div>\n</div>"
@@ -225,10 +224,21 @@ module Orgmode
end
# Escapes any HTML content in the output accumulation buffer @buffer.
- def escape_buffer!
- @buffer.gsub!(/&/, "&")
- @buffer.gsub!(/</, "<")
- @buffer.gsub!(/>/, ">")
+ def escape_string! str
+ str.gsub!(/&/, "&")
+ # Escapes the left and right angular brackets but construction
+ # @<text> which is formatted to <text>
+ str.gsub! /<([^<>\n]*)/ do |match|
+ if $`[-1..-1] == "@" and $'[0..0] == ">" then $&
+ else "<#{$1}"
+ end
+ end
+ str.gsub! /([^<>\n]*)>/ do |match|
+ if $`[-2..-1] == "@<" then $&
+ else "#{$1}>"
+ end
+ end
+ str.gsub!(/@(<[^<>\n]*>)/, "\\1")
end
def buffer_indentation
@@ -242,31 +252,31 @@ module Orgmode
end
Tags = {
- "*" => { :open => "<b>", :close => "</b>" },
- "/" => { :open => "<i>", :close => "</i>" },
- "_" => { :open => "<span style=\"text-decoration:underline;\">",
- :close => "</span>" },
- "=" => { :open => "<code>", :close => "</code>" },
- "~" => { :open => "<code>", :close => "</code>" },
- "+" => { :open => "<del>", :close => "</del>" }
+ "*" => { :open => "b", :close => "b" },
+ "/" => { :open => "i", :close => "i" },
+ "_" => { :open => "span style=\"text-decoration:underline;\"",
+ :close => "span" },
+ "=" => { :open => "code", :close => "code" },
+ "~" => { :open => "code", :close => "code" },
+ "+" => { :open => "del", :close => "del" }
}
# Applies inline formatting rules to a string.
def inline_formatting(str)
@re_help.rewrite_emphasis str do |marker, s|
- "#{Tags[marker][:open]}#{s}#{Tags[marker][:close]}"
+ "@<#{Tags[marker][:open]}>#{s}@</#{Tags[marker][:close]}>"
end
if @options[:use_sub_superscripts] then
@re_help.rewrite_subp str do |type, text|
if type == "_" then
- "<sub>#{text}</sub>"
+ "@<sub>#{text}@</sub>"
elsif type == "^" then
- "<sup>#{text}</sup>"
+ "@<sup>#{text}@</sup>"
end
end
end
@re_help.rewrite_images str do |link|
- "<a href=\"#{link}\"><img src=\"#{link}\" /></a>"
+ "@<a href=\"#{link}\">@<img src=\"#{link}\" />@</a>"
end
@re_help.rewrite_links str do |link, text|
text ||= link
@@ -283,30 +293,30 @@ module Orgmode
link = link.sub(/^file:/i, "") # will default to HTTP
text = text.gsub(/([^\]]*\.(jpg|jpeg|gif|png))/xi) do |img_link|
- "<img src=\"#{img_link}\" />"
+ "@<img src=\"#{img_link}\" />"
end
- "<a href=\"#{link}\">#{text}</a>"
+ "@<a href=\"#{link}\">#{text}@</a>"
end
- if (@output_type == :table_row) then
- str.gsub!(/^\|\s*/, "<td>")
- str.gsub!(/\s*\|$/, "</td>")
- str.gsub!(/\s*\|\s*/, "</td><td>")
+ if @output_type == :table_row
+ str.gsub!(/^\|\s*/, "@<td>")
+ str.gsub!(/\s*\|$/, "@</td>")
+ str.gsub!(/\s*\|\s*/, "@</td>@<td>")
end
- if (@output_type == :table_header) then
- str.gsub!(/^\|\s*/, "<th>")
- str.gsub!(/\s*\|$/, "</th>")
- str.gsub!(/\s*\|\s*/, "</th><th>")
+ if @output_type == :table_header
+ str.gsub!(/^\|\s*/, "@<th>")
+ str.gsub!(/\s*\|$/, "@</th>")
+ str.gsub!(/\s*\|\s*/, "@</th>@<th>")
end
if @options[:export_footnotes] then
@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>"
+ "@<sup>@<a class=\"footref\" name=\"fnr.#{name}\" href=\"#fn.#{name}\">#{name}@</a>@</sup>"
end
end
- Orgmode.special_symbols_to_html(str)
+ escape_string! str
+ Orgmode.special_symbols_to_html str
str = @re_help.restore_code_snippets str
- str
end
def normalize_lang(lang)
diff --git a/lib/org-ruby/regexp_helper.rb b/lib/org-ruby/regexp_helper.rb
index 5645533..0e2e989 100644
--- a/lib/org-ruby/regexp_helper.rb
+++ b/lib/org-ruby/regexp_helper.rb
@@ -156,7 +156,7 @@ module Orgmode
yield $1, $3
end
str.gsub! @org_angle_link_text_regexp do |match|
- yield $2, nil
+ yield $1, nil
end
str # for testing
@@ -196,7 +196,7 @@ module Orgmode
@org_img_regexp = /\[\[
([^\]\[]+\.(jpg|jpeg|gif|png)) # Like a normal URL, but must end with a specified extension
\]\]/xi
- @org_angle_link_text_regexp = /(<|<)(\w+:[^\]\s<>]+?)(>|>)/
+ @org_angle_link_text_regexp = /<(\w+:[^\]\s<>]+)>/
end
end # class Emphasis
end # module Orgmode
diff --git a/spec/html_examples/footnotes.html b/spec/html_examples/footnotes.html
index d08ad06..67cdccf 100644
--- a/spec/html_examples/footnotes.html
+++ b/spec/html_examples/footnotes.html
@@ -8,9 +8,7 @@
<div id="footnotes">
<h2 class="footnotes">Footnotes:</h2>
<div id="text-footnotes">
-<p class="footnote"><sup><a class="footnum" name="fn.abc" href="#fnr.abc">abc</a></sup>definition of abc
-</p>
-<p class="footnote"><sup><a class="footnum" name="fn.1" href="#fnr.1">1</a></sup><b>blub</b>
-</p>
+<p class="footnote"><sup><a class="footnum" name="fn.abc" href="#fnr.abc">abc</a></sup>definition of abc</p>
+<p class="footnote"><sup><a class="footnum" name="fn.1" href="#fnr.1">1</a></sup><b>blub</b></p>
</div>
</div>
--
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