View Issue Details

IDProjectCategoryView StatusLast Update
0000039CAT-SOOP[All Projects] Generalpublic2018-10-14 02:51
ReporterkadeAssigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Product Version 
Target VersionFixed in Version 
Summary0000039: Add functionality to the <showhide> tag
DescriptionAdds "label" attribute to the <showhide> tag, that allows button text other than "Show/Hide".
Also fixes an issue caused by the `markdown` library that CAT-SOOP imports, where conversion of blank lines to "

" cause ejection from the <showhide> environment.
TagsNo tags attached.
Attach Tags

Activities

kade

2018-10-14 02:51

reporter   ~0000027

Patch attached.

showhide.patch (1,884 bytes)
# HG changeset patch
# User Kade Phillips <kade@mit.edu>
# Date 1539499824 14400
#      Sun Oct 14 02:50:24 2018 -0400
# Node ID c9c5bb910087140fd330a07e420746fbe48ded88
# Parent  ecc9143cec229de39ac6c56ab3751d53c100375e
showhide

diff -r ecc9143cec22 -r c9c5bb910087 catsoop/language.py
--- a/catsoop/language.py	Tue Oct 02 21:46:47 2018 -0400
+++ b/catsoop/language.py	Sun Oct 14 02:50:24 2018 -0400
@@ -163,6 +163,25 @@
 
 
 def _md(x):
+    replace_LF_with_br = ["showhide"]
+
+    blank_lines = re.compile(r'\n(\n+)', re.MULTILINE)
+    def br(m):
+        return "\n" + "\n".join(["<br/>"]*len(m.group(1))) + "\n"
+    for tag in replace_LF_with_br:
+        opening = re.compile(r'<\s*%s(\s+[^>]+)?\s*>' % tag)
+        closing = re.compile(r'</\s*%s\s*>' % tag)
+        this_op = re.search(opening, x)
+        while this_op:
+            this_cl = closing.search(x, this_op.start())
+            if this_cl is None:
+                break
+            interior = x[this_op.end():this_cl.start()]
+            repl = re.sub(blank_lines, br, interior)
+            len_change = len(repl) - len(interior)
+            x = x[:this_op.end()] + repl + x[this_cl.start():]
+            this_op = opening.search(x, this_cl.end()+len_change)
+
     o = markdown.markdown(
         x,
         extensions=[
@@ -779,8 +798,13 @@
         button = tree.new_tag(
             "button",
             onclick="if(this.nextSibling.style.display === 'none'){this.nextSibling.style.display = 'block';}else{this.nextSibling.style.display = 'none';}",
+            style="font-size:0.85em;",
         )
-        button.string = "Show/Hide"
+        if "label" in i.attrs:
+            button.string = i.attrs["label"]
+            del i.attrs["label"]
+        else:
+            button.string = "Show/Hide"
         i.insert_before(button)
 
     # custom URL handling in img, a, script, link
showhide.patch (1,884 bytes)

Add Note

View Status
Note
Upload Files
Maximum size: 2,097 KB

Drop files here to upload (or click)

Issue History

Date Modified Username Field Change
2018-10-14 02:49 kade New Issue
2018-10-14 02:51 kade File Added: showhide.patch
2018-10-14 02:51 kade Note Added: 0000027