# vim: ft=diff
#
# From: "Peter Valach" - pvalach (a) gmx net
# To: txt2tags-list@lists.sourceforge.net
# Subject: My old patch reinvented :) (Re: [t2t] first v1.3 beta available)
# Date: Wed, 11 Dec 2002 15:25:22 +0100
# 
# Hi,
# 
# [cutted quoted changelog]
# 
# as you (aurelio) may remember, I created a simple patch for "reverse"
# title style some time ago (for 1.0). You refused it, because it could
# confuse somebody... Now I reimplemented it using a setting 
# (Titlestyle).
# I don't think that could confuse anybody, you can even leave it
# undocumented ;-).
# 
# For those who don't understand what I'm typing here about ;-) :
# With "reverse" titles I mean using *more* ='s for main titles. Example:
# 
# === Main title === (rendered in HTML as <h1>)
# 
# == Subtitle == (rendered in HTML as <h2>)
# 
# = Subsubtitle = (rendered in HTML as <h3>)
# 
#
--- txt2tags_orig	Wed Dec 11 14:16:16 2002
+++ txt2tags	Wed Dec 11 15:01:50 2002
@@ -917,7 +917,8 @@
 	
 	# special things
 	regex['special'] = re.compile(r'^%!\s*')
-	regex['setting'] = re.compile(r'(Encoding)\s*:\s*(.+)\s*$',re.I)
+	#PVx: added Titlestyle
+	regex['setting'] = re.compile(r'(Encoding|Titlestyle)\s*:\s*(.+)\s*$',re.I)
 	
 	return regex
 ### END OF regex nightmares
@@ -1278,8 +1279,11 @@
 	
 	AREA = NewArea('head',0)   # then conf, then body
 	subarea = SubareaMaster()
+	#PVx: added titlestyle
 	HEADERS = { 'HEADER1': '-NO TITLE-', 'HEADER2':'', 'HEADER3':'',
-	            'ENCODING': '' }
+	            'ENCODING': '', 'TITLESTYLE': '' }
+	#PVx: added title_maxlevel
+	title_maxlevel = 0
 	ret = []
 	toclist = []
 	header = []
@@ -1454,7 +1458,17 @@
 		if regex['title'].search(line) and not listindent and AREA == 'body':
 			m = regex['title'].search(line)
 			tag = m.group('tag')
-			level = len(tag)
+			#PVx: check for title style
+			if HEADERS['TITLESTYLE'] == 'reverse':
+				# if max level is not set yet, set it
+				if title_maxlevel == 0:
+					title_maxlevel = len(tag)
+					Debug('Reverse title maxlevel set to %s'%title_maxlevel,1)
+				# set level
+				level = title_maxlevel + 1 - len(tag)
+			else:
+				level = len(tag)
+
 			tag = TAGS['title%s'%level]
 			
 			txt = string.strip(m.group('txt'))
