plain text, really

28 views
Skip to first unread message

Felipe G. Nievinski

unread,
Sep 2, 2013, 10:12:34 PM9/2/13
to trac-...@googlegroups.com
I have a handful of pre-formatted plain-text files
over which I'd like to have version control.  SVN 
seems overkill, specially becase I'd prefer to 
edit the files via a web client.  So I'm creating
separate wiki pages for each ASCII file, keeping 
the content enclosed in triple-braces, {{{...}}}.

This fits my needs almost perfectly, except for 
a few kinks:
- the wiki page displays the text inside a quotation 
box; ideally it'd be cleaner, less obstrusive: no block
indentation, no darker background (the mono-spaced
font is okay);
- the wiki page "download as plain text" result reveals
the processor braces; ideally it'd return a stripped
textual renderization of the wiki page (as if for printing), 
rather than the wiki page source.

I've found some related developments:

Unfortunately none is quite what I need.
It seems it'd be just a matter of removing 
existing features rather than building new ones.

Your thoughts?

Also, any hints about the long listing here:

Thanks a lot,
-FGN.

Bas Hopman

unread,
Sep 3, 2013, 4:11:24 AM9/3/13
to trac-...@googlegroups.com
Regarding the quotation box. It is simple to add a css file in the htdocs folder which removes the formatting to leave the plain layout.

The download issue requires a change in the code, I guess. Either by adding plugin or by modifying the TRAC code itself...


2013/9/3 Felipe G. Nievinski <fgnie...@gmail.com>

--
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 trac-users+...@googlegroups.com.
To post to this group, send email to trac-...@googlegroups.com.
Visit this group at http://groups.google.com/group/trac-users.
For more options, visit https://groups.google.com/groups/opt_out.

Felipe G. Nievinski

unread,
Sep 3, 2013, 9:55:56 AM9/3/13
to trac-...@googlegroups.com
Except that the css change would be site-wide, and I'd prefer the formatting change wouldn't affect users who didn't intend it so.

I found that MIME types might help:

{{{
#!text/plain
...
}}

Then I can change just the css for that type, I think.  Still not sure how though.

Am still clueless about how to go about the "download as plain text" vs. "download wiki source" issue...

Thx,
-F.

Peter Suter

unread,
Sep 3, 2013, 2:15:00 PM9/3/13
to trac-...@googlegroups.com
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

Felipe G. Nievinski

unread,
Sep 3, 2013, 4:39:55 PM9/3/13
to trac-...@googlegroups.com
it worked beatifully -- many thanks!!!

I'll try and submit that to trac-hacks, 
for the benefit of future users.

the py code deployment is trivial, 
just not sure how to deploy the css.
manually I had to modify templates/
site.html, then htdocs/site.css -- 
how could I do this without breaking
the existing user settings?

It might be easier to just insert 
the style sheet info in the .py 
and generate it on the fly...






--
You received this message because you are subscribed to a topic in the Google Groups "Trac Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/trac-users/Kh6Rm2s_n9A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to trac-users+unsubscribe@googlegroups.com.

Felipe G. Nievinski

unread,
Sep 4, 2013, 6:54:00 PM9/4/13
to trac-...@googlegroups.com
Here's the final version (attached).
I had a little fight with the CSS precedence.
I'll try and submit this to the trac-hacks.
Thanks once again.
-F.
plaintext.py

Felipe G. Nievinski

unread,
Sep 4, 2013, 7:26:30 PM9/4/13
to trac-...@googlegroups.com
I little hitch: edit preview.
Any hints on how the plugin
could be modified to be called
in this case?
Thx,
-F.

Reply all
Reply to author
Forward
0 new messages