Commit 328b6d00 authored by john's avatar john

updating StructuredTextNG ST.py

parent ac442f42
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
############################################################################## ##############################################################################
import re import re
from string import split,join,replace,expandtabs from string import split,join,replace,expandtabs,strip
def indention(str): def indention(str):
...@@ -97,7 +97,7 @@ def indention(str): ...@@ -97,7 +97,7 @@ def indention(str):
if str == '\n': if str == '\n':
return -1 return -1
str = expandtabs(str) # covert tabs into spaces #str = expandtabs(str) # covert tabs into spaces
front = re.compile('( *)') front = re.compile('( *)')
m = front.match(str) m = front.match(str)
...@@ -160,11 +160,17 @@ def split_paragraphs(paragraphs): ...@@ -160,11 +160,17 @@ def split_paragraphs(paragraphs):
tmp = '' tmp = ''
par = re.compile('\n[ ]*\n') par = re.compile('\n[ ]*\n')
if type(paragraphs).__name__ == "list":
for paragraph in paragraphs:
tmp = tmp + expandtabs(paragraph)
for paragraph in paragraphs: paragraphs = par.split(tmp)
tmp = tmp + paragraph elif type(paragraphs).__name__ == "string":
paragraphs = par.split(expandtabs(paragraphs))
paragraphs = par.split(tmp) else:
print "paragraphs in unacceptable format, must be string or list"
return []
for i in range(len(paragraphs)): for i in range(len(paragraphs)):
paragraphs[i] = paragraphs[i] + '\n\n' paragraphs[i] = paragraphs[i] + '\n\n'
...@@ -187,14 +193,18 @@ def StructuredText(paragraphs): ...@@ -187,14 +193,18 @@ def StructuredText(paragraphs):
top = -1 # which header are we under top = -1 # which header are we under
numbers = {0:0} # how many sub-paragraphs already at a level numbers = {0:0} # how many sub-paragraphs already at a level
struct = [] # the structure to be returned struct = [] # the structure to be returned
paragraphs = split_paragraphs(paragraphs) paragraphs = split_paragraphs(paragraphs)
if not paragraphs:
result = ["",[]]
return result
for paragraph in paragraphs : for paragraph in paragraphs:
if paragraph == '\n': if paragraph == '\n':
ind.append([-1, paragraph]) ind.append([-1, paragraph])
else : else :
ind.append([indention(paragraph), paragraph]) ind.append([indention(paragraph), strip(paragraph)+"\n"])
for indent,paragraph in ind : for indent,paragraph in ind :
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment