On Tue, Oct 6, 2009 at 9:41 PM, Aurélio Jargas <ve...@aurelio.net> wrote:
> I know nothing about Git and nothing about Textile, but any new target
> is very welcome to txt2tags :)

Patch attached.
It inherits from HTML, as textile accepts tags.
I tested the samples and some stuff I had against github: generate a
README.textile using "txt2tags -t textile -H", commit and push it and
it will appear in the project page.

Cheers
Leandro Penz
diff --git a/txt2tags b/txt2tags
index d190bba..4957baf 100755
--- a/txt2tags
+++ b/txt2tags
@@ -139,7 +139,7 @@ else:
 # first file and gui for the second. There is no --no-<action>.
 # --version and --help inside %!options are also odd
 #
-TARGETS  = 'html xhtml sgml dbk tex lout man mgp wiki gwiki doku pmw moin pm6 txt art adoc'.split()
+TARGETS  = 'html xhtml sgml dbk tex lout man mgp wiki gwiki doku pmw moin pm6 txt art adoc textile'.split()
 
 FLAGS    = {'headers'    :1 , 'enum-title' :0 , 'mask-email' :0 ,
             'toc-only'   :0 , 'toc'        :0 , 'rc'         :1 ,
@@ -179,6 +179,7 @@ TARGET_NAMES = {
   'txt'  : _('Plain Text'),
   'art'  : _('Ascii Art'),
   'adoc' : _('AsciiDoc'),
+  'textile' : _('textile document'),
 }
 
 DEBUG = 0     # do not edit here, please use --debug
@@ -469,6 +470,47 @@ _%(HEADER3)s_
 %(HEADER3)s
 """,
 
+	'textile': """\
+<?xml version="1.0"
+      encoding="%(ENCODING)s"
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml";>
+<head>
+<title>%(HEADER1)s</title>
+<meta name="generator" content="http://txt2tags.sf.net"; />
+<link rel="stylesheet" type="text/css" href="%(STYLE)s" />
+</head>
+<body bgcolor="white" text="black">
+<div align="center">
+<h1>%(HEADER1)s</h1>
+<h2>%(HEADER2)s</h2>
+<h3>%(HEADER3)s</h3>
+</div>
+""",
+
+	'textilecss': """\
+<?xml version="1.0"
+      encoding="%(ENCODING)s"
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml";>
+<head>
+<title>%(HEADER1)s</title>
+<meta name="generator" content="http://txt2tags.sf.net"; />
+<link rel="stylesheet" type="text/css" href="%(STYLE)s" />
+</head>
+<body>
+
+<div class="header" id="header">
+<h1>%(HEADER1)s</h1>
+<h2>%(HEADER2)s</h2>
+<h3>%(HEADER3)s</h3>
+</div>
+""",
+
 	'doku': """\
 ===== %(HEADER1)s =====
 
@@ -1074,6 +1116,72 @@ def getTags(config):
 		'img'                  : 'image::\a[]'   ,
 	},
 
+	'textile': {
+		'paragraphOpen'         : ''                                    ,
+		'paragraphClose'        : ''                                    ,
+		'title1'                : 'h1. \a'                              ,
+		'title2'                : 'h2. \a'                              ,
+		'title3'                : 'h3. \a'                              ,
+		'title4'                : 'h4. \a'                              ,
+		'title5'                : 'h5. \a'                              ,
+		#'anchor'               : '<A NAME="\a"></A>\n'                 ,
+		'blockVerbOpen'         : 'pre. '                               ,
+		'blockVerbClose'        : '\n'                                  ,
+		'blockQuoteOpen'        : 'bq.'                                 ,
+		'blockQuoteClose'       : ''                                    ,
+		'blockQuoteLine'        : ''                                    ,
+		'fontMonoOpen'          : '@'                                   ,
+		'fontMonoClose'         : '@'                                   ,
+		'fontBoldOpen'          : '**'                                  ,
+		'fontBoldClose'         : '**'                                  ,
+		'fontItalicOpen'        : '_'                                   ,
+		'fontItalicClose'       : '_'                                   ,
+		'fontUnderlineOpen'     : '+'                                   ,
+		'fontUnderlineClose'    : '+'                                   ,
+		'fontStrikeOpen'        : '-'                                   ,
+		'fontStrikeClose'       : '-'                                   ,
+		'listOpen'              : ''                                    ,
+		'listClose'             : ''                                    ,
+		'listItemOpen'          : ' '                                   ,
+		'listItemClose'         : ''                                    ,
+		'listItemLine'          : '*'                                   ,
+		'numlistOpen'           : ''                                    ,
+		'numlistClose'          : ''                                    ,
+		'numlistItemOpen'       : ' '                                   ,
+		'numlistItemClose'      : ''                                    ,
+		'numlistItemLine'       : '#'                                   ,
+		'deflistOpen'           : ''                                    ,
+		'deflistClose'          : ''                                    ,
+		'deflistItem1Open'      : ''                                    ,
+		'deflistItem1Close'     : ''                                    ,
+		'deflistItem2Open'      : ''                                    ,
+		'deflistItem2Close'     : ''                                    ,
+		'url'                   : '\a'                                  ,
+		'email'                 : '\a'                                  ,
+		'urlMark'               : '"\a":\a'                             ,
+		'emailMark'             : '"\a":mailto:\a'                      ,
+		'img'                   : '!~A~\a!'                             ,
+		'_imgAlignLeft'         : '{float:left;clear:left;}'            ,
+		'_imgAlignCenter'       : '{float:center;}'                     ,
+		'_imgAlignRight'        : '{float:right;clear:right;}'          ,
+		'tableOpen'             : 'table{cellpadding:4;~A~~B~}.'        ,
+		'tableClose'            : ''                                    ,
+		'tableRowOpen'          : ''                                    ,
+		'tableRowClose'         : '|'                                   ,
+		'tableCellOpen'         : '|~A~ '                               ,
+		'tableCellClose'        : ''                                    ,
+		'tableTitleCellOpen'    : '|_. '                                ,
+		'tableTitleCellClose'   : ''                                    ,
+		'_tableBorder'          : 'border:1px solid black;'             ,
+		'_tableAlignCenter'     : 'margin-left:auto;margin-right:auto;' ,
+		'_tableCellAlignLeft'   : '<. '                                 ,
+		'_tableCellAlignRight'  : '>. '                                 ,
+		'_tableCellAlignCenter' : '=. '                                 ,
+		'_tableCellColSpan'     : '\\a.'                                ,
+		'cssOpen'               : '<STYLE TYPE="text/css">'             ,
+		'cssClose'              : '</STYLE>'                            ,
+	},
+
 	# http://wiki.splitbrain.org/wiki:syntax
 	# Hint: <br> is \\ $
 	# Hint: You can add footnotes ((This is a footnote))
@@ -1345,7 +1453,7 @@ def getTags(config):
 	}
 	
 	# Exceptions for --css-sugar
-	if config['css-sugar'] and config['target'] in ('html','xhtml'):
+	if config['css-sugar'] and config['target'] in ('html','xhtml','textile'):
 		# Change just HTML because XHTML inherits it
 		htmltags = alltags['html']
 		# Table with no cellpadding
@@ -1364,6 +1472,14 @@ def getTags(config):
 	xhtml.update(alltags['xhtml'])
 	alltags['xhtml'] = xhtml.copy()
 	
+	# Make the XHTML -> textile inheritance
+	textile = alltags['xhtml'].copy()
+	for key in textile.keys(): textile[key] = textile[key].lower()
+	# Some like HTML tags as lowercase, some don't... (headers out)
+	if HTML_LOWER: alltags['xhtml'] = textile.copy()
+	textile.update(alltags['textile'])
+	alltags['textile'] = textile.copy()
+
 	# Compose the target tags dictionary
 	tags = {}
 	target_tags = alltags[config['target']].copy()
@@ -1680,6 +1796,26 @@ def getRules(config):
 			'blanksaroundtitle':1,
 			'blanksaroundnumtitle':1,
 		},
