#!/usr/bin/python # txt2tags.py # 20010726 ** debut # TODO || moincel ||, TABcel1TABcel2, --- forget table for now. # TODO \ ==
--- mmmm, no. # TODO allow lists inside quotes? (mgp TAB problems) # TODO =title=[label]) # TODO mgp error (escape ^% - how???) # TODO mgp: subquote (increase prefix) ----mmmm, maybe not (big letters, few hspace) # TODO pm6 : check quote # # BUG: sgml: title after quote left a blank line before # #i pm6: paragraph == 1 line import re, string, os, sys from time import strftime,time,localtime my_url = 'http://txt2tags.sourceforge.net' my_email = 'verde@verde666.org' usage = 'usage: %s -t|--type txt,sgml,html,pm6,mgp,moin file.txt\n'%(sys.argv[0]) # soon i'll use getopts &:) if len(sys.argv) != 4: print usage sys.exit(1) doctype = sys.argv[2] file = sys.argv[3] tags = ['txt', 'sgml', 'html', 'pm6', 'mgp', 'moin'] try: T = tags.index(doctype) except ValueError: print "invalid type '%s'"%(doctype) print usage sys.exit(1) if not os.path.isfile(file): print 'file not found: '+file sys.exit(1) ### all the registered tags TAGparagraph = ['', '

', '

', '<@Normal:>', '%font "normal", size 5\n', ''] TAGtitle1 = [' \a' , '\a'+TAGparagraph[1] , '

\a

', '\n<@Title1:>\a', '%page\n\n\a', '= \a ='] TAGtitle2 = ['\t\a' , '\a'+TAGparagraph[1], '

\a

', '\n<@Title2:>\a', '%page\n\n\a', '== \a =='] TAGtitle3 = ['\t\t\a' , '\a'+TAGparagraph[1], '

\a

', '\n<@Title3:>\a', '%page\n\n\a', '=== \a ==='] TAGtitle4 = ['\t\t\t\a' , '\a'+TAGparagraph[1], '

\a

', '\n<@Title4:>\a', '%page\n\n\a', '==== \a ===='] TAGtitle5 = ['\t\t\t\t\a', '\a'+TAGparagraph[1], '
\a
', '\n<@Title5:>\a', '%page\n\n\a', '===== \a ====='] TAGareaPreOpen = ['', '', '
', '<@PreFormat:>', '\n%font "mono"', '{{{']
TAGareaPreClose = ['', '', '
', '', '%font "normal"', '}}}'] TAGareaQuoteOpen = [' ', '', '
', '<@Quote:>', '%prefix " "', ' '] TAGareaQuoteClose = ['', '', '
', '', '%prefix ""', ''] TAGfontMonoOpen = ['', '', '', '', '\n%cont, font "mono"\n', '{{{'] TAGfontMonoClose = ['', '', '', '', '\n%cont, font "normal"\n', '}}}'] TAGfontBoldOpen = ['', '', '', '', '\n%cont, font "normal-b"\n', "'''"] TAGfontBoldClose = ['', '', '', '

', '\n%cont, font "normal"\n', "'''"] TAGfontItalicOpen = ['', '', '', '', '\n%cont, font "normal-i"\n', "''"] TAGfontItalicClose = ['', '', '', '

', '\n%cont, font "normal"\n', "''"] TAGfontBoldItalicOpen = ['', '', '', '', '\n%cont, font "normal-bi"\n', "'''''"] TAGfontBoldItalicClose = ['', '', '', '

', '\n%cont, font "normal"\n', "'''''"] TAGfontUnderlineOpen = ['', TAGfontBoldItalicOpen[1], '', '', '\n%cont, fore "cyan"\n', TAGfontBoldItalicOpen[5]] TAGfontUnderlineClose = ['', TAGfontBoldItalicClose[1], '', '

', '\n%cont, fore "white"\n', TAGfontBoldItalicClose[5]] TAGlistOpen = ['', '', '

    ', '<@Bullet:>', '', ''] TAGlistClose = ['', '', '
', '', '', ''] TAGlistItem = ['- ', '', '
  • ', '• ', '', ' * '] TAGbar1 = ['\a', '', '
    ', '\a', '%bar "white" 5', '----'] TAGbar2 = ['\a', '', '
    ', '\a', '%pause', '----'] TAGurl = ['\a', '', '\a', TAGfontUnderlineOpen[3]+'\a'+TAGfontUnderlineClose[3], '\n%cont, fore "cyan"\n\a\n%cont, fore "white"\n', '[\a]'] TAGemail = ['\a', '', '\a', '\a', TAGurl[4], '[\a]'] TAGimg = ['[\a]', '
    ', '

    ', '\a', '\n%center\n%newimage -yscrzoom 50"\a", left\n', '[\a]'] TAGEOD = ['', '', '', '', '%%EOD', ''] ### the cool regexes re_title = re.compile(r'^\s*(?P={1,5})(?P[^=].*[^=])\1(\[(?P