fnp
/
librarian.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add Hebrew support in pdfs.
[librarian.git]
/
src
/
librarian
/
html.py
diff --git
a/src/librarian/html.py
b/src/librarian/html.py
index
c2f41c0
..
d6482dc
100644
(file)
--- a/
src/librarian/html.py
+++ b/
src/librarian/html.py
@@
-9,7
+9,7
@@
import urllib.parse
import urllib.request
from lxml import etree
import urllib.request
from lxml import etree
-from librarian import XHTMLNS, ParseError, OutputFile
+from librarian import XHTMLNS,
DCNS,
ParseError, OutputFile
from librarian import functions
from PIL import Image
from librarian import functions
from PIL import Image
@@
-39,7
+39,7
@@
def transform_abstrakt(abstrakt_element):
style = etree.parse(style_filename)
xml = etree.tostring(abstrakt_element, encoding='unicode')
document = etree.parse(io.StringIO(
style = etree.parse(style_filename)
xml = etree.tostring(abstrakt_element, encoding='unicode')
document = etree.parse(io.StringIO(
- xml.replace('
abstrakt', '
dlugi_cytat')
+ xml.replace('
<abstrakt', '<dlugi_cytat').replace('</abstrakt', '</
dlugi_cytat')
)) # HACK
result = document.xslt(style)
html = re.sub('<a name="sec[0-9]*"/>', '',
)) # HACK
result = document.xslt(style)
html = re.sub('<a name="sec[0-9]*"/>', '',
@@
-49,6
+49,10
@@
def transform_abstrakt(abstrakt_element):
def add_image_sizes(tree, gallery_path, gallery_url, base_url):
widths = [360, 600, 1200, 1800, 2400]
def add_image_sizes(tree, gallery_path, gallery_url, base_url):
widths = [360, 600, 1200, 1800, 2400]
+ try:
+ os.makedirs(gallery_path)
+ except:
+ pass
for i, ilustr in enumerate(tree.findall('//ilustr')):
rel_path = ilustr.attrib['src']
for i, ilustr in enumerate(tree.findall('//ilustr')):
rel_path = ilustr.attrib['src']
@@
-108,9
+112,14
@@
def transform(wldoc, stylesheet='legacy', options=None, flags=None, css=None, ga
for flag in flags:
document.edoc.getroot().set(flag, 'yes')
for flag in flags:
document.edoc.getroot().set(flag, 'yes')
+ ltag = document.edoc.find('//' + DCNS('language'))
+ lang = functions.lang_code_3to2(ltag.text) or 'pl'
+ document.edoc.getroot().set('lang', lang)
+
document.clean_ed_note()
document.clean_ed_note('abstrakt')
document.fix_pa_akap()
document.clean_ed_note()
document.clean_ed_note('abstrakt')
document.fix_pa_akap()
+ document.hebr_protect()
if not options:
options = {}
if not options:
options = {}
@@
-307,7
+316,8
@@
def any_ancestor(element, test):
def add_anchors(root):
def add_anchors(root):
- counter = 1
+ link_prefix = "f"
+ counter = {"f": 1}
visible_counter = 1
for element in root.iterdescendants():
def f(e):
visible_counter = 1
for element in root.iterdescendants():
def f(e):
@@
-325,18
+335,21
@@
def add_anchors(root):
visible_counter = int(element.get('data-start'))
except ValueError:
visible_counter = 1
visible_counter = int(element.get('data-start'))
except ValueError:
visible_counter = 1
+ if element.get("data-link"):
+ link_prefix = element.get("data-link")
+ counter[link_prefix] = 1
if any_ancestor(element, f):
continue
if element.tag == 'div' and 'verse' in element.get('class', ''):
if visible_counter == 1 or visible_counter % 5 == 0:
if any_ancestor(element, f):
continue
if element.tag == 'div' and 'verse' in element.get('class', ''):
if visible_counter == 1 or visible_counter % 5 == 0:
- add_anchor(element, "
f%d" % counter
, link_text=visible_counter)
- counter += 1
+ add_anchor(element, "
%s%d" % (link_prefix, counter[link_prefix])
, link_text=visible_counter)
+ counter
[link_prefix]
+= 1
visible_counter += 1
elif 'paragraph' in element.get('class', ''):
visible_counter += 1
elif 'paragraph' in element.get('class', ''):
- add_anchor(element, "
f%d" % counter
, link_text=visible_counter)
- counter += 1
+ add_anchor(element, "
%s%d" % (link_prefix, counter[link_prefix])
, link_text=visible_counter)
+ counter
[link_prefix]
+= 1
visible_counter += 1
visible_counter += 1