How to add a new target to txt2tags It's easy! % Bypass site autotag for {{...}} that turns to <...> in diff output %!postproc: '{{( *\\a *)}}' {@\1@} %!includeconf: config.t2t % Undo the bypass %!postproc: {@(.*?)@} {{\1}} %!postproc: '(?i)(
\1 % Trick to color the diff output %!postproc: ^(\+.*) \1 %!postproc: ^(-.*) \1 %!include: menu.t2t == Yes, YOU can make it == So you like txt2tags very much but your favorite format is not yet supported? How about adding it yourself? You don't need to be a Python programmer to do it. You'll just define variables, no algorithm is needed. In fact, if text editors and the command line don't scare you, **you don't even need to be a programmer** to do it. Just read this document carefully :) On the following guidelines we'll add the imaginary "foo" target to txt2tags. %%TOC + Get the most recent txt2tags source code + IMPORTANT! Before you start, make sure you have the newest txt2tags code, available at http://txt2tags.googlecode.com/svn/trunk/txt2tags Open this file on your favorite text editor. + Add the target identifier in TARGETS + % This step can be removed by TARGET = TARGET_NAMES.keys() % But the ordering of TARGET is important to the --help and Tk interface menus % Think about it At the beginning of the txt2tags source code, right after the long heading comments, you'll find the declaration of all the available targets: ``` TARGETS = 'html xhtml sgml tex lout man mgp wiki gwiki doku moin pm6 txt'.split() Just add your new target identifier. Choose a short name (5 letters or less). ``` TARGETS = 'html xhtml sgml tex lout man mgp wiki gwiki doku moin pm6 txt @@@foo@@@'.split() Note: This identifier will also be the filename extension used by txt2tags when saving the result to a file. You can already run "./txt2tags --help" and see your new target listed on the --target option! + Add the textual description in TARGET_NAMES + Scroll down a little and you'll find the target names. Add a new item to the dictionary, using your identifier and the textual description of it: ``` TARGET_NAMES = { 'html' : _('HTML page'), 'xhtml': _('XHTML page'), 'sgml' : _('SGML document'), 'tex' : _('LaTeX document'), 'lout' : _('Lout document'), 'man' : _('UNIX Manual page'), 'mgp' : _('MagicPoint presentation'), 'wiki' : _('Wikipedia page'), 'gwiki': _('Google Wiki page'), 'doku' : _('DokuWiki page'), 'moin' : _('MoinMoin page'), 'pm6' : _('PageMaker document'), 'txt' : _('Plain Text'), @@@'foo' : _('FOO Document'),@@@ } ``` Tip: Copy & paste instead writing from zero to make sure you won't forgot the _(...) format. + Add the header template in HEADER_TEMPLATE + The headers are the first three lines of a txt2tags document. Some targets as LaTeX have a specific place for them (the Preamble), others don't. Make a decision on how to format the header lines. You have three tokens available: - **%(HEADER1)s** - The first source line (Document title) - **%(HEADER2)s** - The second source line (Document author) - **%(HEADER3)s** - The third source line (Document date) - The title/author/date contents are just suggestions. The user can put whatever he/she wants at those lines. And remember that while the first line (title) is required, the other two are optional. Their lines at this template will be removed if not present. ``` '@@@foo@@@': """\ @@@