Edgewall Software

Ticket #6508: 6508-htmlcomment-processor.patch

File 6508-htmlcomment-processor.patch, 2.5 KB (added by rblank, 5 months ago)

Patch against trunk adding a htmlcomment wiki processor

  • trac/wiki/formatter.py

    diff --git a/trac/wiki/formatter.py b/trac/wiki/formatter.py
    a b  
    7979        self.macro_provider = None 
    8080 
    8181        builtin_processors = {'html': self._html_processor, 
     82                              'htmlcomment': self._htmlcomment_processor, 
    8283                              'default': self._default_processor, 
    8384                              'comment': self._comment_processor, 
    8485                              'div': self._div_processor, 
     
    130131            line = unicode(text).splitlines()[e.lineno - 1].strip() 
    131132            return system_message(_('HTML parsing error: %(message)s', 
    132133                                    message=escape(e.msg)), line) 
     134         
     135    def _htmlcomment_processor(self, text): 
     136        if "--" in text: 
     137            return system_message(_('Error: Forbidden character sequence ' 
     138                                    '"--" in htmlcomment wiki code block')) 
     139        return Markup('<!--\n%s-->\n' % text) 
    133140         
    134141    def _elt_processor(self, eltname, format_to, text, args): 
    135142        elt = getattr(tag, eltname)(**args) 
  • trac/wiki/tests/wiki-tests.txt

    diff --git a/trac/wiki/tests/wiki-tests.txt b/trac/wiki/tests/wiki-tests.txt
    a b  
    551551<div>Click me</div> 
    552552------------------------------ 
    553553 […] 
     554============================== HTML comment wiki processor 
     555Before 
     556{{{ 
     557#!htmlcomment 
     558This is a comment <em>with embedded tags &amp; entities</em> 
     559}}} 
     560After 
     561------------------------------ 
     562<p> 
     563Before 
     564</p> 
     565<!-- 
     566This is a comment <em>with embedded tags &amp; entities</em> 
     567--> 
     568<p> 
     569After 
     570</p> 
     571------------------------------ 
     572Before 
     573 […] 
     574After 
     575============================== HTML comment wiki processor, comment ends with "-" 
     576Before 
     577{{{ 
     578#!htmlcomment 
     579This comment ends with - 
     580}}} 
     581After 
     582------------------------------ 
     583<p> 
     584Before 
     585</p> 
     586<!-- 
     587This comment ends with - 
     588--> 
     589<p> 
     590After 
     591</p> 
     592------------------------------ 
     593Before 
     594 […] 
     595After 
     596============================== HTML comment wiki processor, comment contains "--" 
     597Before 
     598{{{ 
     599#!htmlcomment 
     600The character sequence -- is not allowed in comments 
     601}}} 
     602After 
     603------------------------------ 
     604<p> 
     605Before 
     606</p> 
     607<div class="system-message"><strong>Error: Forbidden character sequence "--" in htmlcomment wiki code block</strong></div><p> 
     608After 
     609</p> 
     610------------------------------ 
     611Before 
     612 […] 
     613After 
    554614============================== div and span wiki processors 
    555615And now it's [[span('''TIME FOR BED!,class=important)]]. Really. 
    556616{{{