bar_width = 35
background_color = '#444'
author_color = '#444'
+ default_background = get_resource('res/cover.png')
+ format = 'JPEG'
epochs = {
u'Starożytność': 0,
bg_src = urlopen(book_info.cover_url)
self.background_img = StringIO(bg_src.read())
bg_src.close()
+ else:
+ self.background_img = self.default_background
def pretty_author(self):
return self.author.upper()
# Process all elements except begin and end
else:
# Omit annotation tags
- if len(element.get('name', '')) or element.get('class', '') == 'annotation':
+ if (len(element.get('name', '')) or
+ element.get('class', '') in ('annotation', 'anchor')):
if event == 'end' and element.tail:
for fragment_id in open_fragments:
open_fragments[fragment_id].append('text', element.tail)
counter += 1
+def raw_printable_text(element):
+ working = copy.deepcopy(element)
+ for e in working.findall('a'):
+ if e.get('class') == 'annotation':
+ e.text = ''
+ return etree.tostring(working, method='text', encoding=unicode).strip()
+
+
def add_table_of_contents(root):
sections = []
counter = 1
if any_ancestor(element, lambda e: e.get('id') in ('footnotes',) or e.get('class') in ('person-list',)):
continue
- element_text = etree.tostring(element, method='text',
- encoding=unicode).strip()
+ element_text = raw_printable_text(element)
if element.tag == 'h3' and len(sections) and sections[-1][1] == 'h2':
sections[-1][3].append((counter, element.tag, element_text, []))
else:
flags = ('less-advertising',)
-class VirtualoEpubPackager(Packager):
+class VirtualoPackager(Packager):
@staticmethod
def utf_trunc(text, limit):
""" truncates text to at most `limit' bytes in utf-8 """
cover.VirtualoCover(info).save(os.path.join(outfile_dir, slug+'.jpg'))
outfile = os.path.join(outfile_dir, '1.epub')
outfile_sample = os.path.join(outfile_dir, '1.sample.epub')
- doc.save_output_file(epub.transform(doc),
+ doc.save_output_file(doc.as_epub(),
output_path=outfile)
- doc.save_output_file(epub.transform(doc, sample=25),
+ doc.save_output_file(doc.as_epub(doc, sample=25),
+ output_path=outfile_sample)
+ outfile = os.path.join(outfile_dir, '1.mobi')
+ outfile_sample = os.path.join(outfile_dir, '1.sample.mobi')
+ doc.save_output_file(doc.as_mobi(cover=cover.VirtualoCover),
+ output_path=outfile)
+ doc.save_output_file(
+ doc.as_mobi(doc, cover=cover.VirtualoCover, sample=25),
output_path=outfile_sample)
except ParseError, e:
print '%(file)s:%(name)s:%(message)s' % {
xmlns:dc="http://purl.org/dc/elements/1.1/" >
<xsl:output encoding="utf-8" indent="yes" omit-xml-declaration = "yes" version="2.0" />
+<xsl:strip-space elements="opowiadanie powiesc dramat_wierszowany_l dramat_wierszowany_lp dramat_wspolczesny liryka_l liryka_lp wywiad"/>
<xsl:template match="utwor">
<xsl:choose>
<xsl:when test="@full-page">
<!-- Section headers (included in index)-->
<xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
+ <xsl:call-template name="section-anchor"/>
<h2><xsl:apply-templates mode="inline" /></h2>
</xsl:template>
<xsl:template match="naglowek_scena|naglowek_rozdzial">
+ <xsl:call-template name="section-anchor"/>
<h3><xsl:apply-templates mode="inline" /></h3>
</xsl:template>
<xsl:template match="naglowek_osoba|naglowek_podrozdzial">
+ <xsl:call-template name="section-anchor"/>
<h4><xsl:apply-templates mode="inline" /></h4>
</xsl:template>
<!-- Other paragraph tags -->
<xsl:template match="miejsce_czas">
+ <xsl:call-template name="section-anchor"/>
<p class="place-and-time"><xsl:apply-templates mode="inline" /></p>
</xsl:template>
<xsl:template match="didaskalia">
+ <xsl:call-template name="section-anchor"/>
<div class="didaskalia"><xsl:apply-templates mode="inline" /></div>
</xsl:template>
</xsl:template>
<xsl:template match="akap|akap_dialog|akap_cd">
- <p class="paragraph"><xsl:apply-templates mode="inline" /></p>
+ <p class="paragraph">
+ <xsl:call-template name="section-anchor"/>
+ <xsl:apply-templates mode="inline" />
+ </p>
</xsl:template>
<xsl:template match="strofa">
<div class="stanza">
+ <xsl:call-template name="section-anchor"/>
<xsl:choose>
<xsl:when test="count(br) > 0">
<xsl:call-template name="verse">
<xsl:value-of select="wl:substitute_entities(.)" />
</xsl:template>
+<!-- ========= -->
+<!-- = utils = -->
+<!-- ========= -->
+<xsl:template name="section-anchor">
+ <!--
+ this formula works as follows:
+ - get all ancestors including self
+ - choose the header (third one from root): utwor/book-type/header
+ - get all preceding siblings
+ - count them
+ - create an <a name="sec123"/> tag.
+ -->
+ <a name="{concat('sec', count(ancestor-or-self::*[last()-2]/preceding-sibling::*) + 1)}" />
+</xsl:template>
-</xsl:stylesheet>
\ No newline at end of file
+</xsl:stylesheet>
if options.verbose:
print input_filename
- output_filename = os.path.splitext(input_filename)[0] + '.png'
+ output_filename = os.path.splitext(input_filename)[0] + '.jpg'
doc = WLDocument.from_file(input_filename)
WLCover(doc.book_info).save(output_filename)
if options.artatech_pdf:
packagers.ArtaTechPdfPackager.prepare(input_filenames, options.output_dir, options.verbose)
if options.virtualo:
- packagers.VirtualoEpubPackager.prepare(input_filenames, options.output_dir, options.verbose)
+ packagers.VirtualoPackager.prepare(input_filenames, options.output_dir, options.verbose)
if options.prestigio:
packagers.PrestigioEpubPackager.prepare(input_filenames, options.output_dir, options.verbose)
if options.prestigio_pdf: