PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/old/txt2tags-2.5.py

http://txt2tags.googlecode.com/
Python | 4991 lines | 4488 code | 195 blank | 308 comment | 203 complexity | 4eaee5f18ce5088297939ff6fb92a688 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, WTFPL

Large files files are truncated, but you can click here to view the full file

  1. #!/usr/bin/env python
  2. # txt2tags - generic text conversion tool
  3. # http://txt2tags.sf.net
  4. #
  5. # Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Aurelio Jargas
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, version 2.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You have received a copy of the GNU General Public License along
  17. # with this program, on the COPYING file.
  18. #
  19. ########################################################################
  20. #
  21. # BORING CODE EXPLANATION AHEAD
  22. #
  23. # Just read it if you wish to understand how the txt2tags code works.
  24. #
  25. ########################################################################
  26. #
  27. # The code that [1] parses the marked text is separated from the
  28. # code that [2] insert the target tags.
  29. #
  30. # [1] made by: def convert()
  31. # [2] made by: class BlockMaster
  32. #
  33. # The structures of the marked text are identified and its contents are
  34. # extracted into a data holder (Python lists and dictionaries).
  35. #
  36. # When parsing the source file, the blocks (para, lists, quote, table)
  37. # are opened with BlockMaster, right when found. Then its contents,
  38. # which spans on several lines, are feeded into a special holder on the
  39. # BlockMaster instance. Just when the block is closed, the target tags
  40. # are inserted for the full block as a whole, in one pass. This way, we
  41. # have a better control on blocks. Much better than the previous line by
  42. # line approach.
  43. #
  44. # In other words, whenever inside a block, the parser *holds* the tag
  45. # insertion process, waiting until the full block is read. That was
  46. # needed primary to close paragraphs for the XHTML target, but
  47. # proved to be a very good adding, improving many other processing.
  48. #
  49. # -------------------------------------------------------------------
  50. #
  51. # These important classes are all documented:
  52. # CommandLine, SourceDocument, ConfigMaster, ConfigLines.
  53. #
  54. # There is a RAW Config format and all kind of configuration is first
  55. # converted to this format. Then a generic method parses it.
  56. #
  57. # These functions get information about the input file(s) and take
  58. # care of the init processing:
  59. # get_infiles_config(), process_source_file() and convert_this_files()
  60. #
  61. ########################################################################
  62. #XXX Python coding warning
  63. # Avoid common mistakes:
  64. # - do NOT use newlist=list instead newlist=list[:]
  65. # - do NOT use newdic=dic instead newdic=dic.copy()
  66. # - do NOT use dic[key] instead dic.get(key)
  67. # - do NOT use del dic[key] without has_key() before
  68. #XXX Smart Image Align don't work if the image is a link
  69. # Can't fix that because the image is expanded together with the
  70. # link, at the linkbank filling moment. Only the image is passed
  71. # to parse_images(), not the full line, so it is always 'middle'.
  72. #XXX Paragraph separation not valid inside Quote
  73. # Quote will not have <p></p> inside, instead will close and open
  74. # again the <blockquote>. This really sux in CSS, when defining a
  75. # different background color. Still don't know how to fix it.
  76. #XXX TODO (maybe)
  77. # New mark or macro which expands to an anchor full title.
  78. # It is necessary to parse the full document in this order:
  79. # DONE 1st scan: HEAD: get all settings, including %!includeconf
  80. # DONE 2nd scan: BODY: expand includes & apply %!preproc
  81. # 3rd scan: BODY: read titles and compose TOC info
  82. # 4th scan: BODY: full parsing, expanding [#anchor] 1st
  83. # Steps 2 and 3 can be made together, with no tag adding.
  84. # Two complete body scans will be *slow*, don't know if it worths.
  85. # One solution may be add the titles as postproc rules
  86. ##############################################################################
  87. # User config (1=ON, 0=OFF)
  88. USE_I18N = 1 # use gettext for i18ned messages? (default is 1)
  89. COLOR_DEBUG = 1 # show debug messages in colors? (default is 1)
  90. BG_LIGHT = 0 # your terminal background color is light (default is 0)
  91. HTML_LOWER = 0 # use lowercased HTML tags instead upper? (default is 0)
  92. ##############################################################################
  93. # These are all the core Python modules used by txt2tags (KISS!)
  94. import re, string, os, sys, time, getopt
  95. # Program information
  96. my_url = 'http://txt2tags.sf.net'
  97. my_name = 'txt2tags'
  98. my_email = 'verde@aurelio.net'
  99. my_version = '2.5'
  100. # i18n - just use if available
  101. if USE_I18N:
  102. try:
  103. import gettext
  104. # If your locale dir is different, change it here
  105. cat = gettext.Catalog('txt2tags',localedir='/usr/share/locale/')
  106. _ = cat.gettext
  107. except:
  108. _ = lambda x:x
  109. else:
  110. _ = lambda x:x
  111. # FLAGS : the conversion related flags , may be used in %!options
  112. # OPTIONS : the conversion related options, may be used in %!options
  113. # ACTIONS : the other behavior modifiers, valid on command line only
  114. # MACROS : the valid macros with their default values for formatting
  115. # SETTINGS: global miscellaneous settings, valid on RC file only
  116. # NO_TARGET: actions that don't require a target specification
  117. # NO_MULTI_INPUT: actions that don't accept more than one input file
  118. # CONFIG_KEYWORDS: the valid %!key:val keywords
  119. #
  120. # FLAGS and OPTIONS are configs that affect the converted document.
  121. # They usually have also a --no-<option> to turn them OFF.
  122. #
  123. # ACTIONS are needed because when doing multiple input files, strange
  124. # behavior would be found, as use command line interface for the
  125. # first file and gui for the second. There is no --no-<action>.
  126. # --version and --help inside %!options are also odd
  127. #
  128. TARGETS = 'html xhtml sgml tex lout man mgp wiki gwiki doku moin pm6 txt'.split()
  129. FLAGS = {'headers' :1 , 'enum-title' :0 , 'mask-email' :0 ,
  130. 'toc-only' :0 , 'toc' :0 , 'rc' :1 ,
  131. 'css-sugar' :0 , 'css-suggar' :0 , 'css-inside' :0 ,
  132. 'quiet' :0 }
  133. OPTIONS = {'target' :'', 'toc-level' :3 , 'style' :'',
  134. 'infile' :'', 'outfile' :'', 'encoding' :'',
  135. 'config-file':'', 'split' :0 , 'lang' :'',
  136. 'show-config-value':'' }
  137. ACTIONS = {'help' :0 , 'version' :0 , 'gui' :0 ,
  138. 'verbose' :0 , 'debug' :0 , 'dump-config':0 ,
  139. 'dump-source':0 }
  140. MACROS = {'date' : '%Y%m%d', 'infile': '%f',
  141. 'mtime': '%Y%m%d', 'outfile': '%f'}
  142. SETTINGS = {} # for future use
  143. NO_TARGET = ['help', 'version', 'gui', 'toc-only', 'dump-config', 'dump-source']
  144. NO_MULTI_INPUT = ['gui','dump-config','dump-source']
  145. CONFIG_KEYWORDS = [
  146. 'target', 'encoding', 'style', 'options', 'preproc','postproc',
  147. 'guicolors']
  148. TARGET_NAMES = {
  149. 'html' : _('HTML page'),
  150. 'xhtml': _('XHTML page'),
  151. 'sgml' : _('SGML document'),
  152. 'tex' : _('LaTeX document'),
  153. 'lout' : _('Lout document'),
  154. 'man' : _('UNIX Manual page'),
  155. 'mgp' : _('MagicPoint presentation'),
  156. 'wiki' : _('Wikipedia page'),
  157. 'gwiki': _('Google Wiki page'),
  158. 'doku' : _('DokuWiki page'),
  159. 'moin' : _('MoinMoin page'),
  160. 'pm6' : _('PageMaker document'),
  161. 'txt' : _('Plain Text'),
  162. }
  163. DEBUG = 0 # do not edit here, please use --debug
  164. VERBOSE = 0 # do not edit here, please use -v, -vv or -vvv
  165. QUIET = 0 # do not edit here, please use --quiet
  166. GUI = 0 # do not edit here, please use --gui
  167. AUTOTOC = 1 # do not edit here, please use --no-toc or %%toc
  168. RC_RAW = []
  169. CMDLINE_RAW = []
  170. CONF = {}
  171. BLOCK = None
  172. regex = {}
  173. TAGS = {}
  174. rules = {}
  175. lang = 'english'
  176. TARGET = ''
  177. STDIN = STDOUT = '-'
  178. MODULEIN = MODULEOUT = '-module-'
  179. ESCCHAR = '\x00'
  180. SEPARATOR = '\x01'
  181. LISTNAMES = {'-':'list', '+':'numlist', ':':'deflist'}
  182. LINEBREAK = {'default':'\n', 'win':'\r\n', 'mac':'\r'}
  183. # Platform specific settings
  184. LB = LINEBREAK.get(sys.platform[:3]) or LINEBREAK['default']
  185. VERSIONSTR = _("%s version %s <%s>")%(my_name,my_version,my_url)
  186. USAGE = string.join([
  187. '',
  188. _("Usage: %s [OPTIONS] [infile.t2t ...]") % my_name,
  189. '',
  190. _(" -t, --target=TYPE set target document type. currently supported:"),
  191. ' %s,' % string.join(TARGETS[:8], ', '),
  192. ' %s' % string.join(TARGETS[8:], ', '),
  193. _(" -i, --infile=FILE set FILE as the input file name ('-' for STDIN)"),
  194. _(" -o, --outfile=FILE set FILE as the output file name ('-' for STDOUT)"),
  195. _(" -H, --no-headers suppress header, title and footer contents"),
  196. _(" --headers show header, title and footer contents (default ON)"),
  197. _(" --encoding=ENC set target file encoding (utf-8, iso-8859-1, etc)"),
  198. _(" --style=FILE use FILE as the document style (like HTML CSS)"),
  199. _(" --css-sugar insert CSS-friendly tags for HTML and XHTML targets"),
  200. _(" --css-inside insert CSS file contents inside HTML/XHTML headers"),
  201. _(" --mask-email hide email from spam robots. x@y.z turns <x (a) y z>"),
  202. _(" --toc add TOC (Table of Contents) to target document"),
  203. _(" --toc-only print document TOC and exit"),
  204. _(" --toc-level=N set maximum TOC level (depth) to N"),
  205. _(" -n, --enum-title enumerate all titles as 1, 1.1, 1.1.1, etc"),
  206. _(" -C, --config-file=F read config from file F"),
  207. _(" --rc read user config file ~/.txt2tagsrc (default ON)"),
  208. _(" --gui invoke Graphical Tk Interface"),
  209. _(" -q, --quiet quiet mode, suppress all output (except errors)"),
  210. _(" -v, --verbose print informative messages during conversion"),
  211. _(" -h, --help print this help information and exit"),
  212. _(" -V, --version print program version and exit"),
  213. _(" --dump-config print all the config found and exit"),
  214. _(" --dump-source print the document source, with includes expanded"),
  215. '',
  216. _("Turn OFF options:"),
  217. " --no-outfile, --no-infile, --no-style, --no-encoding, --no-headers",
  218. " --no-toc, --no-toc-only, --no-mask-email, --no-enum-title, --no-rc",
  219. " --no-css-sugar, --no-css-inside, --no-quiet, --no-dump-config",
  220. " --no-dump-source",
  221. '',
  222. _("Example:\n %s -t html --toc myfile.t2t") % my_name,
  223. '',
  224. _("By default, converted output is saved to 'infile.<target>'."),
  225. _("Use --outfile to force an output file name."),
  226. _("If input file is '-', reads from STDIN."),
  227. _("If output file is '-', dumps output to STDOUT."),
  228. '',
  229. 'http://txt2tags.sourceforge.net',
  230. ''
  231. ], '\n')
  232. ##############################################################################
  233. # Here is all the target's templates
  234. # You may edit them to fit your needs
  235. # - the %(HEADERn)s strings represent the Header lines
  236. # - the %(STYLE)s string is changed by --style contents
  237. # - the %(ENCODING)s string is changed by --encoding contents
  238. # - if any of the above is empty, the full line is removed
  239. # - use %% to represent a literal %
  240. #
  241. HEADER_TEMPLATE = {
  242. 'txt': """\
  243. %(HEADER1)s
  244. %(HEADER2)s
  245. %(HEADER3)s
  246. """,
  247. 'sgml': """\
  248. <!doctype linuxdoc system>
  249. <article>
  250. <title>%(HEADER1)s
  251. <author>%(HEADER2)s
  252. <date>%(HEADER3)s
  253. """,
  254. 'html': """\
  255. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  256. <HTML>
  257. <HEAD>
  258. <META NAME="generator" CONTENT="http://txt2tags.sf.net">
  259. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=%(ENCODING)s">
  260. <LINK REL="stylesheet" TYPE="text/css" HREF="%(STYLE)s">
  261. <TITLE>%(HEADER1)s</TITLE>
  262. </HEAD><BODY BGCOLOR="white" TEXT="black">
  263. <P ALIGN="center"><CENTER><H1>%(HEADER1)s</H1>
  264. <FONT SIZE="4">
  265. <I>%(HEADER2)s</I><BR>
  266. %(HEADER3)s
  267. </FONT></CENTER>
  268. """,
  269. 'htmlcss': """\
  270. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  271. <HTML>
  272. <HEAD>
  273. <META NAME="generator" CONTENT="http://txt2tags.sf.net">
  274. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=%(ENCODING)s">
  275. <LINK REL="stylesheet" TYPE="text/css" HREF="%(STYLE)s">
  276. <TITLE>%(HEADER1)s</TITLE>
  277. </HEAD>
  278. <BODY>
  279. <DIV CLASS="header" ID="header">
  280. <H1>%(HEADER1)s</H1>
  281. <H2>%(HEADER2)s</H2>
  282. <H3>%(HEADER3)s</H3>
  283. </DIV>
  284. """,
  285. 'xhtml': """\
  286. <?xml version="1.0"
  287. encoding="%(ENCODING)s"
  288. ?>
  289. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\
  290. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  291. <html xmlns="http://www.w3.org/1999/xhtml">
  292. <head>
  293. <title>%(HEADER1)s</title>
  294. <meta name="generator" content="http://txt2tags.sf.net" />
  295. <link rel="stylesheet" type="text/css" href="%(STYLE)s" />
  296. </head>
  297. <body bgcolor="white" text="black">
  298. <div align="center">
  299. <h1>%(HEADER1)s</h1>
  300. <h2>%(HEADER2)s</h2>
  301. <h3>%(HEADER3)s</h3>
  302. </div>
  303. """,
  304. 'xhtmlcss': """\
  305. <?xml version="1.0"
  306. encoding="%(ENCODING)s"
  307. ?>
  308. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\
  309. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  310. <html xmlns="http://www.w3.org/1999/xhtml">
  311. <head>
  312. <title>%(HEADER1)s</title>
  313. <meta name="generator" content="http://txt2tags.sf.net" />
  314. <link rel="stylesheet" type="text/css" href="%(STYLE)s" />
  315. </head>
  316. <body>
  317. <div class="header" id="header">
  318. <h1>%(HEADER1)s</h1>
  319. <h2>%(HEADER2)s</h2>
  320. <h3>%(HEADER3)s</h3>
  321. </div>
  322. """,
  323. 'man': """\
  324. .TH "%(HEADER1)s" 1 "%(HEADER3)s" "%(HEADER2)s"
  325. """,
  326. # TODO style to <HR>
  327. 'pm6': """\
  328. <PMTags1.0 win><C-COLORTABLE ("Preto" 1 0 0 0)
  329. ><@Normal=
  330. <FONT "Times New Roman"><CCOLOR "Preto"><SIZE 11>
  331. <HORIZONTAL 100><LETTERSPACE 0><CTRACK 127><CSSIZE 70><C+SIZE 58.3>
  332. <C-POSITION 33.3><C+POSITION 33.3><P><CBASELINE 0><CNOBREAK 0><CLEADING -0.05>
  333. <GGRID 0><GLEFT 7.2><GRIGHT 0><GFIRST 0><G+BEFORE 7.2><G+AFTER 0>
  334. <GALIGNMENT "justify"><GMETHOD "proportional"><G& "ENGLISH">
  335. <GPAIRS 12><G%% 120><GKNEXT 0><GKWIDOW 0><GKORPHAN 0><GTABS $>
  336. <GHYPHENATION 2 34 0><GWORDSPACE 75 100 150><GSPACE -5 0 25>
  337. ><@Bullet=<@-PARENT "Normal"><FONT "Abadi MT Condensed Light">
  338. <GLEFT 14.4><G+BEFORE 2.15><G%% 110><GTABS(25.2 l "")>
  339. ><@PreFormat=<@-PARENT "Normal"><FONT "Lucida Console"><SIZE 8><CTRACK 0>
  340. <GLEFT 0><G+BEFORE 0><GALIGNMENT "left"><GWORDSPACE 100 100 100><GSPACE 0 0 0>
  341. ><@Title1=<@-PARENT "Normal"><FONT "Arial"><SIZE 14><B>
  342. <GCONTENTS><GLEFT 0><G+BEFORE 0><GALIGNMENT "left">
  343. ><@Title2=<@-PARENT "Title1"><SIZE 12><G+BEFORE 3.6>
  344. ><@Title3=<@-PARENT "Title1"><SIZE 10><GLEFT 7.2><G+BEFORE 7.2>
  345. ><@Title4=<@-PARENT "Title3">
  346. ><@Title5=<@-PARENT "Title3">
  347. ><@Quote=<@-PARENT "Normal"><SIZE 10><I>>
  348. %(HEADER1)s
  349. %(HEADER2)s
  350. %(HEADER3)s
  351. """,
  352. 'mgp': """\
  353. #!/usr/X11R6/bin/mgp -t 90
  354. %%deffont "normal" xfont "utopia-medium-r", charset "iso8859-1"
  355. %%deffont "normal-i" xfont "utopia-medium-i", charset "iso8859-1"
  356. %%deffont "normal-b" xfont "utopia-bold-r" , charset "iso8859-1"
  357. %%deffont "normal-bi" xfont "utopia-bold-i" , charset "iso8859-1"
  358. %%deffont "mono" xfont "courier-medium-r", charset "iso8859-1"
  359. %%default 1 size 5
  360. %%default 2 size 8, fore "yellow", font "normal-b", center
  361. %%default 3 size 5, fore "white", font "normal", left, prefix " "
  362. %%tab 1 size 4, vgap 30, prefix " ", icon arc "red" 40, leftfill
  363. %%tab 2 prefix " ", icon arc "orange" 40, leftfill
  364. %%tab 3 prefix " ", icon arc "brown" 40, leftfill
  365. %%tab 4 prefix " ", icon arc "darkmagenta" 40, leftfill
  366. %%tab 5 prefix " ", icon arc "magenta" 40, leftfill
  367. %%%%------------------------- end of headers -----------------------------
  368. %%page
  369. %%size 10, center, fore "yellow"
  370. %(HEADER1)s
  371. %%font "normal-i", size 6, fore "white", center
  372. %(HEADER2)s
  373. %%font "mono", size 7, center
  374. %(HEADER3)s
  375. """,
  376. 'moin': """\
  377. '''%(HEADER1)s'''
  378. ''%(HEADER2)s''
  379. %(HEADER3)s
  380. """,
  381. 'gwiki': """\
  382. *%(HEADER1)s*
  383. %(HEADER2)s
  384. _%(HEADER3)s_
  385. """,
  386. 'doku': """\
  387. ===== %(HEADER1)s =====
  388. **//%(HEADER2)s//**
  389. //%(HEADER3)s//
  390. """,
  391. 'wiki': """\
  392. '''%(HEADER1)s'''
  393. %(HEADER2)s
  394. ''%(HEADER3)s''
  395. """,
  396. 'tex': \
  397. r"""\documentclass{article}
  398. \usepackage{graphicx}
  399. \usepackage[normalem]{ulem} %% needed by strike
  400. \usepackage[urlcolor=blue,colorlinks=true]{hyperref}
  401. \usepackage[%(ENCODING)s]{inputenc} %% char encoding
  402. \usepackage{%(STYLE)s} %% user defined
  403. \title{%(HEADER1)s}
  404. \author{%(HEADER2)s}
  405. \begin{document}
  406. \date{%(HEADER3)s}
  407. \maketitle
  408. \clearpage
  409. """,
  410. 'lout': """\
  411. @SysInclude { doc }
  412. @Document
  413. @InitialFont { Times Base 12p } # Times, Courier, Helvetica, ...
  414. @PageOrientation { Portrait } # Portrait, Landscape
  415. @ColumnNumber { 1 } # Number of columns (2, 3, ...)
  416. @PageHeaders { Simple } # None, Simple, Titles, NoTitles
  417. @InitialLanguage { English } # German, French, Portuguese, ...
  418. @OptimizePages { Yes } # Yes/No smart page break feature
  419. //
  420. @Text @Begin
  421. @Display @Heading { %(HEADER1)s }
  422. @Display @I { %(HEADER2)s }
  423. @Display { %(HEADER3)s }
  424. #@NP # Break page after Headers
  425. """
  426. # @SysInclude { tbl } # Tables support
  427. # setup: @MakeContents { Yes } # show TOC
  428. # setup: @SectionGap # break page at each section
  429. }
  430. ##############################################################################
  431. def getTags(config):
  432. "Returns all the known tags for the specified target"
  433. keys = """
  434. title1 numtitle1
  435. title2 numtitle2
  436. title3 numtitle3
  437. title4 numtitle4
  438. title5 numtitle5
  439. title1Open title1Close
  440. title2Open title2Close
  441. title3Open title3Close
  442. title4Open title4Close
  443. title5Open title5Close
  444. blocktitle1Open blocktitle1Close
  445. blocktitle2Open blocktitle2Close
  446. blocktitle3Open blocktitle3Close
  447. paragraphOpen paragraphClose
  448. blockVerbOpen blockVerbClose
  449. blockQuoteOpen blockQuoteClose blockQuoteLine
  450. blockCommentOpen blockCommentClose
  451. fontMonoOpen fontMonoClose
  452. fontBoldOpen fontBoldClose
  453. fontItalicOpen fontItalicClose
  454. fontUnderlineOpen fontUnderlineClose
  455. fontStrikeOpen fontStrikeClose
  456. listOpen listClose
  457. listItemOpen listItemClose listItemLine
  458. numlistOpen numlistClose
  459. numlistItemOpen numlistItemClose numlistItemLine
  460. deflistOpen deflistClose
  461. deflistItem1Open deflistItem1Close
  462. deflistItem2Open deflistItem2Close deflistItem2LinePrefix
  463. bar1 bar2
  464. url urlMark
  465. email emailMark
  466. img imgAlignLeft imgAlignRight imgAlignCenter
  467. _imgAlignLeft _imgAlignRight _imgAlignCenter
  468. tableOpen tableClose
  469. _tableBorder _tableAlignLeft _tableAlignCenter
  470. tableRowOpen tableRowClose tableRowSep
  471. tableTitleRowOpen tableTitleRowClose
  472. tableCellOpen tableCellClose tableCellSep
  473. tableTitleCellOpen tableTitleCellClose tableTitleCellSep
  474. _tableColAlignLeft _tableColAlignRight _tableColAlignCenter
  475. _tableCellAlignLeft _tableCellAlignRight _tableCellAlignCenter
  476. _tableCellColSpan tableColAlignSep
  477. bodyOpen bodyClose
  478. cssOpen cssClose
  479. tocOpen tocClose TOC
  480. anchor
  481. comment
  482. pageBreak
  483. EOD
  484. """.split()
  485. # TIP: \a represents the current text on the mark
  486. # TIP: ~A~, ~B~ and ~C~ are expanded to other tags parts
  487. alltags = {
  488. 'txt': {
  489. 'title1' : ' \a' ,
  490. 'title2' : '\t\a' ,
  491. 'title3' : '\t\t\a' ,
  492. 'title4' : '\t\t\t\a' ,
  493. 'title5' : '\t\t\t\t\a',
  494. 'blockQuoteLine' : '\t' ,
  495. 'listItemOpen' : '- ' ,
  496. 'numlistItemOpen' : '\a. ' ,
  497. 'bar1' : '\a' ,
  498. 'url' : '\a' ,
  499. 'urlMark' : '\a (\a)' ,
  500. 'email' : '\a' ,
  501. 'emailMark' : '\a (\a)' ,
  502. 'img' : '[\a]' ,
  503. },
  504. 'html': {
  505. 'paragraphOpen' : '<P>' ,
  506. 'paragraphClose' : '</P>' ,
  507. 'title1' : '~A~<H1>\a</H1>' ,
  508. 'title2' : '~A~<H2>\a</H2>' ,
  509. 'title3' : '~A~<H3>\a</H3>' ,
  510. 'title4' : '~A~<H4>\a</H4>' ,
  511. 'title5' : '~A~<H5>\a</H5>' ,
  512. 'anchor' : '<A NAME="\a"></A>\n',
  513. 'blockVerbOpen' : '<PRE>' ,
  514. 'blockVerbClose' : '</PRE>' ,
  515. 'blockQuoteOpen' : '<BLOCKQUOTE>' ,
  516. 'blockQuoteClose' : '</BLOCKQUOTE>' ,
  517. 'fontMonoOpen' : '<CODE>' ,
  518. 'fontMonoClose' : '</CODE>' ,
  519. 'fontBoldOpen' : '<B>' ,
  520. 'fontBoldClose' : '</B>' ,
  521. 'fontItalicOpen' : '<I>' ,
  522. 'fontItalicClose' : '</I>' ,
  523. 'fontUnderlineOpen' : '<U>' ,
  524. 'fontUnderlineClose' : '</U>' ,
  525. 'fontStrikeOpen' : '<S>' ,
  526. 'fontStrikeClose' : '</S>' ,
  527. 'listOpen' : '<UL>' ,
  528. 'listClose' : '</UL>' ,
  529. 'listItemOpen' : '<LI>' ,
  530. 'numlistOpen' : '<OL>' ,
  531. 'numlistClose' : '</OL>' ,
  532. 'numlistItemOpen' : '<LI>' ,
  533. 'deflistOpen' : '<DL>' ,
  534. 'deflistClose' : '</DL>' ,
  535. 'deflistItem1Open' : '<DT>' ,
  536. 'deflistItem1Close' : '</DT>' ,
  537. 'deflistItem2Open' : '<DD>' ,
  538. 'bar1' : '<HR NOSHADE SIZE=1>' ,
  539. 'bar2' : '<HR NOSHADE SIZE=5>' ,
  540. 'url' : '<A HREF="\a">\a</A>' ,
  541. 'urlMark' : '<A HREF="\a">\a</A>' ,
  542. 'email' : '<A HREF="mailto:\a">\a</A>' ,
  543. 'emailMark' : '<A HREF="mailto:\a">\a</A>' ,
  544. 'img' : '<IMG~A~ SRC="\a" BORDER="0" ALT="">',
  545. '_imgAlignLeft' : ' ALIGN="left"' ,
  546. '_imgAlignCenter' : ' ALIGN="middle"',
  547. '_imgAlignRight' : ' ALIGN="right"' ,
  548. 'tableOpen' : '<TABLE~A~~B~ CELLPADDING="4">',
  549. 'tableClose' : '</TABLE>' ,
  550. 'tableRowOpen' : '<TR>' ,
  551. 'tableRowClose' : '</TR>' ,
  552. 'tableCellOpen' : '<TD~A~~S~>' ,
  553. 'tableCellClose' : '</TD>' ,
  554. 'tableTitleCellOpen' : '<TH~S~>' ,
  555. 'tableTitleCellClose' : '</TH>' ,
  556. '_tableBorder' : ' BORDER="1"' ,
  557. '_tableAlignCenter' : ' ALIGN="center"',
  558. '_tableCellAlignRight' : ' ALIGN="right"' ,
  559. '_tableCellAlignCenter': ' ALIGN="center"',
  560. '_tableCellColSpan' : ' COLSPAN="\a"' ,
  561. 'cssOpen' : '<STYLE TYPE="text/css">',
  562. 'cssClose' : '</STYLE>' ,
  563. 'comment' : '<!-- \a -->' ,
  564. 'EOD' : '</BODY></HTML>'
  565. },
  566. #TIP xhtml inherits all HTML definitions (lowercased)
  567. #TIP http://www.w3.org/TR/xhtml1/#guidelines
  568. #TIP http://www.htmlref.com/samples/Chapt17/17_08.htm
  569. 'xhtml': {
  570. 'listItemClose' : '</li>' ,
  571. 'numlistItemClose' : '</li>' ,
  572. 'deflistItem2Close' : '</dd>' ,
  573. 'bar1' : '<hr class="light" />',
  574. 'bar2' : '<hr class="heavy" />',
  575. 'anchor' : '<a id="\a" name="\a"></a>\n',
  576. 'img' : '<img~A~ src="\a" border="0" alt=""/>',
  577. },
  578. 'sgml': {
  579. 'paragraphOpen' : '<p>' ,
  580. 'title1' : '<sect>\a~A~<p>' ,
  581. 'title2' : '<sect1>\a~A~<p>' ,
  582. 'title3' : '<sect2>\a~A~<p>' ,
  583. 'title4' : '<sect3>\a~A~<p>' ,
  584. 'title5' : '<sect4>\a~A~<p>' ,
  585. 'anchor' : '<label id="\a">' ,
  586. 'blockVerbOpen' : '<tscreen><verb>' ,
  587. 'blockVerbClose' : '</verb></tscreen>' ,
  588. 'blockQuoteOpen' : '<quote>' ,
  589. 'blockQuoteClose' : '</quote>' ,
  590. 'fontMonoOpen' : '<tt>' ,
  591. 'fontMonoClose' : '</tt>' ,
  592. 'fontBoldOpen' : '<bf>' ,
  593. 'fontBoldClose' : '</bf>' ,
  594. 'fontItalicOpen' : '<em>' ,
  595. 'fontItalicClose' : '</em>' ,
  596. 'fontUnderlineOpen' : '<bf><em>' ,
  597. 'fontUnderlineClose' : '</em></bf>' ,
  598. 'listOpen' : '<itemize>' ,
  599. 'listClose' : '</itemize>' ,
  600. 'listItemOpen' : '<item>' ,
  601. 'numlistOpen' : '<enum>' ,
  602. 'numlistClose' : '</enum>' ,
  603. 'numlistItemOpen' : '<item>' ,
  604. 'deflistOpen' : '<descrip>' ,
  605. 'deflistClose' : '</descrip>' ,
  606. 'deflistItem1Open' : '<tag>' ,
  607. 'deflistItem1Close' : '</tag>' ,
  608. 'bar1' : '<!-- \a -->' ,
  609. 'url' : '<htmlurl url="\a" name="\a">' ,
  610. 'urlMark' : '<htmlurl url="\a" name="\a">' ,
  611. 'email' : '<htmlurl url="mailto:\a" name="\a">' ,
  612. 'emailMark' : '<htmlurl url="mailto:\a" name="\a">' ,
  613. 'img' : '<figure><ph vspace=""><img src="\a">'+\
  614. '</figure>' ,
  615. 'tableOpen' : '<table><tabular ca="~C~">' ,
  616. 'tableClose' : '</tabular></table>' ,
  617. 'tableRowSep' : '<rowsep>' ,
  618. 'tableCellSep' : '<colsep>' ,
  619. '_tableColAlignLeft' : 'l' ,
  620. '_tableColAlignRight' : 'r' ,
  621. '_tableColAlignCenter': 'c' ,
  622. 'comment' : '<!-- \a -->' ,
  623. 'TOC' : '<toc>' ,
  624. 'EOD' : '</article>'
  625. },
  626. 'tex': {
  627. 'title1' : '\n~A~\section*{\a}' ,
  628. 'title2' : '~A~\\subsection*{\a}' ,
  629. 'title3' : '~A~\\subsubsection*{\a}',
  630. # title 4/5: DIRTY: para+BF+\\+\n
  631. 'title4' : '~A~\\paragraph{}\\textbf{\a}\\\\\n',
  632. 'title5' : '~A~\\paragraph{}\\textbf{\a}\\\\\n',
  633. 'numtitle1' : '\n~A~\section{\a}' ,
  634. 'numtitle2' : '~A~\\subsection{\a}' ,
  635. 'numtitle3' : '~A~\\subsubsection{\a}' ,
  636. 'anchor' : '\\hypertarget{\a}{}\n' ,
  637. 'blockVerbOpen' : '\\begin{verbatim}' ,
  638. 'blockVerbClose' : '\\end{verbatim}' ,
  639. 'blockQuoteOpen' : '\\begin{quotation}' ,
  640. 'blockQuoteClose' : '\\end{quotation}' ,
  641. 'fontMonoOpen' : '\\texttt{' ,
  642. 'fontMonoClose' : '}' ,
  643. 'fontBoldOpen' : '\\textbf{' ,
  644. 'fontBoldClose' : '}' ,
  645. 'fontItalicOpen' : '\\textit{' ,
  646. 'fontItalicClose' : '}' ,
  647. 'fontUnderlineOpen' : '\\underline{' ,
  648. 'fontUnderlineClose' : '}' ,
  649. 'fontStrikeOpen' : '\\sout{' ,
  650. 'fontStrikeClose' : '}' ,
  651. 'listOpen' : '\\begin{itemize}' ,
  652. 'listClose' : '\\end{itemize}' ,
  653. 'listItemOpen' : '\\item ' ,
  654. 'numlistOpen' : '\\begin{enumerate}' ,
  655. 'numlistClose' : '\\end{enumerate}' ,
  656. 'numlistItemOpen' : '\\item ' ,
  657. 'deflistOpen' : '\\begin{description}',
  658. 'deflistClose' : '\\end{description}' ,
  659. 'deflistItem1Open' : '\\item[' ,
  660. 'deflistItem1Close' : ']' ,
  661. 'bar1' : '\n\\hrulefill{}\n' ,
  662. 'bar2' : '\n\\rule{\linewidth}{1mm}\n',
  663. 'url' : '\\htmladdnormallink{\a}{\a}',
  664. 'urlMark' : '\\htmladdnormallink{\a}{\a}',
  665. 'email' : '\\htmladdnormallink{\a}{mailto:\a}',
  666. 'emailMark' : '\\htmladdnormallink{\a}{mailto:\a}',
  667. 'img' : '\\includegraphics{\a}',
  668. 'tableOpen' : '\\begin{center}\\begin{tabular}{|~C~|}',
  669. 'tableClose' : '\\end{tabular}\\end{center}',
  670. 'tableRowOpen' : '\\hline ' ,
  671. 'tableRowClose' : ' \\\\' ,
  672. 'tableCellSep' : ' & ' ,
  673. '_tableColAlignLeft' : 'l' ,
  674. '_tableColAlignRight' : 'r' ,
  675. '_tableColAlignCenter': 'c' ,
  676. 'tableColAlignSep' : '|' ,
  677. 'comment' : '% \a' ,
  678. 'TOC' : '\\tableofcontents',
  679. 'pageBreak' : '\\clearpage',
  680. 'EOD' : '\\end{document}'
  681. },
  682. 'lout': {
  683. 'paragraphOpen' : '@LP' ,
  684. 'blockTitle1Open' : '@BeginSections' ,
  685. 'blockTitle1Close' : '@EndSections' ,
  686. 'blockTitle2Open' : ' @BeginSubSections' ,
  687. 'blockTitle2Close' : ' @EndSubSections' ,
  688. 'blockTitle3Open' : ' @BeginSubSubSections' ,
  689. 'blockTitle3Close' : ' @EndSubSubSections' ,
  690. 'title1Open' : '\n~A~@Section @Title { \a } @Begin',
  691. 'title1Close' : '@End @Section' ,
  692. 'title2Open' : '\n~A~ @SubSection @Title { \a } @Begin',
  693. 'title2Close' : ' @End @SubSection' ,
  694. 'title3Open' : '\n~A~ @SubSubSection @Title { \a } @Begin',
  695. 'title3Close' : ' @End @SubSubSection' ,
  696. 'title4Open' : '\n~A~@LP @LeftDisplay @B { \a }',
  697. 'title5Open' : '\n~A~@LP @LeftDisplay @B { \a }',
  698. 'anchor' : '@Tag { \a }\n' ,
  699. 'blockVerbOpen' : '@LP @ID @F @RawVerbatim @Begin',
  700. 'blockVerbClose' : '@End @RawVerbatim' ,
  701. 'blockQuoteOpen' : '@QD {' ,
  702. 'blockQuoteClose' : '}' ,
  703. # enclosed inside {} to deal with joined**words**
  704. 'fontMonoOpen' : '{@F {' ,
  705. 'fontMonoClose' : '}}' ,
  706. 'fontBoldOpen' : '{@B {' ,
  707. 'fontBoldClose' : '}}' ,
  708. 'fontItalicOpen' : '{@II {' ,
  709. 'fontItalicClose' : '}}' ,
  710. 'fontUnderlineOpen' : '{@Underline{' ,
  711. 'fontUnderlineClose' : '}}' ,
  712. # the full form is more readable, but could be BL EL LI NL TL DTI
  713. 'listOpen' : '@BulletList' ,
  714. 'listClose' : '@EndList' ,
  715. 'listItemOpen' : '@ListItem{' ,
  716. 'listItemClose' : '}' ,
  717. 'numlistOpen' : '@NumberedList' ,
  718. 'numlistClose' : '@EndList' ,
  719. 'numlistItemOpen' : '@ListItem{' ,
  720. 'numlistItemClose' : '}' ,
  721. 'deflistOpen' : '@TaggedList' ,
  722. 'deflistClose' : '@EndList' ,
  723. 'deflistItem1Open' : '@DropTagItem {' ,
  724. 'deflistItem1Close' : '}' ,
  725. 'deflistItem2Open' : '{' ,
  726. 'deflistItem2Close' : '}' ,
  727. 'bar1' : '\n@DP @FullWidthRule\n' ,
  728. 'url' : '{blue @Colour { \a }}' ,
  729. 'urlMark' : '\a ({blue @Colour { \a }})' ,
  730. 'email' : '{blue @Colour { \a }}' ,
  731. 'emailMark' : '\a ({blue Colour{ \a }})' ,
  732. 'img' : '~A~@IncludeGraphic { \a }' , # eps only!
  733. '_imgAlignLeft' : '@LeftDisplay ' ,
  734. '_imgAlignRight' : '@RightDisplay ' ,
  735. '_imgAlignCenter' : '@CentredDisplay ' ,
  736. # lout tables are *way* complicated, no support for now
  737. #'tableOpen' : '~A~@Tbl~B~\naformat{ @Cell A | @Cell B } {',
  738. #'tableClose' : '}' ,
  739. #'tableRowOpen' : '@Rowa\n' ,
  740. #'tableTitleRowOpen' : '@HeaderRowa' ,
  741. #'tableCenterAlign' : '@CentredDisplay ' ,
  742. #'tableCellOpen' : '\a {' , # A, B, ...
  743. #'tableCellClose' : '}' ,
  744. #'_tableBorder' : '\nrule {yes}' ,
  745. 'comment' : '# \a' ,
  746. # @MakeContents must be on the config file
  747. 'TOC' : '@DP @ContentsGoesHere @DP',
  748. 'pageBreak' : '\n@NP\n' ,
  749. 'EOD' : '@End @Text'
  750. },
  751. # http://moinmo.in/SyntaxReference
  752. 'moin': {
  753. 'title1' : '= \a =' ,
  754. 'title2' : '== \a ==' ,
  755. 'title3' : '=== \a ===' ,
  756. 'title4' : '==== \a ====' ,
  757. 'title5' : '===== \a =====',
  758. 'blockVerbOpen' : '{{{' ,
  759. 'blockVerbClose' : '}}}' ,
  760. 'blockQuoteLine' : ' ' ,
  761. 'fontMonoOpen' : '{{{' ,
  762. 'fontMonoClose' : '}}}' ,
  763. 'fontBoldOpen' : "'''" ,
  764. 'fontBoldClose' : "'''" ,
  765. 'fontItalicOpen' : "''" ,
  766. 'fontItalicClose' : "''" ,
  767. 'fontUnderlineOpen' : '__' ,
  768. 'fontUnderlineClose' : '__' ,
  769. 'fontStrikeOpen' : '--(' ,
  770. 'fontStrikeClose' : ')--' ,
  771. 'listItemOpen' : ' * ' ,
  772. 'numlistItemOpen' : ' \a. ' ,
  773. 'deflistItem1Open' : ' ' ,
  774. 'deflistItem1Close' : '::' ,
  775. 'deflistItem2LinePrefix': ' :: ' ,
  776. 'bar1' : '----' ,
  777. 'bar2' : '--------' ,
  778. 'url' : '[\a]' ,
  779. 'urlMark' : '[\a \a]' ,
  780. 'email' : '[\a]' ,
  781. 'emailMark' : '[\a \a]' ,
  782. 'img' : '[\a]' ,
  783. 'tableRowOpen' : '||' ,
  784. 'tableCellOpen' : '~A~' ,
  785. 'tableCellClose' : '||' ,
  786. 'tableTitleCellClose' : '||' ,
  787. '_tableCellAlignRight' : '<)>' ,
  788. '_tableCellAlignCenter' : '<:>' ,
  789. 'comment' : '/* \a */' ,
  790. 'TOC' : '[[TableOfContents]]'
  791. },
  792. # http://code.google.com/p/support/wiki/WikiSyntax
  793. 'gwiki': {
  794. 'title1' : '= \a =' ,
  795. 'title2' : '== \a ==' ,
  796. 'title3' : '=== \a ===' ,
  797. 'title4' : '==== \a ====' ,
  798. 'title5' : '===== \a =====',
  799. 'blockVerbOpen' : '{{{' ,
  800. 'blockVerbClose' : '}}}' ,
  801. 'blockQuoteLine' : ' ' ,
  802. 'fontMonoOpen' : '{{{' ,
  803. 'fontMonoClose' : '}}}' ,
  804. 'fontBoldOpen' : '*' ,
  805. 'fontBoldClose' : '*' ,
  806. 'fontItalicOpen' : '_' , # underline == italic
  807. 'fontItalicClose' : '_' ,
  808. 'fontStrikeOpen' : '~~' ,
  809. 'fontStrikeClose' : '~~' ,
  810. 'listItemOpen' : ' * ' ,
  811. 'numlistItemOpen' : ' # ' ,
  812. 'url' : '\a' ,
  813. 'urlMark' : '[\a \a]' ,
  814. 'email' : 'mailto:\a' ,
  815. 'emailMark' : '[mailto:\a \a]',
  816. 'img' : '[\a]' ,
  817. 'tableRowOpen' : '|| ' ,
  818. 'tableRowClose' : ' ||' ,
  819. 'tableCellSep' : ' || ' ,
  820. },
  821. # http://wiki.splitbrain.org/wiki:syntax
  822. # Hint: <br> is \\ $
  823. # Hint: You can add footnotes ((This is a footnote))
  824. 'doku': {
  825. 'title1' : '===== \a =====',
  826. 'title2' : '==== \a ====' ,
  827. 'title3' : '=== \a ===' ,
  828. 'title4' : '== \a ==' ,
  829. 'title5' : '= \a =' ,
  830. # DokuWiki uses ' ' identation to mark verb blocks (see indentverbblock)
  831. 'blockQuoteLine' : '>' ,
  832. 'fontMonoOpen' : "''" ,
  833. 'fontMonoClose' : "''" ,
  834. 'fontBoldOpen' : "**" ,
  835. 'fontBoldClose' : "**" ,
  836. 'fontItalicOpen' : "//" ,
  837. 'fontItalicClose' : "//" ,
  838. 'fontUnderlineOpen' : "__" ,
  839. 'fontUnderlineClose' : "__" ,
  840. 'fontStrikeOpen' : '<del>' ,
  841. 'fontStrikeClose' : '</del>' ,
  842. 'listItemOpen' : ' * ' ,
  843. 'numlistItemOpen' : ' - ' ,
  844. 'bar1' : '----' ,
  845. 'url' : '[[\a]]' ,
  846. 'urlMark' : '[[\a|\a]]' ,
  847. 'email' : '[[\a]]' ,
  848. 'emailMark' : '[[\a|\a]]' ,
  849. 'img' : '{{\a}}' ,
  850. 'imgAlignLeft' : '{{\a }}' ,
  851. 'imgAlignRight' : '{{ \a}}' ,
  852. 'imgAlignCenter' : '{{ \a }}' ,
  853. 'tableTitleRowOpen' : '^ ' ,
  854. 'tableTitleRowClose' : ' ^' ,
  855. 'tableTitleCellSep' : ' ^ ' ,
  856. 'tableRowOpen' : '| ' ,
  857. 'tableRowClose' : ' |' ,
  858. 'tableCellSep' : ' | ' ,
  859. # DokuWiki has no attributes. The content must be aligned!
  860. # '_tableCellAlignRight' : '<)>' , # ??
  861. # '_tableCellAlignCenter': '<:>' , # ??
  862. # DokuWiki colspan is the same as txt2tags' with multiple |||
  863. # 'comment' : '## \a' , # ??
  864. # TOC is automatic
  865. },
  866. # http://en.wikipedia.org/wiki/Help:Editing
  867. 'wiki': {
  868. 'title1' : '== \a ==' ,
  869. 'title2' : '=== \a ===' ,
  870. 'title3' : '==== \a ====' ,
  871. 'title4' : '===== \a =====' ,
  872. 'title5' : '====== \a ======',
  873. 'blockVerbOpen' : '<pre>' ,
  874. 'blockVerbClose' : '</pre>' ,
  875. 'blockQuoteOpen' : '<blockquote>' ,
  876. 'blockQuoteClose' : '</blockquote>' ,
  877. 'fontMonoOpen' : '<tt>' ,
  878. 'fontMonoClose' : '</tt>' ,
  879. 'fontBoldOpen' : "'''" ,
  880. 'fontBoldClose' : "'''" ,
  881. 'fontItalicOpen' : "''" ,
  882. 'fontItalicClose' : "''" ,
  883. 'fontUnderlineOpen' : '<u>' ,
  884. 'fontUnderlineClose' : '</u>' ,
  885. 'fontStrikeOpen' : '<s>' ,
  886. 'fontStrikeClose' : '</s>' ,
  887. #XXX Mixed lists not working: *#* list inside numlist inside list
  888. 'listItemLine' : '*' ,
  889. 'numlistItemLine' : '#' ,
  890. 'deflistItem1Open' : '; ' ,
  891. 'deflistItem2LinePrefix': ': ' ,
  892. 'bar1' : '----' ,
  893. 'url' : '[\a]' ,
  894. 'urlMark' : '[\a \a]' ,
  895. 'email' : 'mailto:\a' ,
  896. 'emailMark' : '[mailto:\a \a]' ,
  897. # [[Image:foo.png|right|Optional alt/caption text]] (right, left, center, none)
  898. 'img' : '[[Image:\a~A~]]' ,
  899. '_imgAlignLeft' : '|left' ,
  900. '_imgAlignCenter' : '|center' ,
  901. '_imgAlignRight' : '|right' ,
  902. # {| border="1" cellspacing="0" cellpadding="4" align="center"
  903. 'tableOpen' : '{|~A~~B~ cellpadding="4"',
  904. 'tableClose' : '|}' ,
  905. 'tableRowOpen' : '|-\n| ' ,
  906. 'tableTitleRowOpen' : '|-\n! ' ,
  907. 'tableCellSep' : ' || ' ,
  908. 'tableTitleCellSep' : ' !! ' ,
  909. '_tableBorder' : ' border="1"' ,
  910. '_tableAlignCenter' : ' align="center"' ,
  911. 'comment' : '<!-- \a -->' ,
  912. 'TOC' : '__TOC__' ,
  913. },
  914. # http://www.inference.phy.cam.ac.uk/mackay/mgp/SYNTAX
  915. # http://en.wikipedia.org/wiki/MagicPoint
  916. 'mgp': {
  917. 'paragraphOpen' : '%font "normal", size 5' ,
  918. 'title1' : '%page\n\n\a\n' ,
  919. 'title2' : '%page\n\n\a\n' ,
  920. 'title3' : '%page\n\n\a\n' ,
  921. 'title4' : '%page\n\n\a\n' ,
  922. 'title5' : '%page\n\n\a\n' ,
  923. 'blockVerbOpen' : '%font "mono"' ,
  924. 'blockVerbClose' : '%font "normal"' ,
  925. 'blockQuoteOpen' : '%prefix " "' ,
  926. 'blockQuoteClose' : '%prefix " "' ,
  927. 'fontMonoOpen' : '\n%cont, font "mono"\n' ,
  928. 'fontMonoClose' : '\n%cont, font "normal"\n' ,
  929. 'fontBoldOpen' : '\n%cont, font "normal-b"\n' ,
  930. 'fontBoldClose' : '\n%cont, font "normal"\n' ,
  931. 'fontItalicOpen' : '\n%cont, font "normal-i"\n' ,
  932. 'fontItalicClose' : '\n%cont, font "normal"\n' ,
  933. 'fontUnderlineOpen' : '\n%cont, fore "cyan"\n' ,
  934. 'fontUnderlineClose' : '\n%cont, fore "white"\n' ,
  935. 'listItemLine' : '\t' ,
  936. 'numlistItemLine' : '\t' ,
  937. 'numlistItemOpen' : '\a. ' ,
  938. 'deflistItem1Open' : '\t\n%cont, font "normal-b"\n',
  939. 'deflistItem1Close' : '\n%cont, font "normal"\n' ,
  940. 'bar1' : '%bar "white" 5' ,
  941. 'bar2' : '%pause' ,
  942. 'url' : '\n%cont, fore "cyan"\n\a' +\
  943. '\n%cont, fore "white"\n' ,
  944. 'urlMark' : '\a \n%cont, fore "cyan"\n\a'+\
  945. '\n%cont, fore "white"\n' ,
  946. 'email' : '\n%cont, fore "cyan"\n\a' +\
  947. '\n%cont, fore "white"\n' ,
  948. 'emailMark' : '\a \n%cont, fore "cyan"\n\a'+\
  949. '\n%cont, fore "white"\n' ,
  950. 'img' : '~A~\n%newimage "\a"\n%left\n',
  951. '_imgAlignLeft' : '\n%left' ,
  952. '_imgAlignRight' : '\n%right' ,
  953. '_imgAlignCenter' : '\n%center' ,
  954. 'comment' : '%% \a' ,
  955. 'pageBreak' : '%page\n\n\n' ,
  956. 'EOD' : '%%EOD'
  957. },
  958. # man groff_man ; man 7 groff
  959. 'man': {
  960. 'paragraphOpen' : '.P' ,
  961. 'title1' : '.SH \a' ,
  962. 'title2' : '.SS \a' ,
  963. 'title3' : '.SS \a' ,
  964. 'title4' : '.SS \a' ,
  965. 'title5' : '.SS \a' ,
  966. 'blockVerbOpen' : '.nf' ,
  967. 'blockVerbClose' : '.fi\n' ,
  968. 'blockQuoteOpen' : '.RS' ,
  969. 'blockQuoteClose' : '.RE' ,
  970. 'fontBoldOpen' : '\\fB' ,
  971. 'fontBoldClose' : '\\fR' ,
  972. 'fontItalicOpen' : '\\fI' ,
  973. 'fontItalicClose' : '\\fR' ,
  974. 'listOpen' : '.RS' ,
  975. 'listItemOpen' : '.IP \(bu 3\n',
  976. 'listClose' : '.RE' ,
  977. 'numlistOpen' : '.RS' ,
  978. 'numlistItemOpen' : '.IP \a. 3\n',
  979. 'numlistClose' : '.RE' ,
  980. 'deflistItem1Open' : '.TP\n' ,
  981. 'bar1' : '\n\n' ,
  982. 'url' : '\a' ,
  983. 'urlMark' : '\a (\a)',
  984. 'email' : '\a' ,
  985. 'emailMark' : '\a (\a)',
  986. 'img' : '\a' ,
  987. 'tableOpen' : '.TS\n~A~~B~tab(^); ~C~.',
  988. 'tableClose' : '.TE' ,
  989. 'tableRowOpen' : ' ' ,
  990. 'tableCellSep' : '^' ,
  991. '_tableAlignCenter' : 'center, ',
  992. '_tableBorder' : 'allbox, ',
  993. '_tableColAlignLeft' : 'l' ,
  994. '_tableColAlignRight' : 'r' ,
  995. '_tableColAlignCenter': 'c' ,
  996. 'comment' : '.\\" \a'
  997. },
  998. 'pm6': {
  999. 'paragraphOpen' : '<@Normal:>' ,
  1000. 'title1' : '\n<@Title1:>\a',
  1001. 'title2' : '\n<@Title2:>\a',
  1002. 'title3' : '\n<@Title3:>\a',
  1003. 'title4' : '\n<@Title4:>\a',
  1004. 'title5' : '\n<@Title5:>\a',
  1005. 'blockVerbOpen' : '<@PreFormat:>' ,
  1006. 'blockQuoteLine' : '<@Quote:>' ,
  1007. 'fontMonoOpen' : '<FONT "Lucida Console"><SIZE 9>' ,
  1008. 'fontMonoClose' : '<SIZE$><FONT$>',
  1009. 'fontBoldOpen' : '<B>' ,
  1010. 'fontBoldClose' : '<P>' ,
  1011. 'fontItalicOpen' : '<I>' ,
  1012. 'fontItalicClose' : '<P>' ,
  1013. 'fontUnderlineOpen' : '<U>' ,
  1014. 'fontUnderlineClose' : '<P>' ,
  1015. 'listOpen' : '<@Bullet:>' ,
  1016. 'listItemOpen' : '\x95\t' , # \x95 == ~U
  1017. 'numlistOpen' : '<@Bullet:>' ,
  1018. 'numlistItemOpen' : '\x95\t' ,
  1019. 'bar1' : '\a' ,
  1020. 'url' : '<U>\a<P>' , # underline
  1021. 'urlMark' : '\a <U>\a<P>' ,
  1022. 'email' : '\a' ,
  1023. 'emailMark' : '\a \a' ,
  1024. 'img' : '\a'
  1025. }
  1026. }
  1027. # Exceptions for --css-sugar
  1028. if config['css-sugar'] and config['target'] in ('html','xhtml'):
  1029. # Change just HTML because XHTML inherits it
  1030. htmltags = alltags['html']
  1031. # Table with no cellpadding
  1032. htmltags['tableOpen'] = string.replace(
  1033. htmltags['tableOpen'], ' CELLPADDING="4"', '')
  1034. # DIVs
  1035. htmltags['tocOpen' ] = '<DIV CLASS="toc" ID="toc">'
  1036. htmltags['tocClose'] = '</DIV>'
  1037. htmltags['bodyOpen'] = '<DIV CLASS="body" ID="body">'
  1038. htmltags['bodyClose']= '</DIV>'
  1039. # Make the HTML -> XHTML inheritance
  1040. xhtml = alltags['html'].copy()
  1041. for key in xhtml.keys(): xhtml[key] = string.lower(xhtml[key])
  1042. # Some like HTML tags as lowercase, some don't... (headers out)
  1043. if HTML_LOWER: alltags['html'] = xhtml.copy()
  1044. xhtml.update(alltags['xhtml'])
  1045. alltags['xhtml'] = xhtml.copy()
  1046. # Compose the target tags dictionary
  1047. tags = {}
  1048. target_tags = alltags[config['target']].copy()
  1049. for key in keys: tags[key] = '' # create empty keys
  1050. for key in target_tags.keys():
  1051. tags[key] = maskEscapeChar(target_tags[key]) # populate
  1052. # Map strong line to separator if not defined
  1053. if not tags['bar2'] and tags['bar1']:
  1054. tags['bar2'] = tags['bar1']
  1055. return tags
  1056. ##############################################################################
  1057. def getRules(config):
  1058. "Returns all the target-specific syntax rules"
  1059. ret = {}
  1060. allrules = [
  1061. # target rules (ON/OFF)
  1062. 'linkable', # target supports external links
  1063. 'tableable', # target supports tables
  1064. 'imglinkable', # target supports images as links
  1065. 'imgalignable', # target supports image alignment
  1066. 'imgasdefterm', # target supports image as definition term
  1067. 'autonumberlist', # target supports numbered lists natively
  1068. 'autonumbertitle', # target supports numbered titles natively
  1069. 'stylable', # target supports external style files
  1070. 'parainsidelist', # lists items supports paragraph
  1071. 'spacedlistitem', # lists support blank lines between items
  1072. 'listnotnested', # lists cannot be nested
  1073. 'quotenotnested', # quotes cannot be nested
  1074. 'verbblocknotescaped', # don't escape specials in verb block
  1075. 'verbblockfinalescape', # do final escapes in verb block
  1076. 'escapeurl', # escape special in link URL
  1077. 'onelinepara', # dump paragraph as a single long line
  1078. 'tabletitlerowinbold', # manually bold any cell on table titles
  1079. 'tablecellstrip', # strip extra spaces from each table cell
  1080. 'tablecellspannable', # the table cells can have span attribute
  1081. 'barinsidequote', # bars are allowed inside quote blocks
  1082. 'finalescapetitle', # perform final escapes on title lines
  1083. 'autotocnewpagebefore', # break page before automatic TOC
  1084. 'autotocnewpageafter', # break page after automatic TOC
  1085. 'autotocwithbars', # automatic TOC surrounded by bars
  1086. 'mapbar2pagebreak', # map the strong bar to a page break
  1087. 'titleblocks', # titles must be on open/close section blocks
  1088. # Target code beautify (ON/OFF)
  1089. 'indentverbblock', # add leading spaces to verb block lines
  1090. 'breaktablecell', # break lines after any table cell
  1091. 'breaktablelineopen', # break line after opening table line
  1092. 'breaktitleopen', # break line after any title
  1093. 'notbreaklistopen', # don't break line after opening a new list
  1094. 'notbreakparaopen', # don't break line after opening a new para
  1095. 'keepquoteindent', # don't remove the leading TABs on quotes
  1096. 'keeplistindent', # don't remove the leading spaces on lists
  1097. 'blankendmotherlist', # append a blank line at the mother list end
  1098. 'blankendtable', # append a blank line at the table end
  1099. 'blankendautotoc', # append a blank line at the auto TOC end
  1100. 'tagnotindentable', # tags must be placed at the line begining
  1101. 'spacedlistitemopen', # append a space after the list item open tag
  1102. 'spacednumlistitemopen',# append a space after the numlist item open tag
  1103. 'deflisttextstrip', # strip the contents of the deflist text
  1104. # Value settings
  1105. 'listmaxdepth', # maximum depth for lists
  1106. 'quotemaxdepth', # maximum depth for quotes
  1107. 'tablecellaligntype', # type of table cell align: cell, column
  1108. ]
  1109. rules_bank = {
  1110. 'txt' : {
  1111. 'indentverbblock':1,
  1112. 'spacedlistitem':1,
  1113. 'parainsidelist':1,
  1114. 'keeplistindent':1,
  1115. 'barinsidequote':1,
  1116. 'autotocwithbars':1,
  1117. 'blankendmotherlist':1,
  1118. },
  1119. 'html': {
  1120. 'indentverbblock':1,
  1121. 'linkable':1,
  1122. 'stylable':1,
  1123. 'escapeurl':1,
  1124. 'imglinkable':1,
  1125. 'imgalignable':1,
  1126. 'imgasdefterm':1,
  1127. 'autonumberlist':1,
  1128. 'spacedlistitem':1,
  1129. 'parainsidelist':1,
  1130. 'blankendmotherlist':1,
  1131. 'tableable':1,
  1132. 'tablecellstrip':1,
  1133. 'blankendtable':1,
  1134. 'breaktabl…

Large files files are truncated, but you can click here to view the full file