added a PRE block type which lets through contents without converting them to Markdown
authorPhil Jones <interstar@gmail.com>
Fri, 10 Aug 2018 04:31:46 +0000 (01:31 -0300)
committerPhil Jones <interstar@gmail.com>
Fri, 10 Aug 2018 04:31:46 +0000 (01:31 -0300)
python/thoughtstorms/thoughtstorms/txlib.py
python/thoughtstorms/thoughtstorms/utTxLib.py

index b119961..b009791 100755 (executable)
@@ -111,8 +111,8 @@ class UnknownBlock() :
 
 class PreBlock() :
     """Does nothing, passes contents through without changing them"""
-    def evaluate(self,lines) :
-        return lines
+    def evaluate(self,lines) :        
+        return ["MARKDOWN_TOGGLE"] + lines + ["MARKDOWN_TOGGLE"]
 
 class YouTubeBlock() :
        def evaluate(self,lines) :
@@ -270,7 +270,9 @@ class Block :
        def __init__(self,typ,env) :
                self.type = typ
                self.lines = []
-               if self.type == "YOUTUBE" :
+               if self.type == "PRE" :
+                   self.evaluator = PreBlock()
+               elif self.type == "YOUTUBE" :
                        self.evaluator = YouTubeBlock()
                elif self.type == "SOUNDCLOUD" :
                        self.evaluator = SoundCloudBlock()
@@ -312,7 +314,7 @@ class BlockServices :
                                # In Block
                                if CLOSE in l :
                                        in_block = False
-                                       count = count + 1
+                                       count = count + 1
                                        for x in current_block.evaluate() :
                                            yield x
                                        current_block=None
@@ -369,6 +371,15 @@ class MarkdownThoughtStorms :
                lines = p.split("\n")
                lines = BlockServices().handle_lines(lines,env)
                lines = (self.wiki_filters(l) for l in lines)
-               page = self.md("\n".join((self.mystrip(l) for l in lines)))                
-               return page
+               page = "\n".join((self.mystrip(l) for l in lines))
+               if "MARKDOWN_TOGGLE" in page :
+                   ps = page.split("\nMARKDOWN_TOGGLE")
+                   for x in range(len(ps)) :
+                       if x % 2 == 0 :
+                           ps[x] = self.md(ps[x])                          
+                       else :
+                           pass
+                   return "\n".join(ps)
+                          
+               return self.md(page) 
 
index aacde50..a6a724d 100755 (executable)
@@ -1,6 +1,14 @@
 from txlib import MarkdownThoughtStorms, Environment
 
-import unittest 
+import unittest, re
+
+def assertCollapseNL(test,a,b) :
+    a = re.sub("\n+","\n",a)
+    b = re.sub("\n+","\n",b)
+    print(a)
+    print(b)
+    test.assertEqual(a,b)
+    
 
 class TestMarkdownThoughtStorms(unittest.TestCase) :
 
@@ -39,5 +47,44 @@ After
         self.assertEqual(self.chef.cook(p,self.env),
 """<p>Before</p>\n<p><div class="youtube-embedded"><iframe width="400" height="271" src="http://www.youtube.com/embed/kc_Jq42Og7Q" frameborder="0" allowfullscreen></iframe></div></p>\n<p>During</p>\n<p><div class="youtube-embedded"><iframe width="400" height="271" src="http://www.youtube.com/embed/kc_Jq42Og7Q" frameborder="0" allowfullscreen></iframe></div></p>\n<p>After</p>""")
 
+    def test3(self) :
+        p = """
+## Some stuff
+xxx
+[<PRE
+
+## This shouldn't be Markdowned
+
+>]
+
+Middle 
+
+[<PRE
+4
+
+
+
+
+blank rows
+>]
+
+Aftermath"""
+        r = """<h2>Some stuff</h2>
+<p>xxx</p>
+
+## This shouldn't be Markdowned
+
+<p>Middle</p>
+
+4
+
+
+
+
+blank rows
+
+<p>Aftermath</p>"""
+        assertCollapseNL(self,self.chef.cook(p,self.env),r)
+
 if __name__ == '__main__' :
     unittest.main()