fix empty instruction; add anchors and top links
[librarian.git] / librarian / pyhtml.py
index d36e0fe..d138701 100644 (file)
@@ -66,11 +66,12 @@ class EduModule(Xmill):
             toc.append("<li>%s</li>" % atxt)
         toc = "<ul class='toc'>%s</ul>" % "".join(toc)
         add_header = "Lekcja: " if self.options['wldoc'].book_info.type in ('course', 'synthetic') else ''
             toc.append("<li>%s</li>" % atxt)
         toc = "<ul class='toc'>%s</ul>" % "".join(toc)
         add_header = "Lekcja: " if self.options['wldoc'].book_info.type in ('course', 'synthetic') else ''
-        return "<h1 class='title'>%s" % add_header, "</h1>" + toc
+        return "<h1 class='title'><a name='top'></a>%s" % add_header, "</h1>" + toc
 
 
-    @tagged("h2")
     def handle_naglowek_rozdzial(self, element):
     def handle_naglowek_rozdzial(self, element):
-        return "", "".join(tag_open_close("a", name=self.naglowek_to_anchor(element)))
+        return_to_top = u"<a href='#top' class='top-link'>wróć do spisu treści</a>"
+        anchor = "".join(tag_open_close("a", name=self.naglowek_to_anchor(element)))
+        return return_to_top + "<h2>", anchor + "</h2>"
 
     def handle_uwaga(self, _e):
         return None
 
     def handle_uwaga(self, _e):
         return None
@@ -268,7 +269,7 @@ u"""%(wskazowki)s
         url = self.options['urlmapper'].url_for_image(slug, ext)
         thumb_url = self.options['urlmapper'].url_for_image(slug, ext, IMAGE_THUMB_WIDTH)
         e = etree.Element("a", attrib={"href": url, "class": "image"})
         url = self.options['urlmapper'].url_for_image(slug, ext)
         thumb_url = self.options['urlmapper'].url_for_image(slug, ext, IMAGE_THUMB_WIDTH)
         e = etree.Element("a", attrib={"href": url, "class": "image"})
-        e.append(etree.Element("img", attrib={"src": url, "alt": alt,
+        e.append(etree.Element("img", attrib={"src": thumb_url, "alt": alt,
                     "width": str(IMAGE_THUMB_WIDTH)}))
         return etree.tostring(e, encoding=unicode), u""
 
                     "width": str(IMAGE_THUMB_WIDTH)}))
         return etree.tostring(e, encoding=unicode), u""
 
@@ -277,7 +278,7 @@ u"""%(wskazowki)s
         if not url:
             print '!! <video> missing url'
             return
         if not url:
             print '!! <video> missing url'
             return
-        m = re.match(r'https?://(?:www.)?youtube.com/watch\?(?:.*&)?v=([^&]+)(?:$|&)', url)
+        m = re.match(r'(?:https?://)?(?:www.)?youtube.com/watch\?(?:.*&)?v=([^&]+)(?:$|&)', url)
         if not m:
             print '!! unknown <video> url scheme:', url
             return
         if not m:
             print '!! unknown <video> url scheme:', url
             return
@@ -361,14 +362,16 @@ class Exercise(EduModule):
     def get_instruction(self):
         if not self.instruction_printed:
             self.instruction_printed = True
     def get_instruction(self):
         if not self.instruction_printed:
             self.instruction_printed = True
-            return u'<span class="instruction">%s</span>' % self.INSTRUCTION
+            if self.INSTRUCTION:
+                return u'<span class="instruction">%s</span>' % self.INSTRUCTION
+            else:
+                return ""
         else:
             return ""
 
 
 
 class Wybor(Exercise):
         else:
             return ""
 
 
 
 class Wybor(Exercise):
-    INSTRUCTION = None
     def handle_cwiczenie(self, element):
         pre, post = super(Wybor, self).handle_cwiczenie(element)
         is_single_choice = True
     def handle_cwiczenie(self, element):
         pre, post = super(Wybor, self).handle_cwiczenie(element)
         is_single_choice = True
@@ -491,7 +494,6 @@ class Przyporzadkuj(Exercise):
                    u"Kliknij numer odpowiedzi, przeciągnij i upuść w wybranym polu."]
 
     def get_instruction(self):
                    u"Kliknij numer odpowiedzi, przeciągnij i upuść w wybranym polu."]
 
     def get_instruction(self):
-        print self.options['handles']
         if not self.instruction_printed:
             self.instruction_printed = True
             return u'<span class="instruction">%s</span>' % self.INSTRUCTION[self.options['handles'] and 1 or 0]
         if not self.instruction_printed:
             self.instruction_printed = True
             return u'<span class="instruction">%s</span>' % self.INSTRUCTION[self.options['handles'] and 1 or 0]