I would propose an alternative approach. Do not put the {{{...}}} into the stored wiki page. (Then you don't have to worry about reversing all the effects that this has.) Instead write a plugin that only puts the {{{...}}} into the wiki page when it is prepared for display.

I think this can be done with the IWikiPageManipulator.
http://trac.edgewall.org/wiki/TracDev/PluginDevelopment/ExtensionPoints/trac.wiki.api.IWikiPageManipulator

You would have to come up with a different trick to specify which wiki pages should be handled in this way. For example you could use a special naming scheme, like a special ".txt" ending.

That plugin could also add a special CSS class (e.g. class="dottxt") by wrapping the page in {{{#!div class="dottxt" ... }}}.
http://trac.edgewall.org/wiki/WikiHtml#HowtoUseDivSpan

The entire thing could then look like this:

{{{
from trac.core import *
from trac.wiki.api import IWikiPageManipulator

class PlainTextWikiPagePreparer(Component):

    implements(IWikiPageManipulator)

    # A custom CSS class name that can be used for styling
    CSS_CLASSNAME = 'dottxt'

    def prepare_wiki_page(self, req, page, fields):
        if self._is_special_page(page):
            fields['text'] = self._escape_wikitext(page.text)

    def validate_wiki_page(self, req, page):
        return []

    def _is_special_page(self, page):
        """Should the page be treated as special pre-formatted plain text?
        For example, let's treat all wiki pages ending in .txt special.
        """
        return page.name.endswith('.txt')

    def _escape_wikitext(self, wikitext):
        """Return the escaped wikitext of a pre-formatted plain text.
        For example, let's wrap the entire thing in {{{...}}}.
        """
return '{{{#!div class="' + self.CSS_CLASSNAME + '"\n{{{\n' + wikitext + '\n}}}\n}}}'
}}}

You could put this - without the {{{ }}} - into a single file plugin in your plugins folder. Or extend it to a full plugin including the custom CSS.
http://trac.edgewall.org/wiki/TracPlugins#/dropped

---
Peter

--
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/trac-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to