Multiple instances of the same abbreviation

Convert all of them, not just the first, when
they occur in the same string.
This commit is contained in:
Jacques Distler 2011-08-26 20:55:04 -05:00
parent 903c4b6bdd
commit 27ad6ff2a8
2 changed files with 19 additions and 13 deletions

View file

@ -21,7 +21,7 @@
require 'iconv'
require 'nokogiri'
require 'strscan'
module MaRuKu; module In; module Markdown; module BlockLevelParser
@ -175,12 +175,15 @@ Disabled by default because of security concerns.
reg = Regexp.new(Regexp.escape(abbrev))
self.replace_each_string do |s|
# bug if many abbreviations are present (agorf)
if m = reg.match(s)
e = md_abbr(abbrev.dup, title ? title.dup : nil)
[m.pre_match, e, m.post_match]
else
s
p=StringScanner.new(s)
a = []
until p.eos?
o = ''
o << p.getch until p.scan(reg) or p.eos?
a << o
a << md_abbr(abbrev.dup, title ? title.dup : nil) if p.matched =~ reg
end
a
end
end
end

View file

@ -3,7 +3,7 @@ Write a comment abouth the test here.
{}
*** Markdown input: ***
The HTML specification is maintained by the W3C.
The HTML specification is maintained by the W3C. The W3C is headquartered in Geneva.
*[HTML]: Hyper Text Markup Language
*[W3C]: World Wide Web Consortium
@ -20,7 +20,9 @@ md_el(:document,[
md_el(:abbr,["HTML"],{:title=>"Hyper Text Markup Language"},[]),
" specification is maintained by the ",
md_el(:abbr,["W3C"],{:title=>"World Wide Web Consortium"},[]),
"."
". The ",
md_el(:abbr,["W3C"],{:title=>"World Wide Web Consortium"},[]),
" is headquartered in Geneva."
]),
md_el(:abbr_def,[],{:abbr=>"HTML",:text=>"Hyper Text Markup Language"},[]),
md_el(:abbr_def,[],{:abbr=>"W3C",:text=>"World Wide Web Consortium"},[]),
@ -32,16 +34,17 @@ md_el(:document,[
md_el(:abbr_def,[],{:abbr=>"Tigra Genesis",:text=>nil},[])
],{},[])
*** Output of to_html ***
<p>The <abbr title="Hyper Text Markup Language">HTML</abbr> specification is maintained by the <abbr title="World Wide Web Consortium">W3C</abbr>.</p>
<p>The <abbr title="Hyper Text Markup Language">HTML</abbr> specification is maintained by the <abbr title="World Wide Web Consortium">W3C</abbr>. The <abbr title="World Wide Web Consortium">W3C</abbr> is headquartered in Geneva.</p>
<p>Operation <abbr>Tigra Genesis</abbr> is going well.</p>
*** Output of to_latex ***
The HTML specification is maintained by the W3C.
The HTML specification is maintained by the W3C. The W3C is headquartered in Geneva.
Operation Tigra Genesis is going well.
*** Output of to_md ***
The HTML specification is maintained by
the W3C.
the W3C. The W3C is headquartered in
Geneva.
*[HTML]: Hyper Text Markup Language
*[W3C]: World Wide Web Consortium
@ -49,4 +52,4 @@ Operation Tigra Genesis is going well.
*[Tigra Genesis]:
*** Output of to_s ***
The HTML specification is maintained by the W3C.Operation Tigra Genesis is going well.
The HTML specification is maintained by the W3C. The W3C is headquartered in Geneva.Operation Tigra Genesis is going well.