Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/epub/create_epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from zipfile import ZipFile
from datetime import datetime

import src.html.create_songs_html as cash
from src.html.kindle_html_converter import KindleHtmlConverter
from src.html import html_converter_utils as converter_utils
from src.html import song_utils

import src.lib.songbook as sb
import src.lib.any_index_generator as aig
import src.lib.img2cover.img2cover as img2cover
Expand All @@ -25,7 +28,7 @@ def actual_datetime():
# def name_of_file(song):
# return os.path.splitext(os.path.split(song)[1])[0]

CSS_FILES = ["song.css", "common.css", "song_common.css", "index.css"]
CSS_FILES = ["song_kindle.css", "common.css", "song_common.css", "index.css"]

def create_content_opf(songbook, list_of_songs_meta, target_dir, pre_files=[], post_files=[]):
tmp_path =os.path.join(sb.repo_dir(), "src", "epub", "templates", "content.opf")
Expand Down Expand Up @@ -220,11 +223,11 @@ def create_toc_xhtml(list_of_songs_meta, target_dir, page_suffix):

et = etree.ElementTree(root)
et.write(out_path, pretty_print=True, method='xml', encoding='utf-8', xml_declaration=True)
cash.replace_in_file(out_path, out_path, lambda s: s.replace("</li><li>","</li>\n\t\t<li>").replace("><ol>",">\n<ol>"))
converter_utils.replace_in_file(out_path, out_path, lambda s: s.replace("</li><li>","</li>\n\t\t<li>").replace("><ol>",">\n<ol>"))
return files

def resolveTemplate(songbook, from_file, to_file):
return cash.replace_in_file(from_file, to_file,
return converter_utils.replace_in_file(from_file, to_file,
lambda s: (s.replace(":date:", actual_date())
.replace(":datetime:", actual_datetime())
.replace(":title:", songbook.title())
Expand Down Expand Up @@ -290,7 +293,8 @@ def create_full_epub(songbook, target_dir):

create_template_epub(songbook, target_dir)
path_out = os.path.join(target_dir, "epub", "OEBPS")
cash.create_all_songs_html(los, path_out, list([suffix]))
converter = KindleHtmlConverter()
song_utils.create_all_songs_html(converter, los, path_out, list([suffix]))
files = []
files.extend(create_toc_xhtml(los, target_dir, page_suffix = suffix))

Expand Down
2 changes: 1 addition & 1 deletion src/epub/templates/content.opf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<item id="start" href="songs.xhtml" media-type="application/xhtml+xml"/>
<!--item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/-->
<item id="common_css" href="CSS/common.css" media-type="text/css"/>
<item id="song_css" href="CSS/song.css" media-type="text/css"/>
<item id="song_css" href="CSS/song_kindle.css" media-type="text/css"/>
<item id="index_css" href="CSS/index.css" media-type="text/css"/>
<item id="song_common_css" href="CSS/song_common.css" media-type="text/css"/>
</manifest>
Expand Down
162 changes: 162 additions & 0 deletions src/epub/templates/song_kindle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
@import url('common.css');

body {
font-family: sans-serif;
}

div.song_body {
width: max-content;
display: table;
}

/* Per block settings - Chorus, Verses, Instrumental */

div.verse, div.chorus, div.other {
display: contents;
}

div.chorus div.row span.lyric {
padding-left: 3ex;
}

div.block_spacer {
display: table-row;
empty-cells: show;
height: 2.5ex;
}

/* Per row settings*/

div.row {
display: table-row;
page-break-inside: avoid;
page-break-after: avoid;
}

div.row:last-of-type {
page-break-after: auto;
}

/* Lyrics */

span.block_id, span.lyric, span.chords, span.bis_inactive, span.bis_active, span.chords_ins {
display: table-cell;
}

span.block_id {
padding-top: 1ex;
page-break-inside: avoid;
page-break-after: avoid;
}
/* margin-right: 0.5em;*/
/*}*/

/* As there is no call-span in CSS we allow the instrumental row to overflow */
span.chords_ins {
max-width: 5em;
padding-left: 1em;
text-overflow: ellipsis;
white-space: nowrap;
}

/* Chords above the text */

span.lyric span.chunk {
display: inline-table;
/*border: 1px solid green;*/
vertical-align: bottom;
}

span.lyric span.chord {
display: table-row;
/*border: 1px solid orange;*/
max-height: 0;
}

span.lyric span.chord span.ch{
display: table-cell;
}

span.lyric span.content {
display: table-row;
/*border: 1px solid red;*/
/*overflow-wrap: normal;*/
/*white-space: nowrap;*/
/*hyphens: none;*/
}

span.lyric span.content-i {
display: table-cell;
/*border: 1px solid red;*/
white-space: pre-line;
overflow-wrap: normal;
/*white-space: nowrap;*/
/*empty-cells: show;*/
hyphens: none;
height: 2.2ex;
}

span.ws {
display: inline-block;
width: 0.5ex;
opacity: 0;
}

div.over_false span.lyric span.ch {
display: none;
}

/*!* Generic styling*!*/

h1 {
text-align: left;
}

span.lyric span.ch {
font-family: sans-serif;
font-size: xx-small;
font-weight: bolder;
}

span.ch {
font-family: sans-serif;
font-weight: bolder;
}

span.chords span.ch {
padding-right: 0.3em;
}

span.chords {
padding-left: 1em;
padding-right: 1em;
max-width: 10em;
overflow-wrap: break-word;

/* not sure if needed... commenting for now*/
/* overflow-wrap: break-word;*/
/* hyphens: none;*/
/* white-space: nowrap;*/
}

div.row > span.bis_inactive {
padding-right: 0.4em;
empty-cells: show;
width: 2em;
}

div.row > span.bis_active {
padding-left: 0.4em;
padding-right: 0.3em;
border-right: solid;
empty-cells: show;
text-align: right;
width: 2em; /* fixed length makes it more likely on kindle to finish at the same place */
}

div.comment {
margin-top: 1.5em;
font-style: italic;
white-space: pre-wrap;
font-size: 0.7em;
}
1 change: 1 addition & 0 deletions src/html/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty file to mark directory as Python package
Loading