Edgewall Software

Ticket #2240: escape_shref.2.patch

File escape_shref.2.patch, 3.0 KB (added by cboos, 3 years ago)

Take two, adding as a special case link:[[BR]] to translate to link:<br /> without the need of "!"

  • trac/wiki/tests/wiki-tests.txt

     
    564564<a class="ext-link" href="rfc-2396.compatible://link"><span class="icon"></span>RFC 2396</a> 
    565565</p> 
    566566============================== 
     567Test:[[BR]] There should be a line break 
     568 
     569!Change:[10] There should be a link to changeset [10] 
     570 
     571Other !test:'''bold text''' is not bold 
     572------------------------------ 
     573<p> 
     574Test:<br /> There should be a line break 
     575</p> 
     576<p> 
     577Change:<a class="missing changeset" href="/changeset/10" rel="nofollow">[10]</a> There should be a link to changeset <a class="missing changeset" href="/changeset/10" rel="nofollow">[10]</a> 
     578</p> 
     579<p> 
     580Other test:<strong>bold text</strong> is not bold 
     581</p> 
     582============================== 
     583![Test:[[BR]] There should be a line break] 
     584 
     585![Change:[10] There should be a link to changeset [10]] 
     586 
     587Other ![test:'''bold text''' is not bold] 
     588------------------------------ 
     589<p> 
     590[Test:<br /> There should be a line break] 
     591</p> 
     592<p> 
     593[Change:<a class="missing changeset" href="/changeset/10" rel="nofollow">[10]</a> There should be a link to changeset <a class="missing changeset" href="/changeset/10" rel="nofollow">[10]</a>] 
     594</p> 
     595<p> 
     596Other [test:<strong>bold text</strong> is not bold] 
     597</p> 
     598============================== 
    567599= ça marche! = 
    568600------------------------------ 
    569601<h1 id="çamarche">ça marche!</h1> 
  • trac/wiki/formatter.py

     
    147147                  r"(?P<inlinecode2>!?%s(?P<inline2>.*?)%s)" % (INLINE_TOKEN, 
    148148                                                                INLINE_TOKEN), 
    149149                  r"(?P<htmlescapeentity>!?&#\d+;)"] 
    150     _post_rules = [(r"(?P<shref>!?((?P<sns>%s):" % LINK_SCHEME + 
     150    _post_rules = [(r"(?P<escapehref>!\[?%s:|%s:\[\[(?:br|BR)\]\])" \ 
     151                    % (LINK_SCHEME, LINK_SCHEME)), 
     152                   (r"(?P<shref>(?P<sns>%s):" % LINK_SCHEME + 
    151153                    r"(?P<stgt>'[^']+'|\"[^\"]+\"|" 
    152                     r"(?:\|(?=[^| ])|&(?!lt;)|[^|& ])*[^|'~_\.,& \)])))"), 
    153                    (r"(?P<lhref>!?\[(?:(?P<lns>%s):" % LINK_SCHEME + 
     154                    r"(?:\|(?=[^| ])|&(?!lt;)|[^|& ])*[^|'~_\.,& \)]))"), 
     155                   (r"(?P<lhref>\[(?:(?P<lns>%s):" % LINK_SCHEME + 
    154156                    r"(?P<ltgt>'[^']+'|\"[^\"]+\"|[^\] ]*)" 
    155157                    r"|(?P<rel>[/.][^ [\]]*))" 
    156158                    r"(?: (?P<label>'[^']+'|\"[^\"]+\"|[^\]]+))?\])"), 
     
    247249            self.open_tag(*italic) 
    248250        return tmp 
    249251 
     252    def _escapehref_formatter(self, match, fullmatch): 
     253        return match[0] == '!' and match[1:] or '%s<br />' % match[:-6] 
     254 
    250255    def _shref_formatter(self, match, fullmatch): 
    251256        ns = fullmatch.group('sns') 
    252257        target = fullmatch.group('stgt')