+		'textile': {
+			#TIP textile inherits all XHTML rules
+			'tableable':1,
+			'tablecellaligntype':'cell',
+			'imgalignable':1,
+			'onelinepara':1,
+			'quotenotnested':1,
+			'tagnotindentable':1,
+			'listnotnested':1,
+			'blanksaroundpara':1,
+			'blanksaroundverb':1,
+			'blanksaroundquote':1,
+			'blanksaroundlist':1,
+			'blanksaroundnumlist':1,
+			'blanksarounddeflist':1,
+			'blanksaroundtable':1,
+			'blanksaroundbar':1,
+			'blanksaroundtitle':1,
+			'blanksaroundnumtitle':1,
+		},
 		'doku': {
 			'indentverbblock':1, # DokuWiki uses '  ' to mark verb blocks
 			'spacedlistitem':1,
@@ -1798,7 +1934,7 @@ def getRules(config):
 	}
 	
 	# Exceptions for --css-sugar
-	if config['css-sugar'] and config['target'] in ('html','xhtml'):
+	if config['css-sugar'] and config['target'] in ('html','xhtml','textile'):
 		rules_bank['html']['indentverbblock'] = 0
 		rules_bank['html']['autotocwithbars'] = 0
 	
@@ -1806,6 +1942,9 @@ def getRules(config):
 	if config['target'] == 'xhtml':
 		myrules = rules_bank['html'].copy()   # inheritance
 		myrules.update(rules_bank['xhtml'])   # get XHTML specific
+	elif config['target'] == 'textile':
+		myrules = rules_bank['xhtml'].copy()   # inheritance
+		myrules.update(rules_bank['textile'])  # get textile specific
 	elif config['target'] == 'art':
 		myrules = rules_bank['txt'].copy()    # inheritance
 	else:
@@ -4136,7 +4275,7 @@ def doHeader(headers, config):
 	if not HEADER_TEMPLATE.has_key(target):
 		Error("doHeader: Unknown target '%s'"%target)
 	
-	if target in ('html','xhtml') and config.get('css-sugar'):
+	if target in ('html','xhtml', 'textile') and config.get('css-sugar'):
 		template = HEADER_TEMPLATE[target+'css'].split('\n')
 	else:
 		template = HEADER_TEMPLATE[target].split('\n')
@@ -4172,7 +4311,7 @@ def doHeader(headers, config):
 	
 	# css-inside removes STYLE line
 	#XXX In tex, this also removes the modules call (%!style:amsfonts)
-	if target in ('html','xhtml') and config.get('css-inside') and \
+	if target in ('html','xhtml', 'textile') and config.get('css-inside') and \
 	   config.get('style'):
 		head_data['STYLE'] = []
 	Debug("Header Data: %s"%head_data, 1)
@@ -4207,7 +4346,7 @@ def doHeader(headers, config):
 	
 	# Adding CSS contents into template (for --css-inside)
 	# This code sux. Dirty++
-	if target in ('html','xhtml') and config.get('css-inside') and \
+	if target in ('html','xhtml', 'textile') and config.get('css-inside') and \
 	   config.get('style'):
 		set_global_config(config) # usually on convert(), needed here
 		for i in xrange(len(config['style'])):
@@ -4266,7 +4405,7 @@ def doFooter(config):
 def doEscape(target,txt):
 	"Target-specific special escapes. Apply *before* insert any tag."
 	tmpmask = 'vvvvThisEscapingSuxvvvv'
-	if target in ('html','sgml','xhtml'):
+	if target in ('html','sgml','xhtml', 'textile'):
 		txt = re.sub('&','&amp;',txt)
 		txt = re.sub('<','&lt;',txt)
 		txt = re.sub('>','&gt;',txt)
@@ -4650,7 +4789,7 @@ def parse_images(line):
 				tag = regex['_imgAlign'].sub(align_tag, tag, 1)
 				
 			# Dirty fix to allow centered solo images
-			if align == 'center' and TARGET in ('html','xhtml'):
+			if align == 'center' and TARGET in ('html','xhtml','textile'):
 				rest = regex['img'].sub('',line,1)
 				if re.match('^\s+$', rest):
 					tag = "<center>%s</center>" %tag
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
txt2tags-list mailing list
https://lists.sourceforge.net/lists/listinfo/txt2tags-list

Reply via email to