#!/usr/bin/env python
# txt2tags - generic text conversion tool
# http://txt2tags.sf.net
#
# Copyright 2001, 2002, 2003, 2004, 2005, 2006 Aurelio Marinho Jargas
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You have received a copy of the GNU General Public License along
# with this program, on the COPYING file.
#
########################################################################
#
# BORING CODE EXPLANATION AHEAD
#
# Just read if you wish to understand how the txt2tags code works
#
########################################################################
#
# Version 2.0 was a complete rewrite for the program 'core'.
#
# Now the code that [1] parses the marked text is separated from the
# code that [2] insert the target tags.
#
# [1] made by: def convert()
# [2] made by: class BlockMaster
#
# The structures of the marked text are identified and its contents are
# extracted into a data holder (Python lists and dictionaries).
#
# When parsing the source file, the blocks (para, lists, quote, table)
# are opened with BlockMaster, right when found. Then its contents,
# which spans on several lines, are feeded into a special holder on the
# BlockMaster instance. Just when the block is closed, the target tags
# are inserted for the full block as a whole, in one pass. This way, we
# have a better control on blocks. Much better than the previous line by
# line approach.
#
# In other words, whenever inside a block, the parser *holds* the tag
# insertion process, waiting until the full block is read. That was
# needed primary to close paragraphs for the new XHTML target, but
# proved to be a very good adding, improving many other processing.
#
# -------------------------------------------------------------------
#
# There is also a brand new code for the Configuration schema, 100%
# rewritten. There are new classes, all self documented: CommandLine,
# SourceDocument, ConfigMaster and ConfigLines. In short, a new RAW
# Config format was created, and all kind of configuration is first
# converted to this format, and then a generic method parses it.
#
# The init processing was changed also, and now the functions which
# gets informations about the input files are: get_infiles_config(),
# process_source_file() and convert_this_files()
#
# Other parts are untouched, and remains the same as in v1.7, as the
# marks regexes, target Headers and target Tags & Rules.
#
########################################################################
# Now I think the code is nice, easier to read and understand
#XXX Python coding warning
# Avoid common mistakes:
# - do NOT use newlist=list instead newlist=list[:]
# - do NOT use newdic=dic instead newdic=dic.copy()
# - do NOT use dic[key] instead dic.get(key)
# - do NOT use del dic[key] without has_key() before
#XXX Smart Image Align don't work if the image is a link
# Can't fix that because the image is expanded together with the
# link, at the linkbank filling moment. Only the image is passed
# to parse_images(), not the full line, so it is always 'middle'.
#XXX Paragraph separation not valid inside Quote
# Quote will not have <p></p> inside, instead will close and open
# again the <blockquote>. This really sux in CSS, when defining a
# different background color. Still don't know how to fix it.
#XXX TODO (maybe)
# New mark or macro which expands to an anchor full title.
# It is necessary to parse the full document in this order:
# DONE 1st scan: HEAD: get all settings, including %!includeconf
# DONE 2nd scan: BODY: expand includes & apply %!preproc
# 3rd scan: BODY: read titles and compose TOC info
# 4th scan: BODY: full parsing, expanding [#anchor] 1st
# Steps 2 and 3 can be made together, with no tag adding.
# Two complete body scans will be *slow*, don't know if it worths.
# One solution may be add the titles as postproc rules
##############################################################################
# User config (1=ON, 0=OFF)
USE_I18N = 1 # use gettext for i18ned messages? (default is 1)
COLOR_DEBUG = 1 # show debug messages in colors? (default is 1)
BG_LIGHT = 0 # your terminal background color is light (default is 0)
HTML_LOWER = 0 # use lowercased HTML tags instead upper? (default is 0)
##############################################################################
# These are all the core Python modules used by txt2tags (KISS!)
import re, string, os, sys, time, getopt
# Program information
my_url = 'http://txt2tags.sf.net'
my_name = 'txt2tags'
my_email = 'verde@aurelio.net'
my_version = '2.4'
# i18n - just use if available
if USE_I18N:
try:
import gettext
# If your locale dir is different, change it here
cat = gettext.Catalog('txt2tags',localedir='/usr/share/locale/')
_ = cat.gettext
except:
_ = lambda x:x
else:
_ = lambda x:x
# FLAGS : the conversion related flags , may be used in %!options
# OPTIONS : the conversion related options, may be used in %!options
# ACTIONS : the other behavior modifiers, valid on command line only
# MACROS : the valid macros with their default values for formatting
# SETTINGS: global miscellaneous settings, valid on RC file only
# NO_TARGET: actions that don't require a target specification
# NO_MULTI_INPUT: actions that don't accept more than one input file
# CONFIG_KEYWORDS: the valid %!key:val keywords
#
# FLAGS and OPTIONS are configs that affect the converted document.
# They usually have also a --no-<option> to turn them OFF.
# ACTIONS are needed because when doing multiple input files, strange
# behavior would be found, as use command line interface for the
# first file and gui for the second. There is no --no-<action>.
# --version and --help inside %!options are also odd
#
TARGETS = ['html', 'xhtml', 'sgml', 'tex', 'lout', 'man', 'mgp',
'moin', 'pm6' , 'txt']
FLAGS = {'headers' :1 , 'enum-title' :0 , 'mask-email' :0 ,
'toc-only' :0 , 'toc' :0 , 'rc' :1 ,
'css-sugar' :0 , 'css-suggar' :0 , 'css-inside' :0 ,
'quiet' :0 }
OPTIONS = {'target' :'', 'toc-level' :3 , 'style' :'',
'infile' :'', 'outfile' :'', 'encoding' :'',
'config-file':'', 'split' :0 , 'lang' :''}
ACTIONS = {'help' :0 , 'version' :0 , 'gui' :0 ,
'verbose' :0 , 'debug' :0 , 'dump-config':0 ,
'dump-source':0 }
MACROS = {'date' : '%Y%m%d', 'infile': '%f',
'mtime': '%Y%m%d', 'outfile': '%f'}
SETTINGS = {} # for future use
NO_TARGET = ['help', 'version', 'gui', 'toc-only', 'dump-config', 'dump-source']
NO_MULTI_INPUT = ['gui','dump-config','dump-source']
CONFIG_KEYWORDS = [
'target', 'encoding', 'style', 'options', 'preproc','postproc',
'guicolors']
TARGET_NAMES = {
'html' : _('HTML page'),
'xhtml': _('XHTML page'),
'sgml' : _('SGML document'),
'tex' : _('LaTeX document'),
'lout' : _('Lout document'),
'man' : _('UNIX Manual page'),
'mgp' : _('MagicPoint presentation'),
'moin' : _('MoinMoin page'),
'pm6' : _('PageMaker document'),
'txt' : _('Plain Text'),
}
DEBUG = 0 # do not edit here, please use --debug
VERBOSE = 0 # do not edit here, please use -v, -vv or -vvv
QUIET = 0 # do not edit here, please use --quiet
GUI = 0 # do not edit here, please use --gui
AUTOTOC = 1 # do not edit here, please use --no-toc or %%toc
RC_RAW = []
CMDLINE_RAW = []
CONF = {}
BLOCK = None
regex = {}
TAGS = {}
rules = {}
lang = 'english'
TARGET = ''
STDIN = STDOUT = '-'
MODULEIN =
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Python Standard Lib (220个子文件)
style.css 2KB
book.html 412KB
txt2tags.py 155KB
book.t2t 27KB
sect2.t2t 21KB
sect4.t2t 15KB
sect4.t2t 11KB
sect13.t2t 9KB
sect15.t2t 9KB
sect5.t2t 8KB
sect4.t2t 7KB
sect1.t2t 7KB
sect2.t2t 6KB
sect5.t2t 6KB
sect3.t2t 6KB
sect19.t2t 5KB
sect8.t2t 5KB
sect23.t2t 5KB
sect4.t2t 4KB
sect2.t2t 4KB
sect3.t2t 4KB
preface.t2t 4KB
sect7.t2t 4KB
sect17.t2t 4KB
sect11.t2t 3KB
sect1.t2t 3KB
sect17.t2t 3KB
sect7.t2t 3KB
sect10.t2t 3KB
sect11.t2t 3KB
sect5.t2t 3KB
sect10.t2t 3KB
sect2.t2t 3KB
sect24.t2t 3KB
sect11.t2t 3KB
sect8.t2t 3KB
sect11.t2t 3KB
sect2.t2t 2KB
sect3.t2t 2KB
sect3.t2t 2KB
sect12.t2t 2KB
sect5.t2t 2KB
sect1.t2t 2KB
sect11.t2t 2KB
sect2.t2t 2KB
sect6.t2t 2KB
sect8.t2t 2KB
sect3.t2t 2KB
sect7.t2t 2KB
sect14.t2t 2KB
sect6.t2t 2KB
sect1.t2t 2KB
sect2.t2t 2KB
sect9.t2t 2KB
sect2.t2t 2KB
sect13.t2t 2KB
sect6.t2t 2KB
sect5.t2t 2KB
sect7.t2t 2KB
sect13.t2t 2KB
sect19.t2t 2KB
sect20.t2t 2KB
sect1.t2t 2KB
sect21.t2t 2KB
sect2.t2t 2KB
sect6.t2t 2KB
sect1.t2t 2KB
sect7.t2t 2KB
sect12.t2t 2KB
sect4.t2t 2KB
sect17.t2t 2KB
sect4.t2t 1KB
sect12.t2t 1KB
sect18.t2t 1KB
sect18.t2t 1KB
sect4.t2t 1KB
sect14.t2t 1KB
sect16.t2t 1KB
sect3.t2t 1KB
sect6.t2t 1KB
sect22.t2t 1KB
sect12.t2t 1KB
sect1.t2t 1KB
sect5.t2t 1KB
sect3.t2t 1KB
sect2.t2t 1KB
sect9.t2t 1KB
sect10.t2t 1KB
sect13.t2t 1KB
sect4.t2t 1KB
sect4.t2t 1KB
sect16.t2t 1KB
sect8.t2t 1KB
sect3.t2t 1KB
sect8.t2t 1KB
sect1.t2t 1KB
sect6.t2t 1KB
sect16.t2t 1KB
sect7.t2t 1KB
sect9.t2t 1KB
共 220 条
- 1
- 2
- 3
资源评论
vangau
- 粉丝: 2
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功