Merge branch 'master' of https://github.com/fnp/librarian
authorLukasz <lukasz@anwajler.com>
Tue, 6 Jul 2010 08:23:12 +0000 (10:23 +0200)
committerLukasz <lukasz@anwajler.com>
Tue, 6 Jul 2010 08:23:12 +0000 (10:23 +0200)
librarian/epub.py [new file with mode: 0644]
librarian/epub/logo_wolnelektury.png [new file with mode: 0644]
librarian/epub/style.css [new file with mode: 0644]
librarian/epub/xsltAnnotations.xsl [new file with mode: 0644]
librarian/epub/xsltContent.xsl [new file with mode: 0644]
librarian/epub/xsltScheme.xsl [new file with mode: 0644]
librarian/epub/xsltTitle.xsl [new file with mode: 0644]

diff --git a/librarian/epub.py b/librarian/epub.py
new file mode 100644 (file)
index 0000000..50f9562
--- /dev/null
@@ -0,0 +1,359 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.  
+#
+from __future__ import with_statement
+
+import os
+import os.path
+import shutil
+import sys
+from copy import deepcopy
+from lxml import etree
+import zipfile
+
+from librarian import XMLNamespace, RDFNS, DCNS, WLNS, XHTMLNS
+
+NCXNS = XMLNamespace("http://www.daisy.org/z3986/2005/ncx/")
+OPFNS = XMLNamespace("http://www.idpf.org/2007/opf")
+
+
+def inner_xml(node):
+    """ returns node's text and children as a string
+
+    >>> print inner_xml(etree.fromstring('<a>x<b>y</b>z</a>'))
+    x<b>y</b>z
+    """
+
+    nt = node.text if node.text is not None else ''
+    return ''.join([nt] + [etree.tostring(child) for child in node]) 
+
+def set_inner_xml(node, text):
+    """ sets node's text and children from a string
+
+    >>> e = etree.fromstring('<a>b<b>x</b>x</a>')
+    >>> set_inner_xml(e, 'x<b>y</b>z')
+    >>> print etree.tostring(e)
+    <a>x<b>y</b>z</a>
+    """
+
+    
+    p = etree.fromstring('<x>%s</x>' % text)
+    node.text = p.text
+    node[:] = p[:]
+
+
+def node_name(node):
+    """ Find out a node's name
+
+    >>> print node_name(etree.fromstring('<a>X<b>Y</b>Z</a>'))
+    XYZ
+    """
+
+    tempnode = deepcopy(node)
+
+    for p in ('pe', 'pa', 'pt', 'pr', 'motyw'):
+        for e in tempnode.findall('.//%s' % p):
+            t = e.tail
+            e.clear()
+            e.tail = t
+    etree.strip_tags(tempnode, '*')
+    return tempnode.text
+
+
+def xslt(xml, sheet):
+    if isinstance(xml, etree._Element):
+        xml = etree.ElementTree(xml)
+    with open(sheet) as xsltf:
+        return xml.xslt(etree.parse(xsltf))
+
+
+_resdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'epub')
+def res(fname):
+    return os.path.join(_resdir, fname)
+
+
+def replace_characters(node):
+    def replace_chars(text):
+        if text is None:
+            return None
+        return text.replace("&", "&amp;")\
+                   .replace("---", "&#8212;")\
+                   .replace("--", "&#8211;")\
+                   .replace(",,", "&#8222;")\
+                   .replace('"', "&#8221;")\
+                   .replace("'", "&#8217;")
+    if node.tag == 'extra':
+        node.clear()
+    else:
+        node.text = replace_chars(node.text)
+        node.tail = replace_chars(node.tail)
+        for child in node:
+            replace_characters(child)
+
+
+def find_annotations(annotations, source, part_number):
+    for child in source:
+        if child.tag in ('pe', 'pa', 'pt', 'pr'):
+            annotation = deepcopy(child)
+            annotation.set('number', str(len(annotations)+1))
+            annotation.set('part', str(part_number))
+            annotation.tail = ''
+            annotations.append(annotation)
+            tail = child.tail
+            child.clear()
+            child.tail = tail
+            child.text = str(len(annotations))
+        if child.tag not in ('extra', 'podtytul'):
+            find_annotations(annotations, child, part_number)
+
+
+def replace_by_verse(tree):
+    """ Find stanzas and create new verses in place of a '/' character """
+    stanzas = tree.findall('.//' + WLNS('strofa'))
+    for node in stanzas:
+        for child_node in node:
+            if child_node.tag in ('slowo_obce', 'wyroznienie'):
+                foreign_verses = inner_xml(child_node).split('/\n')
+                if len(foreign_verses) > 1:
+                    new_foreign = ''
+                    for foreign_verse in foreign_verses:
+                        if foreign_verse.startswith('<wers'):
+                            new_foreign += foreign_verse
+                        else:
+                            new_foreign += ''.join(('<wers_normalny>', foreign_verse, '</wers_normalny>'))
+                    set_inner_xml(child_node, new_foreign)
+        verses = inner_xml(node).split('/\n')
+        if len(verses) > 1:
+            modified_inner_xml = ''
+            for verse in verses:
+                if verse.startswith('<wers') or verse.startswith('<extra'):
+                    modified_inner_xml += verse
+                else:
+                    modified_inner_xml += ''.join(('<wers_normalny>', verse, '</wers_normalny>'))
+            set_inner_xml(node, modified_inner_xml)
+
+
+def add_to_manifest(manifest, partno):
+    """ Adds a node to the manifest section in content.opf file """
+    partstr = 'part%d' % partno
+    e = manifest.makeelement(OPFNS('item'), attrib={
+                                 'id': partstr,
+                                 'href': partstr + '.html',
+                                 'media-type': 'application/xhtml+xml',
+                             })
+    manifest.append(e)
+
+
+def add_to_spine(spine, partno):
+    """ Adds a node to the spine section in content.opf file """
+    e = spine.makeelement(OPFNS('itemref'), attrib={'idref': 'part%d' % partno});
+    spine.append(e)
+
+
+def add_nav_point(nav_map, counter, title, part_counter):
+    nav_point = nav_map.makeelement(NCXNS('navPoint'))
+    nav_point.set('id', 'NavPoint-%d' % counter)
+    nav_point.set('playOrder', str(counter))
+
+    nav_label = nav_map.makeelement(NCXNS('navLabel'))
+    text = nav_map.makeelement(NCXNS('text'))
+    text.text = title
+    nav_label.append(text)
+    nav_point.append(nav_label)
+
+    content = nav_map.makeelement(NCXNS('content'))
+    content.set('src', 'part%d.html' % part_counter)
+    nav_point.append(content)
+
+    nav_map.append(nav_point)
+
+
+def add_nav_point2(nav_map, counter, title, part_counter, subcounter):
+    nav_point = nav_map.makeelement(NCXNS('navPoint'))
+    nav_point.set('id', 'NavPoint-%d' % counter)
+    nav_point.set('playOrder', str(counter))
+
+    nav_label = nav_map.makeelement(NCXNS('navLabel'))
+    text = nav_map.makeelement(NCXNS('text'))
+    text.text = title
+    nav_label.append(text)
+    nav_point.append(nav_label)
+
+    content = nav_map.makeelement(NCXNS('content'))
+    content.set('src', 'part%d.html#sub%d' % (part_counter, subcounter))
+    nav_point.append(content)
+
+    nav_map[-1].append(nav_point)
+
+
+def transform(input_file, output_file):
+    """ produces an epub
+
+    input_file and output_file should be filelike objects
+    """
+
+    input_xml = etree.parse(input_file)
+
+    zip = zipfile.ZipFile(output_file, 'w', zipfile.ZIP_DEFLATED)
+
+    mime = zipfile.ZipInfo()
+    mime.filename = 'mimetype'
+    mime.compress_type = zipfile.ZIP_STORED
+    mime.extra = ''
+    zip.writestr(mime, 'application/epub+zip')
+
+    zip.writestr('META-INF/container.xml', '<?xml version="1.0" ?><container version="1.0" ' \
+                       'xmlns="urn:oasis:names:tc:opendocument:xmlns:container">' \
+                       '<rootfiles><rootfile full-path="OPS/content.opf" ' \
+                       'media-type="application/oebps-package+xml" />' \
+                       '</rootfiles></container>')
+
+    metadata_el = input_xml.find('.//'+RDFNS('Description'))
+    metadatasource = etree.ElementTree(metadata_el)
+
+    opf = xslt(metadatasource, res('xsltContent.xsl'))
+
+    manifest = opf.find('.//' + OPFNS('manifest'))
+    spine = opf.find('.//' + OPFNS('spine'))
+
+    for fname in 'style.css', 'logo_wolnelektury.png':
+        zip.write(res(fname), os.path.join('OPS', fname))
+
+    annotations = etree.Element('annotations')
+    part_xml = etree.Element('utwor')
+    etree.SubElement(part_xml, 'master')
+
+    toc_file = etree.fromstring('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE ncx PUBLIC ' \
+                               '"-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">' \
+                               '<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" xml:lang="pl" ' \
+                               'version="2005-1"><head></head><docTitle></docTitle><navMap>' \
+                               '<navPoint id="NavPoint-1" playOrder="1"><navLabel>' \
+                               '<text>Strona tytułowa</text></navLabel><content src="title.html" />' \
+                               '</navPoint><navPoint id="NavPoint-2" playOrder="2"><navLabel>' \
+                               '<text>Początek utworu</text></navLabel><content src="part1.html" />' \
+                               '</navPoint></navMap></ncx>')
+
+    main_xml_part = part_xml[0] # było [0][0], master
+    nav_map = toc_file[-1] # było [-1][-1]
+    depth = 1 # navmap
+
+    if len(input_xml.getroot()) > 1:
+        # rdf before style master
+        main_text = input_xml.getroot()[1]
+    else:
+        # rdf in style master
+        main_text = input_xml.getroot()[0]
+
+    replace_characters(main_text)
+    zip.writestr('OPS/title.html', 
+                 etree.tostring(xslt(input_xml, res('xsltTitle.xsl')), pretty_print=True))
+
+    # Search for table of contents elements and book division
+
+    stupid_i = stupid_j = stupid_k = 1
+    last_node_part = False
+    for one_part in main_text:
+        name = one_part.tag
+        if name in ("naglowek_czesc", "naglowek_rozdzial", "naglowek_akt", "srodtytul"):
+            if name == "naglowek_czesc":
+                stupid_k = 1
+                last_node_part = True
+                find_annotations(annotations, part_xml, stupid_j)
+                replace_by_verse(part_xml)
+                zip.writestr('OPS/part%d.html' % stupid_j,
+                            etree.tostring(xslt(part_xml, res('xsltScheme.xsl')), pretty_print=True))
+                main_xml_part[:] = [deepcopy(one_part)]
+                # add to manifest and spine
+                add_to_manifest(manifest, stupid_j)
+                add_to_spine(spine, stupid_j)
+                name_toc = node_name(one_part)
+                # build table of contents
+                # i+2 because of title page
+                add_nav_point(nav_map, stupid_i+2, name_toc, stupid_j + 1)
+                stupid_i += 1
+                stupid_j += 1
+            else:
+                if last_node_part:
+                    main_xml_part.append(one_part)
+                    last_node_part = False
+                    name_toc = node_name(one_part)
+                    add_nav_point(nav_map, stupid_i + 1, name_toc, stupid_j)
+                else:
+                    stupid_k = 1
+                    find_annotations(annotations, part_xml, stupid_j)
+                    replace_by_verse(part_xml)
+                    zip.writestr('OPS/part%d.html' % stupid_j,
+                                 etree.tostring(xslt(part_xml, res('xsltScheme.xsl')), pretty_print=True))
+                    # start building a new part
+                    main_xml_part[:] = [deepcopy(one_part)]
+                    add_to_manifest(manifest, stupid_j)
+                    add_to_spine(spine, stupid_j)
+                    name_toc = node_name(one_part)
+                    add_nav_point(nav_map, stupid_i + 2, name_toc, stupid_j + 1) # title page
+                    stupid_j += 1
+                    stupid_i += 1
+        else:
+            if name in ('naglowek_podrozdzial', 'naglowek_scena'):
+                depth = 2
+                name_toc =  node_name(one_part)
+                add_nav_point2(nav_map, stupid_i + 2, name_toc, stupid_j, stupid_k)
+                one_part.set('sub', str(stupid_k))
+                stupid_k += 1
+                stupid_i += 1
+            main_xml_part.append(deepcopy(one_part))
+            last_node_part = False
+    find_annotations(annotations, part_xml, stupid_j)
+    replace_by_verse(part_xml)
+    add_to_manifest(manifest, stupid_j)
+    add_to_spine(spine, stupid_j)
+
+    zip.writestr('OPS/part%d.html' % stupid_j,
+                 etree.tostring(xslt(part_xml, res('xsltScheme.xsl')), pretty_print=True))
+
+    # Last modifications in container files and EPUB creation
+    if len(annotations) > 0:
+        nav_map.append(etree.fromstring(
+            '<navPoint id="NavPoint-%(i)d" playOrder="%(i)d" ><navLabel><text>Przypisy</text>'\
+            '</navLabel><content src="annotations.html" /></navPoint>' % {'i':stupid_i+2}))
+        manifest.append(etree.fromstring(
+            '<item id="annotations" href="annotations.html" media-type="application/xhtml+xml" />'))
+        spine.append(etree.fromstring(
+            '<itemref idref="annotations" />'))
+        replace_by_verse(annotations)
+        zip.writestr('OPS/annotations.html', etree.tostring(
+                            xslt(annotations, res("xsltAnnotations.xsl")), pretty_print=True))
+
+    zip.writestr('OPS/content.opf', etree.tostring(opf, pretty_print=True))
+    contents = []
+    title = node_name(etree.ETXPath('.//'+DCNS('title'))(input_xml)[0])
+    attributes = "dtb:uid", "dtb:depth", "dtb:totalPageCount", "dtb:maxPageNumber"
+    for st in attributes:
+        meta = toc_file.makeelement(NCXNS('meta'))
+        meta.set('name', st)
+        meta.set('content', '0')
+        toc_file[0].append(meta)
+    toc_file[0][0].set('content', ''.join((title, 'WolneLektury.pl')))
+    toc_file[0][1].set('content', str(depth))
+    set_inner_xml(toc_file[1], ''.join(('<text>', title, '</text>')))
+    zip.writestr('OPS/toc.ncx', etree.tostring(toc_file, pretty_print=True))
+    zip.close()
+
+
+if __name__ == '__main__':
+    if len(sys.argv) < 2:
+        print >> sys.stderr, 'Usage: wl2epub <input file> [output file]'
+        sys.exit(1)
+
+    input = sys.argv[1]
+    if len(sys.argv) > 2:
+        output = sys.argv[2]
+    else:
+        basename, ext = os.path.splitext(input)
+        output = basename + '.epub' 
+
+    wl2epub(open(input, 'r'), open(output, 'w'))
+
+
+
diff --git a/librarian/epub/logo_wolnelektury.png b/librarian/epub/logo_wolnelektury.png
new file mode 100644 (file)
index 0000000..104d56a
Binary files /dev/null and b/librarian/epub/logo_wolnelektury.png differ
diff --git a/librarian/epub/style.css b/librarian/epub/style.css
new file mode 100644 (file)
index 0000000..652d903
--- /dev/null
@@ -0,0 +1,317 @@
+body\r
+{\r
+       font-size: 12pt;\r
+       font: Georgia, "Times New Roman" , serif;\r
+       line-height: 1.5em;\r
+       margin: 0;\r
+}\r
+\r
+a\r
+{\r
+       color: black;\r
+       text-decoration: none;\r
+}\r
+\r
+#book-text\r
+{\r
+       margin: 2em;\r
+       /*margin-right: 9em;*/\r
+}\r
+\r
+/* =================================================== */\r
+/* = Common elements: headings, paragraphs and lines = */\r
+/* =================================================== */\r
+\r
+\r
+.h2\r
+{\r
+       size: big;\r
+       font-size: 2em;\r
+       margin: 0;\r
+       margin-top: 1.5em;\r
+       font-weight: bold;\r
+       line-height: 1.5em;\r
+}\r
+\r
+.h3\r
+{\r
+       text-align:left;\r
+    font-size: 1.5em;\r
+    margin-top: 1.5em;\r
+    font-weight: normal;\r
+    line-height: 1.5em;\r
+}\r
+\r
+.h4\r
+{\r
+       font-size: 1em;\r
+    margin: 0;\r
+    margin-top: 1.5em;\r
+       line-height: 1.5em;\r
+}\r
+\r
+p\r
+{\r
+       margin: 0;\r
+}\r
+\r
+/* ======================== */\r
+/* = Footnotes and themes = */\r
+/* ======================== */\r
+\r
+.theme-begin\r
+{\r
+       border-left: 0.1em solid #DDDDDD;\r
+       color: #777;\r
+       padding: 0 0.5em;\r
+       width: 7.5em;\r
+       font-style: normal;\r
+       font-weight: normal;\r
+       font-size: 0.875em;\r
+       float: right;\r
+       margin-right: -9.5em;\r
+       clear: both;\r
+       left: 40em;\r
+       line-height: 1.5em;\r
+       text-align: left;\r
+}\r
+\r
+.annotation\r
+{\r
+       font-style: normal;\r
+       font-weight: normal;\r
+       font-size: 0.875em;\r
+}\r
+\r
+#footnotes .annotation\r
+{\r
+       display: block;\r
+       float: left;\r
+       width: 2.5em;\r
+       clear: both;\r
+}\r
+\r
+#footnotes div\r
+{\r
+    margin: 0;\r
+    margin-top: 1.5em;\r
+}\r
+\r
+#footnotes p\r
+{\r
+       margin-left: 2.5em;\r
+       font-size: 0.875em;\r
+}\r
+\r
+.block\r
+{\r
+       font-size: 0.875em;\r
+       padding: 1em;\r
+}\r
+\r
+/* ============= */\r
+/* = Numbering = */\r
+/* ============= */\r
+\r
+.anchor\r
+{\r
+       margin: -0.25em -0.5em;\r
+       color: #777;\r
+       font-size: 0.875em;\r
+       width: 2em;\r
+       text-align: center;\r
+       padding: 0.25em 0.5em;\r
+       line-height: 1.5em;\r
+}\r
+\r
+/* =================== */\r
+/* = Custom elements = */\r
+/* =================== */\r
+\r
+.title-page\r
+{\r
+    margin-top: 1.5em;\r
+}\r
+\r
+.title\r
+{\r
+    font-size: 3em;\r
+    margin-bottom: 1.5em;\r
+    text-align: center;\r
+    line-height: 1.5em;\r
+    font-weight: bold;\r
+}\r
+\r
+.author\r
+{\r
+    margin: 0;\r
+    text-align: center;\r
+    font-weight: bold;\r
+\r
+    font-size: 1.5em;\r
+    line-height: 1.5em;\r
+    margin-bottom: 0.25em;\r
+}\r
+\r
+.collection\r
+{\r
+    margin: 0;\r
+    text-align: center;\r
+    font-weight: bold;\r
+\r
+       font-size: 1.125em;\r
+       line-height: 1.5em;\r
+       margin-bottom: -0.25em;\r
+}\r
+\r
+.subtitle\r
+{\r
+    margin: 0;\r
+    text-align: center;\r
+    font-weight: bold;\r
+\r
+       font-size: 1.5em;\r
+       line-height: 1.5em;\r
+       margin-top: -0.25em;\r
+}\r
+\r
+div.didaskalia\r
+{\r
+       font-style: italic;\r
+       margin-top: 0.5em;\r
+       margin-left: 1.5em;\r
+}\r
+\r
+div.kwestia\r
+{\r
+       margin-top: 0.5em;\r
+}\r
+\r
+div.stanza\r
+{\r
+       margin-top: 1.5em;\r
+}\r
+\r
+.paragraph\r
+{\r
+       text-align: justify;\r
+       margin-top: 1.5em;\r
+}\r
+\r
+.motto\r
+{\r
+       text-align: justify;\r
+       font-style: italic;\r
+       margin-top: 1.5em;\r
+}\r
+\r
+.motto_podpis\r
+{\r
+       font-size: 0.875em;\r
+       text-align: right;\r
+}\r
+\r
+div.fragment\r
+{\r
+       border-bottom: 0.1em solid #999;\r
+       padding-bottom: 1.5em;\r
+}\r
+\r
+div.note\r
+{\r
+       text-align: right;\r
+       font-style: italic;\r
+}\r
+div.note div.paragraph\r
+{\r
+    text-align: right;\r
+    font-style: italic;\r
+}\r
+div.dedication\r
+{\r
+    text-align: right;\r
+    font-style: italic;\r
+}\r
+div.dedication div.paragaph\r
+{\r
+    text-align: right;\r
+    font-style: italic;\r
+}\r
+\r
+\r
+hr.spacer\r
+{\r
+       height: 3em;\r
+       visibility: hidden;\r
+}\r
+\r
+hr.spacer-line\r
+{\r
+       margin: 0;\r
+       margin-top: 1.5em;\r
+       margin-bottom: 1.5em;\r
+       border: none;\r
+       border-bottom: 0.1em solid #000;\r
+}\r
+\r
+.spacer-asterisk\r
+{\r
+       padding: 0;\r
+    margin: 0;\r
+    margin-top: 1.5em;\r
+    margin-bottom: 1.5em;\r
+       text-align: center;\r
+}\r
+\r
+div.person-list ol\r
+{\r
+       list-style: none;\r
+       padding: 0;\r
+       padding-left: 1.5em;\r
+}\r
+\r
+.place-and-time\r
+{\r
+       font-style: italic;\r
+}\r
+\r
+em.math\r
+{\r
+       font-style: italic;\r
+}\r
+em.foreign-word\r
+{\r
+    font-style: italic;\r
+}\r
+em.book-title\r
+{\r
+    font-style: italic;\r
+}\r
+em.didaskalia\r
+{\r
+    font-style: italic;\r
+}\r
+\r
+em.author-emphasis\r
+{\r
+       letter-spacing: 0.1em;\r
+}\r
+\r
+em.person\r
+{\r
+       font-style: normal;\r
+       font-variant: small-caps;\r
+}\r
+\r
+p.info\r
+{\r
+       text-align: center;\r
+       margin-bottom: 1em;\r
+}\r
+\r
+p.info img\r
+{\r
+       margin: 0;\r
+       margin-left: 2em;\r
+       margin-right: 2em;\r
+}\r
diff --git a/librarian/epub/xsltAnnotations.xsl b/librarian/epub/xsltAnnotations.xsl
new file mode 100644 (file)
index 0000000..d0af8ab
--- /dev/null
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\r
+  <xsl:output method="html" version="1.0" encoding="utf-8" />\r
+  <xsl:output doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" />\r
+  <xsl:output doctype-public="-//W3C//DTD XHTML 1.1//EN" />\r
+\r
+  <xsl:template match="/">\r
+    <html xmlns="http://www.w3.org/1999/xhtml">\r
+      <head>\r
+        <link rel="stylesheet" href="style.css" type="text/css" />\r
+        <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />\r
+        <title>\r
+          <xsl:text>Przypisy</xsl:text>\r
+        </title>\r
+      </head>\r
+      <body>\r
+        <div id="book-text" xmlns="http://www.w3.org/1999/xhtml">\r
+          <div id="footnotes" xmlns="http://www.w3.org/1999/xhtml">\r
+            <h2 xmlns="http://www.w3.org/1999/xhtml">\r
+              Przypisy:\r
+            </h2>\r
+            <xsl:apply-templates mode="przypis" />\r
+          </div>\r
+        </div>\r
+      </body>\r
+    </html>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="text()" >\r
+    <xsl:value-of select="." disable-output-escaping="yes"/>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="pa|pe|pr|pt" mode="przypis">\r
+    <div xmlns="http://www.w3.org/1999/xhtml">\r
+      <p id="annotation-{@number}" xmlns="http://www.w3.org/1999/xhtml"></p>\r
+      <a class="annotation" href="part{@part}.html#anchor-{@number}" xmlns="http://www.w3.org/1999/xhtml">\r
+        [<xsl:value-of select="@number" />]\r
+      </a>\r
+      <p xmlns="http://www.w3.org/1999/xhtml">\r
+        <xsl:apply-templates />\r
+      </p>\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="slowo_obce">\r
+    <em class="foreign-word" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates select="text()" />\r
+    </em>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="akap|akap_cd">\r
+    <p class="paragraph" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </p>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="strofa">\r
+    <div class="stanza" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="tytul_dziela" >\r
+    <em class="book-title" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:if test="@typ = '1'" >„</xsl:if>\r
+      <xsl:apply-templates />\r
+      <xsl:if test="@typ = '1'">”</xsl:if>\r
+    </em>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="wers_normalny">\r
+    <p class="verse" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </p>\r
+  </xsl:template>\r
+\r
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/librarian/epub/xsltContent.xsl b/librarian/epub/xsltContent.xsl
new file mode 100644 (file)
index 0000000..548bcb7
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/">\r
+  <xsl:output method="html" version="1.0" omit-xml-declaration="no" />\r
+\r
+  <xsl:template match="/">\r
+    <package xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" version="2.0">\r
+      <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:opf="http://www.idpf.org/2007/opf">\r
+        <xsl:apply-templates select="//dc:title" />\r
+        <dc:language xsi:type="dcterms:RFC3066">\r
+          <xsl:apply-templates select="//dc:language" />\r
+        </dc:language>\r
+        <dc:identifier id="BookId" opf:scheme="URI">\r
+          <xsl:apply-templates select="//dc:identifier.url" />\r
+        </dc:identifier>\r
+        <dc:subject>\r
+          <xsl:apply-templates select="//dc:identifier.url" />\r
+        </dc:subject>\r
+        <dc:creator>\r
+          <xsl:apply-templates select="//dc:creator" />\r
+        </dc:creator>\r
+        <dc:publisher>\r
+          <xsl:apply-templates select="//dc:publisher" />\r
+        </dc:publisher>\r
+        <dc:date xsi:type="dcterms:W3CDTF">\r
+          <xsl:apply-templates select="//dc:date" />\r
+        </dc:date>\r
+      </metadata>\r
+      <manifest>\r
+        <item id="toc" href="toc.ncx" media-type="application/x-dtbncx+xml" />\r
+        <item id="style" href="style.css" media-type="text/css" />\r
+        <item id="titlePage" href="title.html" media-type="application/xhtml+xml" />\r
+        <item id="logo_wolnelektury" href="logo_wolnelektury.png" media-type="image/png" />\r
+      </manifest>\r
+      <spine toc="toc">\r
+        <itemref idref="titlePage" />\r
+      </spine>\r
+    </package>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="dc:title" >\r
+    <dc:title>\r
+      <xsl:value-of select="." />\r
+    </dc:title>\r
+  </xsl:template>\r
+\r
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/librarian/epub/xsltScheme.xsl b/librarian/epub/xsltScheme.xsl
new file mode 100644 (file)
index 0000000..109b1cc
--- /dev/null
@@ -0,0 +1,342 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\r
+  <xsl:output method="html" version="1.0" encoding="utf-8" />\r
+  <xsl:output doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" />\r
+  <xsl:output doctype-public="-//W3C//DTD XHTML 1.1//EN" />\r
+\r
+  <xsl:template match="/" >\r
+    <xsl:element name="html" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:element name="head">\r
+        <link rel="stylesheet" href="style.css" type="text/css" />\r
+        <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />\r
+        <title>\r
+          WolneLektury.pl\r
+        </title>\r
+      </xsl:element>\r
+      <xsl:element name="body" xmlns="http://www.w3.org/1999/xhtml">\r
+        <xsl:element name="div" xmlns="http://www.w3.org/1999/xhtml">\r
+          <xsl:attribute name="id">book-text</xsl:attribute>\r
+          <xsl:if test="//nazwa_utworu">\r
+            <!--h1 xmlns="http://www.w3.org/1999/xhtml"-->\r
+              <xsl:apply-templates select=" //nazwa_utworu" mode="poczatek"/>\r
+            <!--/h1-->\r
+          </xsl:if>\r
+          <xsl:apply-templates />\r
+        </xsl:element>\r
+      </xsl:element>\r
+    </xsl:element>\r
+  </xsl:template>\r
+\r
+  <!--===========================================================-->\r
+  <!-- Tagi BLOKOWE -->\r
+  <!--===========================================================-->\r
+\r
+  <xsl:template match="nota">\r
+    <div class="note" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="lista_osob" >\r
+    <div class="person-list" xmlns="http://www.w3.org/1999/xhtml">\r
+      <div class="h3" xmlns="http://www.w3.org/1999/xhtml">\r
+        <xsl:apply-templates select="child::naglowek_listy" />\r
+      </div>\r
+      <ol xmlns="http://www.w3.org/1999/xhtml">\r
+        <xsl:apply-templates select="lista_osoba" />\r
+      </ol>\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="dedykacja">\r
+    <div class="dedication" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="kwestia">\r
+    <div class="kwestia" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates select="strofa|akapit|didaskalia|akap " />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="dlugi_cytat|poezja_cyt">\r
+    <div class="block" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="motto">\r
+    <div class="motto" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <!--===========================================================-->\r
+  <!-- Tagi PARAGRAFOWE -->\r
+  <!--===========================================================-->\r
+\r
+  <xsl:template match="autor_utworu" mode="poczatek">\r
+    <h2 class="author" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </h2>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="autor_utworu" />\r
+\r
+  <xsl:template match="dzielo_nadrzedne" mode="poczatek">\r
+    <h2 class="collection" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </h2>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="dzielo_nadrzedne" />\r
+\r
+  <xsl:template match="nazwa_utworu" mode="poczatek" >\r
+    <h2 class="author" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </h2>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="nazwa_utworu" />\r
+\r
+  <xsl:template match="podtytul" mode="poczatek">\r
+    <h2 class="subtitle" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </h2>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="podtytul" />\r
+\r
+  <xsl:template match="naglowek_czesc|srodtytul">\r
+    <h2 class="h2" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </h2>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="naglowek_akt">\r
+    <h2 class="h2" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </h2>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="naglowek_scena">\r
+    <a id="sub{@sub}" xmlns="http://www.w3.org/1999/xhtml"></a>\r
+    <h2 class="h3" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </h2>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="naglowek_podrozdzial">\r
+    <a id="sub{@sub}" xmlns="http://www.w3.org/1999/xhtml"></a>\r
+    <h2 class="h4" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </h2>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="naglowek_rozdzial">\r
+    <h2 class="h3" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </h2>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="naglowek_osoba">\r
+    <h2 class="h4" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </h2>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="miejsce_czas">\r
+    <div class="place-and-time" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="didaskalia">\r
+    <div class="didaskalia" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="akap|akap_dialog|akap_cd">\r
+    <div class="paragraph" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="strofa">\r
+    <div class="stanza" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="wers_normalny">\r
+    <div class="verse" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="wers_wciety">\r
+    <div class="verse" style="padding-left: 1em;" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="wers_wciety[@typ='1']">\r
+    <div class="verse" style="padding-left: 1em;" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="wers_wciety[@typ='2']">\r
+    <div class="verse" style="padding-left: 2em;" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="wers_wciety[@typ='3']">\r
+    <div class="verse" style="padding-left: 3em;" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="wers_wciety[@typ='4']">\r
+    <div class="verse" style="padding-left: 4em;" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="wers_wciety[@typ='5']">\r
+    <div class="verse" style="padding-left: 5em;" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="wers_wciety[@typ='6']">\r
+    <div class="verse" style="padding-left: 6em;" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="wers_cd">\r
+    <div class="verse" style="padding-left: 12em;" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="motto_podpis">\r
+    <div class="motto_podpis" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <!--===========================================================-->\r
+  <!-- Tagi LINIOWE -->\r
+  <!--===========================================================-->\r
+\r
+  <xsl:template match="slowo_obce">\r
+    <em class="foreign-word" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </em>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="mat" >\r
+    <em class="math" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </em>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="didask_tekst" >\r
+    <em class="didaskalia" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </em>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="tytul_dziela" >\r
+    <em class="book-title" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:if test="@typ = '1'" >„</xsl:if>\r
+      <xsl:apply-templates />\r
+      <xsl:if test="@typ = '1'">”</xsl:if>\r
+    </em>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="wyroznienie" >\r
+    <em class="author-emphasis" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </em>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="osoba" >\r
+    <em class="person" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </em>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="naglowek_listy"  >\r
+    <xsl:apply-templates />\r
+  </xsl:template>\r
+\r
+  <xsl:template match="lista_osoba" >\r
+    <li xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </li>\r
+  </xsl:template>\r
+\r
+  <!--===========================================================-->\r
+  <!-- Tagi STANDALONE -->\r
+  <!--===========================================================-->\r
+\r
+  <xsl:template match="sekcja_swiatlo">\r
+    <hr class="spacer" xmlns="http://www.w3.org/1999/xhtml"></hr>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="sekcja_asterysk">\r
+    <p class="spacer-asterisk" xmlns="http://www.w3.org/1999/xhtml">*</p>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="separator_linia">\r
+    <hr class="spacer-line" xmlns="http://www.w3.org/1999/xhtml"></hr>\r
+  </xsl:template>\r
+\r
+  <!--===========================================================-->\r
+  <!-- Tagi SPECJALNE -->\r
+  <!--===========================================================-->\r
+\r
+  <!--xsl:template match="motyw" >\r
+    <a class="theme-begin" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates select="text()" />\r
+    </a>\r
+  </xsl:template-->\r
+  <xsl:template match="motyw" />\r
+\r
+  <!--===========================================================-->\r
+  <!-- Tagi IGNOROWANE -->\r
+  <!--===========================================================-->\r
+\r
+  <xsl:template match="pe|pa|pr|pt" />\r
+\r
+  <xsl:template match="extra" />\r
+\r
+  <xsl:template match="pe|pa|pr|pt" >\r
+    <a id="anchor-{.}" class="anchor" href="annotations.html#annotation-{.}" \r
+       xmlns="http://www.w3.org/1999/xhtml">[<xsl:apply-templates />]</a>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="uwaga" />\r
+\r
+  <!--pominięcie tych metadanych-->\r
+  <xsl:template match="rdf:RDF" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" />\r
+\r
+  <!--===========================================================-->\r
+  <!-- Tagi TEKSTOWE -->\r
+  <!--===========================================================-->\r
+\r
+  <xsl:template match="text()"  >\r
+    <xsl:value-of select="." disable-output-escaping="yes"/>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="text()" >\r
+    <xsl:value-of select="." disable-output-escaping="yes"/>\r
+  </xsl:template>\r
+\r
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/librarian/epub/xsltTitle.xsl b/librarian/epub/xsltTitle.xsl
new file mode 100644 (file)
index 0000000..c69db26
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/">\r
+  <xsl:output method="html" version="1.0" encoding="utf-8" />\r
+  <xsl:output doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" />\r
+  <xsl:output doctype-public="-//W3C//DTD XHTML 1.1//EN" />\r
+\r
+  <xsl:template match="/">\r
+    <html xmlns="http://www.w3.org/1999/xhtml">\r
+      <head>\r
+        <link rel="stylesheet" href="style.css" type="text/css" />\r
+        <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />\r
+        <title>\r
+          <xsl:text>Strona tytułowa</xsl:text>\r
+        </title>\r
+      </head>\r
+      <body>\r
+        <div id="book-text" xmlns="http://www.w3.org/1999/xhtml">\r
+          <div class='title-page'>\r
+            <xsl:choose>\r
+              <xsl:when test="//autor_utworu | //nazwa_utworu">\r
+                <xsl:apply-templates select="//autor_utworu | //nazwa_utworu | //podtytul | //dzielo_nadrzedne" mode="poczatek"/>\r
+              </xsl:when>\r
+              <xsl:otherwise>\r
+                <xsl:apply-templates select="//dc:creator | //dc:title | //podtytul | //dzielo_nadrzedne" mode="poczatek"/>\r
+              </xsl:otherwise>\r
+            </xsl:choose>\r
+          </div>\r
+          <p class="info">Publikacja zrealizowana w ramach projektu WolneLektury.pl</p>\r
+          <p class="info">\r
+            <img src="logo_wolnelektury.png" alt="WolneLektury.pl" />\r
+          </p>\r
+        </div>\r
+      </body>\r
+    </html>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="text()" >\r
+    <xsl:value-of select="." disable-output-escaping="yes" />\r
+  </xsl:template>\r
+\r
+  <xsl:template match="node()" mode="poczatek">\r
+    <xsl:value-of select="." />\r
+  </xsl:template>\r
+\r
+  <xsl:template match="dc:creator" mode="poczatek">\r
+    <div class="author" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="autor_utworu" mode="poczatek">\r
+    <div class="author" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="dzielo_nadrzedne" mode="poczatek">\r
+    <div class="collection" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="nazwa_utworu" mode="poczatek" >\r
+    <h1 class="title" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </h1>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="dc:title" mode="poczatek" >\r
+    <h1 class="title" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </h1>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="podtytul" mode="poczatek">\r
+    <div class="subtitle" xmlns="http://www.w3.org/1999/xhtml">\r
+      <xsl:apply-templates />\r
+    </div>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="pe|pa|pr|pt" />\r
+\r
+  <xsl:template match="extra" />\r
+\r
+  <xsl:template match="pe|pa|pr|pt" />\r
+\r
+  <xsl:template match="extra" />\r
+\r
+  <xsl:template match="motyw" />\r
+\r
+</xsl:stylesheet>
\ No newline at end of file