X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/724310b910f3ec0aeb2a1fbd0189d5f588a00f8f..515398ba21b6ac3c0db230a465cfc8528db8d10e:/librarian/pyhtml.py
diff --git a/librarian/pyhtml.py b/librarian/pyhtml.py
index 6d1e914..1f1f3df 100644
--- a/librarian/pyhtml.py
+++ b/librarian/pyhtml.py
@@ -13,6 +13,17 @@ from copy import deepcopy
IMAGE_THUMB_WIDTH = 300
+try:
+ from fnpdjango.utils.text.slughifi import slughifi
+ def naglowek_to_anchor(naglowek):
+ return slughifi(naglowek.text)
+except ImportError:
+ from urllib import quote
+ def naglowek_to_anchor(naglowek):
+ return quote(re.sub(r" +", " ", naglowek.text.strip()))
+
+
+
class EduModule(Xmill):
def __init__(self, options=None):
super(EduModule, self).__init__(options)
@@ -54,25 +65,22 @@ class EduModule(Xmill):
handle_tytul_dziela = tag('em', 'title')
handle_slowo_obce = tag('em', 'foreign')
- def naglowek_to_anchor(self, naglowek):
- return re.sub(r" +", " ", naglowek.text.strip())
-
def handle_nazwa_utworu(self, element):
toc = []
for naglowek in element.getparent().findall('.//naglowek_rozdzial'):
a = etree.Element("a")
- a.attrib["href"] = "#" + self.naglowek_to_anchor(naglowek)
+ a.attrib["href"] = "#" + naglowek_to_anchor(naglowek)
a.text = naglowek.text
atxt = etree.tostring(a, encoding=unicode)
toc.append("
%s" % atxt)
toc = "" % "".join(toc)
add_header = "Lekcja: " if self.options['wldoc'].book_info.type in ('course', 'synthetic') else ''
- return "%s" % add_header, "
" + toc
+ return "%s" % add_header, "
" + toc
def handle_naglowek_rozdzial(self, element):
return_to_top = u"wrÃ³Ä do spisu treÅci"
- anchor = "".join(tag_open_close("a", name=self.naglowek_to_anchor(element)))
- return return_to_top + "", anchor + "
"
+ pre, post = tag_open_close("h2", id=naglowek_to_anchor(element))
+ return return_to_top + pre, post
def handle_uwaga(self, _e):
return None
@@ -151,16 +159,24 @@ u"""%(wskazowki)s
# Lists
def handle_lista(self, element, attrs={}):
ltype = element.attrib.get('typ', 'punkt')
+ if not element.findall("punkt"):
+ if ltype == 'czytelnia':
+ return 'W przygotowaniu.
'
+ else:
+ return None
if ltype == 'slowniczek':
surl = element.attrib.get('src', None)
if surl is None:
# print '** missing src on , setting default'
- surl = 'http://edukacjamedialna.edu.pl/slowniczek'
+ surl = 'http://edukacjamedialna.edu.pl/lekcje/slowniczek/'
sxml = None
if surl:
sxml = etree.fromstring(self.options['provider'].by_uri(surl).get_string())
self.options = {'slowniczek': True, 'slowniczek_xml': sxml }
- return '', '
'
+ pre, post = '', '
'
+ if self.options['wldoc'].book_info.url.slug != 'slowniczek':
+ post += u'Zobacz caÅy sÅowniczek.
' % surl
+ return pre, post
listtag = {'num': 'ol',
'punkt': 'ul',
@@ -434,7 +450,7 @@ Overrides the returned content default handle_pytanie
u""""""
def handle_punkt(self, element):
- return """""" \
+ return """""" \
% element.attrib,\
""
@@ -541,9 +557,9 @@ class Przyporzadkuj(Exercise):
elif self.options['predicate']:
if self.options['min']:
- placeholders = u'' * self.options['min']
+ placeholders = u'' * self.options['min']
else:
- placeholders = u''
+ placeholders = u''
return '' % element.attrib, ''
else: