NarrativeWeb now has Styked Notes! Thanks for being a giant help Benny. Could not have done it without you. Bringing the default print stylesheet up to date with the rest of them.

svn: r12683
This commit is contained in:
Rob G. Healey 2009-06-19 23:53:42 +00:00
parent 4cab1104b0
commit d181d6bd33
2 changed files with 884 additions and 400 deletions

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: $
# $Id:$
"""
Narrative Web Page generator.
@ -103,6 +103,9 @@ from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS
# import HTML Class
from libhtml import Html
# import styled notes from
# src/plugins/lib/libhtmlbackend.py
from libhtmlbackend import HtmlBackend
#------------------------------------------------------------------------
#
# constants
@ -191,6 +194,9 @@ class BasePage(object):
gid - Gramps ID
"""
# class to do conversion of styled notes to html markup
self._backend = HtmlBackend()
self.report = report
self.title_str = title
self.gid = gid
@ -212,6 +218,49 @@ class BasePage(object):
self.linkhome = report.options['linkhome']
self.use_gallery = report.options['gallery']
#################################################
#
# Will produce styled notes for NarrativeWeb by using:
# src/plugins/lib/libhtmlbackend.py
#
#################################################
def styled_note(self, styledtext, format):
"""
styledtext : assumed a StyledText object to write
format : = 0 : Flowed, = 1 : Preformatted
style_name : name of the style to use for default presentation
"""
text = str(styledtext)
if not text:
return ''
s_tags = styledtext.get_tags()
#FIXME: following split should be regex to match \n\s*\n instead?
markuptext = self._backend.add_markup_from_styled(text, s_tags,
split='\n\n')
htmllist = Html('div', id='grampsstylednote')
if format == 1:
#preformatted, retain whitespace.
#so use \n\n for paragraph detection
#FIXME: following split should be regex to match \n\s*\n instead?
htmllist += Html('pre', indent=None, inline=True)
for line in markuptext.split('\n\n'):
htmllist += Html('p')
for realline in line.split('\n'):
htmllist += realline
htmllist += Html('br')
elif format == 0:
#flowed
#FIXME: following split should be regex to match \n\s*\n instead?
for line in markuptext.split('\n\n'):
htmllist += Html('p')
htmllist += line
return htmllist
# ---------------------------------------------------------------------------------------
#
# # Web Page Fortmatter and writer
@ -289,8 +338,19 @@ class BasePage(object):
footer_note = self.report.options['footernote']
if footer_note:
note = db.get_note_from_gramps_id(footer_note)
user_footer = Html('div', id='user_footer') + Html('p', note.get())
footer += user_footer
note_text = note.get()
if note_text:
user_footer = Html('div', id='user_footer')
# styled notes
htmlnotetext = self.styled_note(note.get_styledtext(),
note.get_format())
if htmlnotetext:
text = htmlnotetext
else:
text = Html('p', note_text)
user_footer += text
footer += user_footer
value = _dd.display(date.Today())
msg = _('Generated by <a href="%(homepage)s">'
@ -394,14 +454,25 @@ class BasePage(object):
headerdiv = (Html('div', id='header') +
Html('h1', html_escape(self.title_str), id='SiteTitle', inline=True)
)
header = self.report.options['headernote']
if header:
note = db.get_note_from_gramps_id(header)
p = Html('p', note.get(), id='user_header')
headerdiv += p
body += headerdiv
header_note = self.report.options['headernote']
if header_note:
note = db.get_note_from_gramps_id(header_note)
note_text = note.get()
if note_text:
user_header = Html('div', id='user_header')
headerdiv += user_header
# styled notes
htmlnotetext = self.styled_note(note.get_styledtext(),
note.get_format())
if htmlnotetext:
text = htmlnotetext
else:
text = Html('p', note_text)
user_header += text
# Begin Navigation Menu
navigation = self.display_nav_links(title)
body += navigation
@ -597,23 +668,24 @@ class BasePage(object):
for notehandle in notelist:
note = db.get_note_from_handle(notehandle)
format = note.get_format()
text = note.get()
note_text = note.get()
try:
text = unicode(text)
note_text = unicode(note_text)
except UnicodeDecodeError:
text = unicode(str(text), errors='replace')
note_text = unicode(str(note_text), errors='replace')
if text:
title = Html('h4', _('Narrative'), inline=True)
section += title
if format:
text = u"<pre>%s</pre>" % text
if note_text:
section += Html('h4', _('Narrative'), inline=True)
# styled notes
htmlnotetext = self.styled_note(note.get_styledtext(),
note.get_format())
if htmlnotetext:
section += htmlnotetext
else:
text = u"<br />".join(text.split("\n"))
section += Html('p', text)
section += Html('p', note_text)
# return notes narrative to its callers
# return notes to its callers
return section
def display_url_list(self, urllist=None):
@ -696,7 +768,17 @@ class BasePage(object):
notelist = sref.get_note_list()
for notehandle in notelist:
note = db.get_note_from_handle(notehandle)
tmp.append("%s: %s" % (_('Text'), note.get()))
note_text = note.get()
if note_text:
# styled notes
htmlnotetext = self.styled_note(note.get_styledtext(),
note.get_format())
if htmlnotetext:
text = htmlnotetext
else:
text = Html('p', note_text)
tmp.append("%s: %s" % (_('Text'), text))
if len(tmp):
ordered2 += Html('li') + (
Html('a', '; &nbsp; '.join(tmp), name=" #sref%d%s " % (cindex+1, key))
@ -1884,35 +1966,45 @@ class IntroductionPage(BasePage):
def __init__(self, report, title):
BasePage.__init__(self, report, title)
db = report.database
of = self.report.create_file(report.intro_fname)
# Note. In old NarrativeWeb.py the content_divid depended on filename.
intro, body = self.write_header(_('Introduction'))
intropage, body = self.write_header(_('Introduction'))
sect_intro = Html('div', id='Introduction', class_='content')
# begin Introduction division
with Html('div', class_='content', id='Introduction') as section:
body += section
introimg = report.add_image('introimg')
if introimg:
sect_intro += introimg
introimg = report.add_image('introimg')
if introimg is not None:
section += introimg
note_id = report.options['intronote']
if note_id:
note_obj = report.database.get_note_from_gramps_id(note_id)
text = note_obj.get()
if note_obj.get_format():
text = Html('pre', text)
note_id = report.options['intronote']
note = db.get_note_from_gramps_id(note_id)
if note:
note_text = note.get()
# styled notes
htmlnotetext = self.styled_note(note.get_styledtext(),
note.get_format())
if htmlnotetext:
text = htmlnotetext
else:
text = Html('pre', note_text)
else:
text = Html('p', '<br>'.join(text.split('\n')))
sect_intro += text
text = None
text = text or '&nbsp;'
section += text
# add clearline for proper styling
# create footer section
# create clear line for proper styling
# bring all body pieces together
footer = self.write_footer()
body += (sect_intro, fullclear, footer)
body += (fullclear, footer)
# send page out for processing
self.mywriter(intro, of)
# and close the file
self.mywriter(intropage, of)
class HomePage(BasePage):
"""
@ -1933,13 +2025,20 @@ class HomePage(BasePage):
note_id = report.options['homenote']
if note_id:
note_obj = report.database.get_note_from_gramps_id(note_id)
text = note_obj.get()
if note_obj.get_format():
text = Html('pre', text, inline=True)
else:
text = Html('<br>'.join(text.split('\n')), inline=True)
sect_home_page += text
note = report.database.get_note_from_gramps_id(note_id)
note_text = note.get()
if note_text:
user_footer = Html('div', id='user_footer')
# styled notes
htmlnotetext = self.styled_note(note.get_styledtext(),
note.get_format())
if htmlnotetext:
text = htmlnotetext
else:
text = Html('p', note_text)
user_footer += text
sect_home_page += user_footer
# create footer section
# create clear line for proper styling
@ -2354,13 +2453,18 @@ class ContactPage(BasePage):
note_id = report.options['contactnote']
if note_id:
note_obj = report.database.get_note_from_gramps_id(note_id)
text = note_obj.get()
if note_obj.get_format():
text = u"\t\t<pre>%s</pre>" % text
else:
text = u"<br />".join(text.split("\n"))
summaryarea += Html('p', text, inline=True)
note = report.database.get_note_from_gramps_id(note_id)
note_text = note.get()
if note_text:
# styled notes
htmlnotetext = self.styled_note(note.get_styledtext(),
note.get_format())
if htmlnotetext:
text = htmlnotetext
else:
text = Html('p', note_text)
summaryarea += text
# add clearline for proper styling
# add footer section
@ -2764,16 +2868,23 @@ class IndividualPage(BasePage):
# display any notes associated with this name
notelist = name.get_note_list()
if len(notelist) > 0:
if len(notelist):
unordered = Html('ul')
tabcol2 += unordered
for notehandle in notelist:
note = db.get_note_from_handle(notehandle)
if note:
note_text = note.get()
if note_text:
txt = u" ".join(note_text.split("\n"))
unordered += Html('li', txt, inline=True)
tabcol2 += unordered
# styled notes
htmlnotetext = self.styled_note(note.get_styledtext(),
note.get_format())
if htmlnotetext:
text = htmlnotetext
else:
text = Html('pre', note_text)
unordered += text
# finished with this name
tabrow += (tabcol1, tabcol2)
@ -2894,9 +3005,7 @@ class IndividualPage(BasePage):
self.place_list[place_handle] = [lnk]
place = self.place_link(place_handle,
ReportUtils.place_name(db,
place_handle),
up=True)
ReportUtils.place_name(db, place_handle), up=True)
else:
place = ''
@ -2975,15 +3084,16 @@ class IndividualPage(BasePage):
note = db.get_note_from_handle(notehandle)
if note:
note_text = note.get()
format = note.get_format()
if note_text:
tabcol += Html('p', class_='EventNote')
if format:
tabcol += Html('pre', note_text)
# styled notes
htmlnotetext = self.styled_note(note.get_styledtext(),
note.get_format())
if htmlnotetext:
text = htmlnotetext
else:
tabcol += '<br />'.join(note_text.split('\n'))
else:
tabcol += '&nbsp;'
text = Html('p', note_text)
tabcol += text
tabrow += tabcol
# return events table row to its caller
@ -3416,21 +3526,24 @@ class IndividualPage(BasePage):
for notehandle in notelist:
note = db.get_note_from_handle(notehandle)
if note:
text = note.get()
format = note.get_format()
if text:
tabrow = Html('tr')
tabcol1 = Html('td', '&nbsp;', class_='ColumnType', inline=True)
tabcol2 = Html('td', _('Narrative'), class_='ColumnAttribute', inline=True)
tabcol3 = Html('td', class_='ColumnValue')
if format:
text = u"<pre>%s</pre>" % text
tabrow = Html('tr')
tabcol1 = Html('td', '&nbsp;', class_='ColumnType', inline=True)
tabcol2 = Html('td', _('Narrative'), class_='ColumnAttribute', inline=True)
tabcol3 = Html('td', class_='ColumnValue')
note_text = note.get()
if note_text:
# styled notes
htmlnotetext = self.styled_note(note.get_styledtext(),
note.get_format())
if htmlnotetext:
text = htmlnotetext
else:
text = u"<br />".join(text.split("\n"))
para = Html('p', text)
tabcol3 += para
tabrow += (tabcol1, tabcol2, tabcol3)
relation_table += tabrow
text = Html('p', note_text)
tabcol3 += text
tabrow += (tabcol1, tabcol2, tabcol3)
relation_table += tabrow
# return table to its caller
return relation_table