ged2doc.html_writer

Module which produces HTML output.

Functions

TR(x)

This is no-op function, only used to mark translatable strings, to extract all strings run pygettext -k TR ...

Classes

HtmlWriter(flocator, output, tr[, encoding, …])

Transforms GEDCOM file into nicely formatted HTML page.

class ged2doc.html_writer.HtmlWriter(flocator, output, tr, encoding=None, encoding_errors='strict', sort_order=<NameOrder.SURNAME_GIVEN: 'last+first'>, name_fmt=0, make_images=True, make_stat=True, make_toc=True, events_without_dates=True, page_width='800px', image_width='300px', image_height='300px', image_upscale=False, tree_width=4)[source]

Bases: ged2doc.writer.Writer

Transforms GEDCOM file into nicely formatted HTML page.

This is a sub-class of Writer class providing implementation for rendering methods which transform GEDCOM info into HTML constructs. Constructor takes a large number of arguments which configure appearance of the resulting HTML page. After instantiating an object of this type one has to call save() method to produce output file.

Parameters
flocatorged2doc.input.FileLocator

File locator instance.

outputstr or io.TextIOBase

Name for the output file or file object.

trged2doc.i18n.I18N

Object supporting translation.

encodingstr, optional

GEDCOM file encoding, if None then encoding is determined from file itself.

encoding_errorsstr, optional

Controls error handling behavior during string decoding, one of “strict” (default), “ignore”, or “replace”.

sort_orderged4py.model.NameOrder, optional

Determines ordering of person in output file, one of the constants defined in ged4py.model.NameOrder enum.

name_fmtint, optional

Bit mask with flags from ged2doc.name module.

make_imagesbool, optional

If True (default) then generate images for persons.

make_statbool, optional

If True (default) then generate statistics section.

make_tocbool, optional

If True (default) then generate Table of Contents.

events_without_datesbool, optional

If True (default) then show events that have no associated dates.

page_widthged2doc.size.Size

Width of the produced HTML page.

image_widthged2doc.size.Size

Size of the images.

image_heightged2doc.size.Size

Size of the images.

image_upscalebool

If True then smaller images will be re-scaled to extend to image size.

tree_widthint

Number of generations in ancestor tree.

Methods

save()

Produce output document.

_render_prolog()[source]

Generate initial document header/title.

_interpolate(text)[source]

Takes text with embedded references and returns properly escaped text with HTML links.

Parameters
textstr

Arbitrary text with references.

Returns
htmlstr

HTML as text.

_render_section(level, ref_id, title, newpage=False)[source]

Produces new section in the output document.

This method should also save section reference so that TOC can be later produced when _render_toc method is called.

Parameters
levelint

Section level (1, 2, 3, etc.).

ref_idstr

Unique section identifier.

titlestr

Printable section name.

newpagebool, optional

If True then start new page (for documents that support pagination).

_render_person(person, image_data, attributes, families, events, notes)[source]

Output person information.

Parameters
personged4py.model.Individual

INDI record representation.

image_databytes or None

Either None or binary image data (typically content of JPEG image).

attributeslist [ tuple ]

List of (attr_name, text) tuples, may be empty.

familieslist [ str ]

List of strings (possibly empty), each string contains description of one family and should be typically rendered as a separate paragraph.

eventslist [ tuple ]

List of (date, text) tuples, may be empty. Date is properly formatted string and does not need any other formatting.

noteslist [ str ]

List of strings, each string should be rendered as separate paragraph.

Notes

Textual information in parameters to this method can include references to other persons (e.g. mother/father). Such references are embedded into text in encoded format determined by _person_ref method. It is responsibility of the subclasses to extract these references from text and re-encode them using proper backend representation.

_render_name_stat(n_total, n_females, n_males)[source]

Produces summary table.

Sum of male and female counters can be lower than total count due to individuals with unknown/unspecified gender.

Parameters
n_totalint

Total number of individuals.

n_femalesint

Number of female individuals.

n_malesint

Number of male individuals.

_render_name_freq(freq_table)[source]

Produces name statistics table.

Parameters
freq_tablelist [ tuple ]

List of (name, count) tuples.

_render_toc()[source]

Produce table of contents using info collected in _render_section().

_finalize()[source]

Finalize output.

_abc_impl = <_abc_data object>
_get_image_fragment(image_data)[source]

Returns <img> HTML fragment for given image data (byte array).

Parameters
image_databytes

Image data.

Returns
htmlstr

HTML text containing image.

_make_ancestor_tree(person)[source]

Make SVG picture for parent tree.

Parameters
personged4py.model.Individual

INDI record

Returns
htmllist [ str ]

SVG data (HTML contents), list of strings.