PageRenderTime 70ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/old/txt2tags-2.3.py

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

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