aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--screenplain/richstring.py10
-rw-r--r--tests/files/indentation.fountain11
-rw-r--r--tests/files/indentation.fountain.fdx24
-rw-r--r--tests/files/indentation.fountain.html6
4 files changed, 48 insertions, 3 deletions
diff --git a/screenplain/richstring.py b/screenplain/richstring.py
index 9470c7d..e24db1a 100644
--- a/screenplain/richstring.py
+++ b/screenplain/richstring.py
@@ -45,7 +45,11 @@ class RichString(object):
return self.segments[-1].text.endswith(string)
def to_html(self):
- return ''.join(seg.to_html() for seg in self.segments)
+ html = ''.join(seg.to_html() for seg in self.segments)
+ if html.startswith(' '):
+ return ' ' + html[1:]
+ else:
+ return html
def __eq__(self, other):
return (
@@ -110,8 +114,8 @@ class Segment(object):
return (
''.join(style.start_html for style in ordered_styles) +
re.sub(
- ' ', # two spaces
- '  ',
+ ' +', # at least two spaces
+ lambda m: ' ' * (len(m.group(0)) - 1) + ' ',
cgi.escape(self.text).encode('ascii', 'xmlcharrefreplace'),
) +
''.join(style.end_html for style in reversed(ordered_styles))
diff --git a/tests/files/indentation.fountain b/tests/files/indentation.fountain
new file mode 100644
index 0000000..1640032
--- /dev/null
+++ b/tests/files/indentation.fountain
@@ -0,0 +1,11 @@
+EXT. INDENTATION TEST
+
+ Four spaces
+
+ Three spaces
+
+ Two spaces
+
+ One space
+
+No spaces
diff --git a/tests/files/indentation.fountain.fdx b/tests/files/indentation.fountain.fdx
new file mode 100644
index 0000000..958417f
--- /dev/null
+++ b/tests/files/indentation.fountain.fdx
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+<FinalDraft DocumentType="Script" Template="No" Version="1">
+
+ <Content>
+ <Paragraph Type="Scene Heading">
+ <Text>EXT. INDENTATION TEST</Text>
+ </Paragraph>
+ <Paragraph Type="Action">
+ <Text> Four spaces</Text>
+ </Paragraph>
+ <Paragraph Type="Action">
+ <Text> Three spaces</Text>
+ </Paragraph>
+ <Paragraph Type="Action">
+ <Text> Two spaces</Text>
+ </Paragraph>
+ <Paragraph Type="Action">
+ <Text> One space</Text>
+ </Paragraph>
+ <Paragraph Type="Action">
+ <Text>No spaces</Text>
+ </Paragraph>
+ </Content>
+</FinalDraft>
diff --git a/tests/files/indentation.fountain.html b/tests/files/indentation.fountain.html
new file mode 100644
index 0000000..491b515
--- /dev/null
+++ b/tests/files/indentation.fountain.html
@@ -0,0 +1,6 @@
+<h6>EXT. INDENTATION TEST</h6>
+<div class="action"><p>&nbsp;&nbsp;&nbsp; Four spaces</p></div>
+<div class="action"><p>&nbsp;&nbsp; Three spaces</p></div>
+<div class="action"><p>&nbsp; Two spaces</p></div>
+<div class="action"><p>&nbsp;One space</p></div>
+<div class="action"><p>No spaces</p></div>