2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-03-01 05:56:29 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2007-04-23 17:16:26 +05:30
|
|
|
# Copyright (C) 2007 Brian G. Matherly
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# 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; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# 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 should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2003-11-14 00:20:01 +05:30
|
|
|
# $Id$
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import time
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-03-11 06:42:06 +05:30
|
|
|
from PluginUtils import register_text_doc
|
2002-10-20 19:55:16 +05:30
|
|
|
import ImgManip
|
2006-03-01 05:56:29 +05:30
|
|
|
import tarfile
|
2002-10-20 19:55:16 +05:30
|
|
|
import const
|
2003-06-16 10:27:25 +05:30
|
|
|
import Errors
|
2003-08-25 08:41:40 +05:30
|
|
|
import BaseDoc
|
2003-10-11 19:52:17 +05:30
|
|
|
import QuestionDialog
|
2006-03-03 05:53:04 +05:30
|
|
|
import Mime
|
2006-06-19 02:28:25 +05:30
|
|
|
import Utils
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constant regular expressions
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
t_header_line_re = re.compile(
|
|
|
|
r"(.*)<TITLE>(.*)</TITLE>(.*)",
|
|
|
|
re.DOTALL|re.IGNORECASE|re.MULTILINE)
|
|
|
|
t_keyword_line_re = re.compile(
|
|
|
|
r'(.*name="keywords"\s+content=")([^\"]*)(".*)$',
|
|
|
|
re.DOTALL|re.IGNORECASE|re.MULTILINE)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Default template
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
_top = [
|
|
|
|
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">\n',
|
|
|
|
'<HTML>\n',
|
|
|
|
'<HEAD>\n',
|
2003-01-29 08:36:51 +05:30
|
|
|
' <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">\n',
|
|
|
|
' <META NAME="keywords" CONTENT="">\n',
|
2002-10-20 19:55:16 +05:30
|
|
|
' <TITLE>\n',
|
|
|
|
' </TITLE>\n',
|
|
|
|
' <STYLE type="text/css">\n',
|
|
|
|
' <!--\n',
|
|
|
|
' BODY { background-color: #ffffff }\n',
|
|
|
|
' .parent_name { font-family: Arial; font-style: bold }\n',
|
|
|
|
' .child_name { font-family: Arial; font-style: bold }\n',
|
|
|
|
' -->\n',
|
|
|
|
' </STYLE>\n',
|
|
|
|
'</HEAD>\n',
|
|
|
|
'<BODY>\n',
|
|
|
|
' <!-- START -->\n'
|
|
|
|
]
|
|
|
|
|
|
|
|
_bottom = [
|
|
|
|
' <!-- STOP -->\n',
|
|
|
|
'</BODY>\n',
|
|
|
|
'</HTML>\n'
|
|
|
|
]
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HtmlDoc
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2007-04-30 07:26:34 +05:30
|
|
|
class HtmlDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-02-25 02:45:21 +05:30
|
|
|
def __init__(self,styles,type,template):
|
|
|
|
BaseDoc.BaseDoc.__init__(self,styles,None,template)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.year = time.localtime(time.time())[0]
|
|
|
|
self.ext = '.html'
|
2007-02-11 09:21:43 +05:30
|
|
|
self.meta = ""
|
|
|
|
self.copyright = 'Copyright © %d' % (self.year)
|
|
|
|
self.map = None
|
|
|
|
self.f = None
|
|
|
|
self.filename = None
|
|
|
|
self.top = []
|
|
|
|
self.bottom = []
|
|
|
|
self.base = ""
|
|
|
|
self.load_template()
|
|
|
|
self.build_header()
|
|
|
|
self.style_declaration = None
|
|
|
|
self.image_dir = "images"
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def set_extension(self,val):
|
|
|
|
if val[0] != '.':
|
|
|
|
val = "." + val
|
|
|
|
self.ext = val
|
2007-02-11 09:21:43 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def set_image_dir(self,dirname):
|
|
|
|
self.image_dir = dirname
|
|
|
|
|
2003-01-29 08:36:51 +05:30
|
|
|
def set_keywords(self,keywords):
|
2005-12-06 12:08:09 +05:30
|
|
|
self.meta = ",".join(keywords)
|
2003-01-29 08:36:51 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def load_tpkg(self):
|
|
|
|
start = re.compile(r"<!--\s*START\s*-->")
|
|
|
|
stop = re.compile(r"<!--\s*STOP\s*-->")
|
|
|
|
top_add = 1
|
|
|
|
bottom_add = 0
|
2006-03-01 05:56:29 +05:30
|
|
|
archive = tarfile.open(self.template)
|
2007-02-15 08:44:03 +05:30
|
|
|
self.map = {}
|
2006-03-01 05:56:29 +05:30
|
|
|
for tarinfo in archive:
|
|
|
|
self.map[tarinfo.name] = archive.extractfile(tarinfo)
|
2002-10-20 19:55:16 +05:30
|
|
|
templateFile = self.map['template.html']
|
|
|
|
while 1:
|
|
|
|
line = templateFile.readline()
|
|
|
|
if line == '':
|
|
|
|
break
|
|
|
|
if top_add == 1:
|
|
|
|
self.top.append(line)
|
|
|
|
match = start.search(line)
|
|
|
|
if match:
|
|
|
|
top_add = 0
|
|
|
|
elif bottom_add == 0:
|
|
|
|
match = stop.search(line)
|
|
|
|
if match != None:
|
|
|
|
bottom_add = 1
|
|
|
|
self.bottom.append(line)
|
|
|
|
else:
|
|
|
|
self.bottom.append(line)
|
|
|
|
templateFile.close()
|
2007-02-15 08:44:03 +05:30
|
|
|
archive.close
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if top_add == 1:
|
|
|
|
mymsg = _("The marker '<!-- START -->' was not in the template")
|
2004-10-11 02:46:44 +05:30
|
|
|
QuestionDialog.ErrorDialog(_("Template Error"),mymsg)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def load_html(self):
|
|
|
|
start = re.compile(r"<!--\s*START\s*-->")
|
|
|
|
stop = re.compile(r"<!--\s*STOP\s*-->")
|
|
|
|
top_add = 1
|
|
|
|
bottom_add = 0
|
|
|
|
templateFile = open(self.template,"r")
|
|
|
|
for line in templateFile.readlines():
|
|
|
|
if top_add == 1:
|
|
|
|
self.top.append(line)
|
|
|
|
match = start.search(line)
|
|
|
|
if match:
|
|
|
|
top_add = 0
|
|
|
|
elif bottom_add == 0:
|
|
|
|
match = stop.search(line)
|
|
|
|
if match != None:
|
|
|
|
bottom_add = 1
|
|
|
|
self.bottom.append(line)
|
|
|
|
else:
|
|
|
|
self.bottom.append(line)
|
|
|
|
templateFile.close()
|
|
|
|
|
|
|
|
if top_add == 1:
|
|
|
|
mymsg = _("The marker '<!-- START -->' was not in the template")
|
2004-10-26 08:50:38 +05:30
|
|
|
QuestionDialog.ErrorDialog(_("Template Error"),mymsg)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def load_template(self):
|
|
|
|
if self.template:
|
|
|
|
try:
|
|
|
|
if self.template[-4:] == 'tpkg':
|
|
|
|
self.load_tpkg()
|
|
|
|
else:
|
|
|
|
self.load_html()
|
|
|
|
except IOError,msg:
|
|
|
|
mymsg = _("Could not open %s\nUsing the default template") % \
|
|
|
|
self.template
|
2003-10-15 09:25:15 +05:30
|
|
|
QuestionDialog.WarningDialog(mymsg,str(msg))
|
2002-10-20 19:55:16 +05:30
|
|
|
self.bottom = _bottom
|
|
|
|
self.top = _top
|
|
|
|
except:
|
|
|
|
mymsg = _("Could not open %s\nUsing the default template") % \
|
|
|
|
self.template
|
2003-10-11 19:52:17 +05:30
|
|
|
QuestionDialog.WarningDialog(mymsg)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.bottom = _bottom
|
|
|
|
self.top = _top
|
|
|
|
else:
|
|
|
|
self.bottom = _bottom
|
|
|
|
self.top = _top
|
|
|
|
|
|
|
|
def process_line(self,line):
|
2007-09-08 11:24:02 +05:30
|
|
|
l = line.replace('$VERSION',const.VERSION)
|
2005-12-06 12:08:09 +05:30
|
|
|
return l.replace('$COPYRIGHT',self.copyright)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def open(self,filename):
|
|
|
|
(r,e) = os.path.splitext(filename)
|
|
|
|
if e == self.ext:
|
|
|
|
self.filename = filename
|
|
|
|
else:
|
|
|
|
self.filename = filename + self.ext
|
|
|
|
|
|
|
|
self.base = os.path.dirname(self.filename)
|
|
|
|
|
2003-05-16 07:19:50 +05:30
|
|
|
try:
|
|
|
|
self.f = open(self.filename,"w")
|
|
|
|
except IOError,msg:
|
|
|
|
errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg)
|
|
|
|
raise Errors.ReportError(errmsg)
|
|
|
|
except:
|
|
|
|
raise Errors.ReportError(_("Could not create %s") % self.filename)
|
|
|
|
|
2003-01-29 08:36:51 +05:30
|
|
|
if self.meta:
|
|
|
|
match = t_keyword_line_re.match(self.file_header)
|
|
|
|
if match:
|
|
|
|
g = match.groups()
|
|
|
|
line = "%s%s%s" % (g[0],self.meta,g[2])
|
|
|
|
else:
|
|
|
|
line = self.file_header
|
|
|
|
else:
|
|
|
|
line = self.file_header
|
|
|
|
self.f.write(line)
|
2003-06-13 21:47:45 +05:30
|
|
|
if not self.style_declaration:
|
|
|
|
self.build_style_declaration()
|
2002-10-20 19:55:16 +05:30
|
|
|
self.f.write(self.style_declaration)
|
|
|
|
|
|
|
|
def build_header(self):
|
2005-12-06 12:08:09 +05:30
|
|
|
self.fix_title("".join(self.top))
|
2003-10-12 07:59:24 +05:30
|
|
|
|
|
|
|
def fix_title(self,msg=None):
|
|
|
|
if msg == None:
|
|
|
|
match = t_header_line_re.match(self.file_header)
|
|
|
|
else:
|
|
|
|
match = t_header_line_re.match(msg)
|
2002-10-20 19:55:16 +05:30
|
|
|
if match:
|
|
|
|
m = match.groups()
|
2007-06-02 09:40:37 +05:30
|
|
|
self.file_header = '%s<TITLE>%s</TITLE>%s\n' % (m[0],m[1],m[2])
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-01-13 10:35:39 +05:30
|
|
|
self.file_header = self.top
|
2002-10-20 19:55:16 +05:30
|
|
|
self.file_header = self.process_line(self.file_header)
|
|
|
|
|
|
|
|
def build_style_declaration(self):
|
2007-04-23 17:16:26 +05:30
|
|
|
styles = self.get_style_sheet()
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
text = ['<style type="text/css">\n<!--']
|
2007-04-23 17:16:26 +05:30
|
|
|
|
|
|
|
for sname in styles.get_cell_style_names():
|
|
|
|
style = styles.get_cell_style(sname)
|
2002-10-20 19:55:16 +05:30
|
|
|
pad = "%.3fcm" % style.get_padding()
|
|
|
|
top = bottom = left = right = 'none'
|
|
|
|
if style.get_top_border():
|
|
|
|
top = 'thin solid #000000'
|
|
|
|
if style.get_bottom_border():
|
|
|
|
bottom = 'thin solid #000000'
|
|
|
|
if style.get_left_border():
|
2008-01-06 01:40:26 +05:30
|
|
|
left = 'thin solid #000000'
|
2002-10-20 19:55:16 +05:30
|
|
|
if style.get_right_border():
|
|
|
|
right = 'thin solid #000000'
|
|
|
|
text.append('.%s {\n'
|
|
|
|
'\tpadding: %s %s %s %s;\n'
|
|
|
|
'\tborder-top:%s; border-bottom:%s;\n'
|
|
|
|
'\tborder-left:%s; border-right:%s;\n}'
|
2007-04-23 17:16:26 +05:30
|
|
|
% (sname, pad, pad, pad, pad, top, bottom, left, right))
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
for style_name in styles.get_paragraph_style_names():
|
|
|
|
style = styles.get_paragraph_style(style_name)
|
2002-10-20 19:55:16 +05:30
|
|
|
font = style.get_font()
|
|
|
|
font_size = font.get_size()
|
|
|
|
font_color = '#%02x%02x%02x' % font.get_color()
|
|
|
|
align = style.get_alignment_text()
|
|
|
|
text_indent = "%.2f" % style.get_first_indent()
|
|
|
|
right_margin = "%.2f" % style.get_right_margin()
|
|
|
|
left_margin = "%.2f" % style.get_left_margin()
|
2005-12-06 12:08:09 +05:30
|
|
|
top_margin = "%.2f" % style.get_top_margin()
|
|
|
|
bottom_margin = "%.2f" % style.get_bottom_margin()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
top = bottom = left = right = 'none'
|
|
|
|
if style.get_top_border():
|
|
|
|
top = 'thin solid #000000'
|
|
|
|
if style.get_bottom_border():
|
|
|
|
bottom = 'thin solid #000000'
|
|
|
|
if style.get_left_border():
|
2008-01-06 01:40:26 +05:30
|
|
|
left = 'thin solid #000000'
|
2002-10-20 19:55:16 +05:30
|
|
|
if style.get_right_border():
|
|
|
|
right = 'thin solid #000000'
|
|
|
|
|
|
|
|
italic = bold = ''
|
|
|
|
if font.get_italic():
|
|
|
|
italic = 'font-style:italic; '
|
|
|
|
if font.get_bold():
|
|
|
|
bold = 'font-weight:bold; '
|
2003-08-25 08:41:40 +05:30
|
|
|
if font.get_type_face() == BaseDoc.FONT_SANS_SERIF:
|
2002-10-20 19:55:16 +05:30
|
|
|
family = '"Helvetica","Arial","sans-serif"'
|
|
|
|
else:
|
|
|
|
family = '"Times New Roman","Times","serif"'
|
|
|
|
|
|
|
|
text.append('.%s {\n'
|
|
|
|
'\tfont-size: %dpt; color: %s;\n'
|
|
|
|
'\ttext-align: %s; text-indent: %scm;\n'
|
|
|
|
'\tmargin-right: %scm; margin-left: %scm;\n'
|
2005-12-06 12:08:09 +05:30
|
|
|
'\tmargin-top: %scm; margin-bottom: %scm;\n'
|
2002-10-20 19:55:16 +05:30
|
|
|
'\tborder-top:%s; border-bottom:%s;\n'
|
|
|
|
'\tborder-left:%s; border-right:%s;\n'
|
|
|
|
'\t%s%sfont-family:%s;\n}'
|
2007-04-23 17:16:26 +05:30
|
|
|
% (style_name, font_size, font_color,
|
2002-10-20 19:55:16 +05:30
|
|
|
align, text_indent,
|
|
|
|
right_margin, left_margin,
|
2005-12-06 12:08:09 +05:30
|
|
|
top_margin, bottom_margin,
|
2002-10-20 19:55:16 +05:30
|
|
|
top, bottom, left, right,
|
|
|
|
italic, bold, family))
|
|
|
|
|
|
|
|
text.append('-->\n</style>')
|
2005-12-06 12:08:09 +05:30
|
|
|
self.style_declaration = '\n'.join(text)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def close(self):
|
|
|
|
for line in self.bottom:
|
|
|
|
self.f.write(self.process_line(line))
|
|
|
|
self.f.close()
|
2003-03-23 09:46:29 +05:30
|
|
|
self.write_support_files()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-01-01 23:47:47 +05:30
|
|
|
if self.print_req:
|
|
|
|
apptype = 'text/html'
|
2006-03-03 05:53:04 +05:30
|
|
|
app = Mime.get_application(apptype)
|
2006-06-19 02:28:25 +05:30
|
|
|
Utils.launch(app[0],self.filename)
|
2004-01-01 23:47:47 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def write_support_files(self):
|
|
|
|
if self.map:
|
|
|
|
for name in self.map.keys():
|
|
|
|
if name == 'template.html':
|
|
|
|
continue
|
2007-02-15 08:44:03 +05:30
|
|
|
fname = '%s%s%s' % (self.base,os.path.sep,name)
|
2003-05-16 07:19:50 +05:30
|
|
|
try:
|
|
|
|
f = open(fname, 'wb')
|
|
|
|
f.write(self.map[name].read())
|
|
|
|
f.close()
|
|
|
|
except IOError,msg:
|
|
|
|
errmsg = "%s\n%s" % (_("Could not create %s") % fname, msg)
|
|
|
|
raise Errors.ReportError(errmsg)
|
|
|
|
except:
|
|
|
|
raise Errors.ReportError(_("Could not create %s") % fname)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-03-10 10:26:20 +05:30
|
|
|
def add_media_object(self,name,pos,x,y,alt=''):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.empty = 0
|
|
|
|
size = int(max(x,y) * float(150.0/2.54))
|
|
|
|
refname = "is%s" % os.path.basename(name)
|
|
|
|
|
|
|
|
if self.image_dir:
|
2007-02-15 08:44:03 +05:30
|
|
|
imdir = '%s%s%s' % (self.base,os.path.sep,self.image_dir)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
imdir = self.base
|
|
|
|
|
|
|
|
if not os.path.isdir(imdir):
|
|
|
|
try:
|
|
|
|
os.mkdir(imdir)
|
|
|
|
except:
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
2007-12-31 02:30:28 +05:30
|
|
|
ImgManip.resize_to_jpeg(name, refname, size, size)
|
2002-10-20 19:55:16 +05:30
|
|
|
except:
|
|
|
|
return
|
|
|
|
|
|
|
|
if pos == "right":
|
|
|
|
xtra = ' align="right"'
|
|
|
|
elif pos == "left" :
|
|
|
|
xtra = ' align="left"'
|
|
|
|
else:
|
|
|
|
xtra = ''
|
|
|
|
|
|
|
|
if self.image_dir:
|
2007-12-31 02:30:28 +05:30
|
|
|
self.f.write('<img src="%s/%s" border="0" alt="%s"%s>\n' % \
|
|
|
|
(self.image_dir, refname, alt, xtra))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2007-12-31 02:30:28 +05:30
|
|
|
self.f.write('<img src="%s" border="0" alt="%s"%s>\n'
|
|
|
|
% (refname, alt, xtra))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def start_table(self,name,style):
|
2007-04-23 17:16:26 +05:30
|
|
|
styles = self.get_style_sheet()
|
|
|
|
self.tbl = styles.get_table_style(style)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.f.write('<table width="%d%%" ' % self.tbl.get_width())
|
|
|
|
self.f.write('cellspacing="0">\n')
|
|
|
|
|
|
|
|
def end_table(self):
|
|
|
|
self.f.write('</table>\n')
|
|
|
|
|
|
|
|
def start_row(self):
|
|
|
|
self.col = 0
|
|
|
|
self.f.write('<tr>\n')
|
|
|
|
|
|
|
|
def end_row(self):
|
|
|
|
self.f.write('</tr>\n')
|
|
|
|
|
|
|
|
def start_cell(self,style_name,span=1):
|
|
|
|
self.empty = 1
|
|
|
|
self.f.write('<td valign="top"')
|
|
|
|
if span > 1:
|
|
|
|
self.f.write(' colspan="' + str(span) + '"')
|
|
|
|
self.col = self.col + 1
|
|
|
|
else:
|
|
|
|
self.f.write(' width="')
|
|
|
|
self.f.write(str(self.tbl.get_column_width(self.col)))
|
|
|
|
self.f.write('%"')
|
|
|
|
self.f.write(' class="')
|
|
|
|
self.f.write(style_name)
|
|
|
|
self.f.write('">')
|
|
|
|
self.col = self.col + 1
|
|
|
|
|
|
|
|
def end_cell(self):
|
|
|
|
self.f.write('</td>\n')
|
|
|
|
|
|
|
|
def start_paragraph(self,style_name,leader=None):
|
|
|
|
self.f.write('<p class="' + style_name + '">')
|
|
|
|
if leader != None:
|
|
|
|
self.f.write(leader)
|
|
|
|
self.f.write(' ')
|
|
|
|
|
|
|
|
def end_paragraph(self):
|
|
|
|
if self.empty == 1:
|
|
|
|
self.f.write(' ')
|
|
|
|
self.empty = 0
|
|
|
|
self.f.write('</p>\n')
|
|
|
|
|
2003-11-14 00:20:01 +05:30
|
|
|
def start_bold(self):
|
|
|
|
self.f.write('<b>')
|
|
|
|
|
|
|
|
def end_bold(self):
|
|
|
|
self.f.write('</b>')
|
2007-01-31 08:43:31 +05:30
|
|
|
|
|
|
|
def start_superscript(self):
|
|
|
|
self.f.write('<sup>')
|
|
|
|
|
|
|
|
def end_superscript(self):
|
|
|
|
self.f.write('</sup>')
|
2003-11-14 00:20:01 +05:30
|
|
|
|
2003-12-11 09:19:44 +05:30
|
|
|
def write_note(self,text,format,style_name):
|
|
|
|
if format == 1:
|
2003-12-13 04:54:07 +05:30
|
|
|
self.f.write('<pre class=%s style="font-family: courier, monospace">' % style_name)
|
2003-12-11 09:19:44 +05:30
|
|
|
self.write_text(text)
|
|
|
|
self.f.write('</pre>')
|
|
|
|
elif format == 0:
|
|
|
|
for line in text.split('\n\n'):
|
|
|
|
self.start_paragraph(style_name)
|
|
|
|
self.write_text(line.strip().replace('\n',' '))
|
|
|
|
self.end_paragraph()
|
|
|
|
|
2006-06-03 09:02:26 +05:30
|
|
|
def write_text(self,text,mark=None):
|
2005-12-06 12:08:09 +05:30
|
|
|
text = text.replace('&','&'); # Must be first
|
|
|
|
text = text.replace('<','<');
|
|
|
|
text = text.replace('>','>');
|
|
|
|
text = text.replace('\n','<br>')
|
2003-05-08 06:12:10 +05:30
|
|
|
text = text.replace('<super>','<sup>')
|
|
|
|
text = text.replace('</super>','</sup>')
|
2002-10-20 19:55:16 +05:30
|
|
|
if text != "":
|
|
|
|
self.empty = 0
|
2008-01-06 01:40:26 +05:30
|
|
|
self.f.write(text)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-01-01 23:47:47 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Register the document generator with the GRAMPS plugin system
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-06-19 02:28:25 +05:30
|
|
|
print_label = None
|
2004-01-01 23:47:47 +05:30
|
|
|
try:
|
2006-03-03 05:53:04 +05:30
|
|
|
prog = Mime.get_application("text/html")
|
|
|
|
mtype = Mime.get_description("text/html")
|
2004-04-04 10:09:52 +05:30
|
|
|
|
|
|
|
if Utils.search_for(prog[0]):
|
|
|
|
print_label=_("Open in %s") % prog[1]
|
|
|
|
else:
|
|
|
|
print_label=None
|
2006-06-19 02:28:25 +05:30
|
|
|
|
|
|
|
if mtype == _("unknown"):
|
|
|
|
mtype = _('HTML')
|
|
|
|
|
2006-03-11 06:42:06 +05:30
|
|
|
register_text_doc(mtype,HtmlDoc,1,0,1,".html", print_label)
|
2004-01-01 23:47:47 +05:30
|
|
|
except:
|
2006-03-11 06:42:06 +05:30
|
|
|
register_text_doc(_('HTML'),HtmlDoc,1,0,1,".html", None)
|