function to replace all occurrences of file inclusion in a file
authorValentin Haenel <valentin.haenel@gmx.de>
Fri, 22 Oct 2010 16:01:07 +0000 (18:01 +0200)
committerValentin Haenel <valentin.haenel@gmx.de>
Fri, 22 Oct 2010 18:30:54 +0000 (20:30 +0200)
code/wiki2beamer

index cb699473d969ae730f2c0fa8ad2a059971f6df7f..a73366a989ca6a7ea953a8ef48209834b6f1278f 100755 (executable)
@@ -84,6 +84,9 @@ autotemplate = [\
     ('titleframe', 'True')\
 ]
 
+nowikistartre = re.compile(r'^<\[\s*nowiki\s*\]')
+nowikiendre = re.compile(r'^\[\s*nowiki\s*\]>')
+
 class w2bstate:
     def __init__(self):
         self.frame_opened = False
@@ -738,8 +741,6 @@ def get_autotemplatemode(line, autotemplatemode):
         return (line, autotemplatemode)
 
 def get_nowikimode(line, nowikimode):
-    nowikistartre = re.compile(r'^<\[\s*nowiki\s*\]')
-    nowikiendre = re.compile(r'^\[\s*nowiki\s*\]>')
     
     if not nowikimode and nowikistartre.match(line)!=None:
         line = nowikistartre.sub('', line)
@@ -882,6 +883,21 @@ def include_file(line):
     else:
         return [line]
 
+def include_files(lines):
+    output = []
+    nowikimode = False
+    for line in lines:
+        if nowikimode:
+            if nowikiendre.match(line):
+                nowikimode = False
+            output.append(line)
+        elif nowikistartre.match(line):
+            output.append(line)
+            nowikimode = True
+        else:
+            output += include_file(line)
+    return output
+
 def convert2beamer_full(lines):
     """ convert to LaTeX beamer"""
     state = w2bstate()