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:
parent
4cab1104b0
commit
d181d6bd33
File diff suppressed because it is too large
Load Diff
@ -103,6 +103,9 @@ from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS
|
|||||||
# import HTML Class
|
# import HTML Class
|
||||||
from libhtml import Html
|
from libhtml import Html
|
||||||
|
|
||||||
|
# import styled notes from
|
||||||
|
# src/plugins/lib/libhtmlbackend.py
|
||||||
|
from libhtmlbackend import HtmlBackend
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# constants
|
# constants
|
||||||
@ -191,6 +194,9 @@ class BasePage(object):
|
|||||||
gid - Gramps ID
|
gid - Gramps ID
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# class to do conversion of styled notes to html markup
|
||||||
|
self._backend = HtmlBackend()
|
||||||
|
|
||||||
self.report = report
|
self.report = report
|
||||||
self.title_str = title
|
self.title_str = title
|
||||||
self.gid = gid
|
self.gid = gid
|
||||||
@ -212,6 +218,49 @@ class BasePage(object):
|
|||||||
self.linkhome = report.options['linkhome']
|
self.linkhome = report.options['linkhome']
|
||||||
self.use_gallery = report.options['gallery']
|
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
|
# # Web Page Fortmatter and writer
|
||||||
@ -289,7 +338,18 @@ class BasePage(object):
|
|||||||
footer_note = self.report.options['footernote']
|
footer_note = self.report.options['footernote']
|
||||||
if footer_note:
|
if footer_note:
|
||||||
note = db.get_note_from_gramps_id(footer_note)
|
note = db.get_note_from_gramps_id(footer_note)
|
||||||
user_footer = Html('div', id='user_footer') + Html('p', note.get())
|
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
|
footer += user_footer
|
||||||
|
|
||||||
value = _dd.display(date.Today())
|
value = _dd.display(date.Today())
|
||||||
@ -394,14 +454,25 @@ class BasePage(object):
|
|||||||
headerdiv = (Html('div', id='header') +
|
headerdiv = (Html('div', id='header') +
|
||||||
Html('h1', html_escape(self.title_str), id='SiteTitle', inline=True)
|
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
|
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
|
# Begin Navigation Menu
|
||||||
navigation = self.display_nav_links(title)
|
navigation = self.display_nav_links(title)
|
||||||
body += navigation
|
body += navigation
|
||||||
@ -597,23 +668,24 @@ class BasePage(object):
|
|||||||
|
|
||||||
for notehandle in notelist:
|
for notehandle in notelist:
|
||||||
note = db.get_note_from_handle(notehandle)
|
note = db.get_note_from_handle(notehandle)
|
||||||
format = note.get_format()
|
note_text = note.get()
|
||||||
text = note.get()
|
|
||||||
try:
|
try:
|
||||||
text = unicode(text)
|
note_text = unicode(note_text)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
text = unicode(str(text), errors='replace')
|
note_text = unicode(str(note_text), errors='replace')
|
||||||
|
|
||||||
if text:
|
if note_text:
|
||||||
title = Html('h4', _('Narrative'), inline=True)
|
section += Html('h4', _('Narrative'), inline=True)
|
||||||
section += title
|
|
||||||
if format:
|
# styled notes
|
||||||
text = u"<pre>%s</pre>" % text
|
htmlnotetext = self.styled_note(note.get_styledtext(),
|
||||||
|
note.get_format())
|
||||||
|
if htmlnotetext:
|
||||||
|
section += htmlnotetext
|
||||||
else:
|
else:
|
||||||
text = u"<br />".join(text.split("\n"))
|
section += Html('p', note_text)
|
||||||
section += Html('p', text)
|
|
||||||
|
|
||||||
# return notes narrative to its callers
|
# return notes to its callers
|
||||||
return section
|
return section
|
||||||
|
|
||||||
def display_url_list(self, urllist=None):
|
def display_url_list(self, urllist=None):
|
||||||
@ -696,7 +768,17 @@ class BasePage(object):
|
|||||||
notelist = sref.get_note_list()
|
notelist = sref.get_note_list()
|
||||||
for notehandle in notelist:
|
for notehandle in notelist:
|
||||||
note = db.get_note_from_handle(notehandle)
|
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):
|
if len(tmp):
|
||||||
ordered2 += Html('li') + (
|
ordered2 += Html('li') + (
|
||||||
Html('a', '; '.join(tmp), name=" #sref%d%s " % (cindex+1, key))
|
Html('a', '; '.join(tmp), name=" #sref%d%s " % (cindex+1, key))
|
||||||
@ -1884,35 +1966,45 @@ class IntroductionPage(BasePage):
|
|||||||
|
|
||||||
def __init__(self, report, title):
|
def __init__(self, report, title):
|
||||||
BasePage.__init__(self, report, title)
|
BasePage.__init__(self, report, title)
|
||||||
|
db = report.database
|
||||||
|
|
||||||
of = self.report.create_file(report.intro_fname)
|
of = self.report.create_file(report.intro_fname)
|
||||||
# Note. In old NarrativeWeb.py the content_divid depended on filename.
|
# 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')
|
introimg = report.add_image('introimg')
|
||||||
if introimg:
|
if introimg is not None:
|
||||||
sect_intro += introimg
|
section += introimg
|
||||||
|
|
||||||
note_id = report.options['intronote']
|
note_id = report.options['intronote']
|
||||||
if note_id:
|
note = db.get_note_from_gramps_id(note_id)
|
||||||
note_obj = report.database.get_note_from_gramps_id(note_id)
|
if note:
|
||||||
text = note_obj.get()
|
note_text = note.get()
|
||||||
if note_obj.get_format():
|
|
||||||
text = Html('pre', text)
|
|
||||||
else:
|
|
||||||
text = Html('p', '<br>'.join(text.split('\n')))
|
|
||||||
sect_intro += text
|
|
||||||
|
|
||||||
|
# styled notes
|
||||||
|
htmlnotetext = self.styled_note(note.get_styledtext(),
|
||||||
|
note.get_format())
|
||||||
|
if htmlnotetext:
|
||||||
|
text = htmlnotetext
|
||||||
|
else:
|
||||||
|
text = Html('pre', note_text)
|
||||||
|
else:
|
||||||
|
text = None
|
||||||
|
text = text or ' '
|
||||||
|
section += text
|
||||||
|
|
||||||
|
# add clearline for proper styling
|
||||||
# create footer section
|
# create footer section
|
||||||
# create clear line for proper styling
|
|
||||||
# bring all body pieces together
|
|
||||||
footer = self.write_footer()
|
footer = self.write_footer()
|
||||||
body += (sect_intro, fullclear, footer)
|
body += (fullclear, footer)
|
||||||
|
|
||||||
# send page out for processing
|
# send page out for processing
|
||||||
self.mywriter(intro, of)
|
# and close the file
|
||||||
|
self.mywriter(intropage, of)
|
||||||
|
|
||||||
class HomePage(BasePage):
|
class HomePage(BasePage):
|
||||||
"""
|
"""
|
||||||
@ -1933,13 +2025,20 @@ class HomePage(BasePage):
|
|||||||
|
|
||||||
note_id = report.options['homenote']
|
note_id = report.options['homenote']
|
||||||
if note_id:
|
if note_id:
|
||||||
note_obj = report.database.get_note_from_gramps_id(note_id)
|
note = report.database.get_note_from_gramps_id(note_id)
|
||||||
text = note_obj.get()
|
note_text = note.get()
|
||||||
if note_obj.get_format():
|
if note_text:
|
||||||
text = Html('pre', text, inline=True)
|
user_footer = Html('div', id='user_footer')
|
||||||
|
|
||||||
|
# styled notes
|
||||||
|
htmlnotetext = self.styled_note(note.get_styledtext(),
|
||||||
|
note.get_format())
|
||||||
|
if htmlnotetext:
|
||||||
|
text = htmlnotetext
|
||||||
else:
|
else:
|
||||||
text = Html('<br>'.join(text.split('\n')), inline=True)
|
text = Html('p', note_text)
|
||||||
sect_home_page += text
|
user_footer += text
|
||||||
|
sect_home_page += user_footer
|
||||||
|
|
||||||
# create footer section
|
# create footer section
|
||||||
# create clear line for proper styling
|
# create clear line for proper styling
|
||||||
@ -2354,13 +2453,18 @@ class ContactPage(BasePage):
|
|||||||
|
|
||||||
note_id = report.options['contactnote']
|
note_id = report.options['contactnote']
|
||||||
if note_id:
|
if note_id:
|
||||||
note_obj = report.database.get_note_from_gramps_id(note_id)
|
note = report.database.get_note_from_gramps_id(note_id)
|
||||||
text = note_obj.get()
|
note_text = note.get()
|
||||||
if note_obj.get_format():
|
if note_text:
|
||||||
text = u"\t\t<pre>%s</pre>" % text
|
|
||||||
|
# styled notes
|
||||||
|
htmlnotetext = self.styled_note(note.get_styledtext(),
|
||||||
|
note.get_format())
|
||||||
|
if htmlnotetext:
|
||||||
|
text = htmlnotetext
|
||||||
else:
|
else:
|
||||||
text = u"<br />".join(text.split("\n"))
|
text = Html('p', note_text)
|
||||||
summaryarea += Html('p', text, inline=True)
|
summaryarea += text
|
||||||
|
|
||||||
# add clearline for proper styling
|
# add clearline for proper styling
|
||||||
# add footer section
|
# add footer section
|
||||||
@ -2764,16 +2868,23 @@ class IndividualPage(BasePage):
|
|||||||
|
|
||||||
# display any notes associated with this name
|
# display any notes associated with this name
|
||||||
notelist = name.get_note_list()
|
notelist = name.get_note_list()
|
||||||
if len(notelist) > 0:
|
if len(notelist):
|
||||||
unordered = Html('ul')
|
unordered = Html('ul')
|
||||||
|
tabcol2 += unordered
|
||||||
for notehandle in notelist:
|
for notehandle in notelist:
|
||||||
note = db.get_note_from_handle(notehandle)
|
note = db.get_note_from_handle(notehandle)
|
||||||
if note:
|
if note:
|
||||||
note_text = note.get()
|
note_text = note.get()
|
||||||
if note_text:
|
if note_text:
|
||||||
txt = u" ".join(note_text.split("\n"))
|
|
||||||
unordered += Html('li', txt, inline=True)
|
# styled notes
|
||||||
tabcol2 += unordered
|
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
|
# finished with this name
|
||||||
tabrow += (tabcol1, tabcol2)
|
tabrow += (tabcol1, tabcol2)
|
||||||
@ -2894,9 +3005,7 @@ class IndividualPage(BasePage):
|
|||||||
self.place_list[place_handle] = [lnk]
|
self.place_list[place_handle] = [lnk]
|
||||||
|
|
||||||
place = self.place_link(place_handle,
|
place = self.place_link(place_handle,
|
||||||
ReportUtils.place_name(db,
|
ReportUtils.place_name(db, place_handle), up=True)
|
||||||
place_handle),
|
|
||||||
up=True)
|
|
||||||
else:
|
else:
|
||||||
place = ''
|
place = ''
|
||||||
|
|
||||||
@ -2975,15 +3084,16 @@ class IndividualPage(BasePage):
|
|||||||
note = db.get_note_from_handle(notehandle)
|
note = db.get_note_from_handle(notehandle)
|
||||||
if note:
|
if note:
|
||||||
note_text = note.get()
|
note_text = note.get()
|
||||||
format = note.get_format()
|
|
||||||
if note_text:
|
if note_text:
|
||||||
tabcol += Html('p', class_='EventNote')
|
|
||||||
if format:
|
# styled notes
|
||||||
tabcol += Html('pre', note_text)
|
htmlnotetext = self.styled_note(note.get_styledtext(),
|
||||||
|
note.get_format())
|
||||||
|
if htmlnotetext:
|
||||||
|
text = htmlnotetext
|
||||||
else:
|
else:
|
||||||
tabcol += '<br />'.join(note_text.split('\n'))
|
text = Html('p', note_text)
|
||||||
else:
|
tabcol += text
|
||||||
tabcol += ' '
|
|
||||||
tabrow += tabcol
|
tabrow += tabcol
|
||||||
|
|
||||||
# return events table row to its caller
|
# return events table row to its caller
|
||||||
@ -3416,19 +3526,22 @@ class IndividualPage(BasePage):
|
|||||||
for notehandle in notelist:
|
for notehandle in notelist:
|
||||||
note = db.get_note_from_handle(notehandle)
|
note = db.get_note_from_handle(notehandle)
|
||||||
if note:
|
if note:
|
||||||
text = note.get()
|
|
||||||
format = note.get_format()
|
|
||||||
if text:
|
|
||||||
tabrow = Html('tr')
|
tabrow = Html('tr')
|
||||||
tabcol1 = Html('td', ' ', class_='ColumnType', inline=True)
|
tabcol1 = Html('td', ' ', class_='ColumnType', inline=True)
|
||||||
tabcol2 = Html('td', _('Narrative'), class_='ColumnAttribute', inline=True)
|
tabcol2 = Html('td', _('Narrative'), class_='ColumnAttribute', inline=True)
|
||||||
tabcol3 = Html('td', class_='ColumnValue')
|
tabcol3 = Html('td', class_='ColumnValue')
|
||||||
if format:
|
|
||||||
text = u"<pre>%s</pre>" % text
|
note_text = note.get()
|
||||||
|
if note_text:
|
||||||
|
|
||||||
|
# styled notes
|
||||||
|
htmlnotetext = self.styled_note(note.get_styledtext(),
|
||||||
|
note.get_format())
|
||||||
|
if htmlnotetext:
|
||||||
|
text = htmlnotetext
|
||||||
else:
|
else:
|
||||||
text = u"<br />".join(text.split("\n"))
|
text = Html('p', note_text)
|
||||||
para = Html('p', text)
|
tabcol3 += text
|
||||||
tabcol3 += para
|
|
||||||
tabrow += (tabcol1, tabcol2, tabcol3)
|
tabrow += (tabcol1, tabcol2, tabcol3)
|
||||||
relation_table += tabrow
|
relation_table += tabrow
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user