From e76e044308a8d3b5fa93bc9a2657897c480bb782 Mon Sep 17 00:00:00 2001 From: Martin Vilcans Date: Thu, 14 Apr 2016 00:10:15 +0200 Subject: Show multiple spaces in a row as is in HTML & PDF Not sure if FDX output should use   Let's keep using spaces for now. Closes #30 --- screenplain/richstring.py | 10 +++++++--- tests/files/indentation.fountain | 11 +++++++++++ tests/files/indentation.fountain.fdx | 24 ++++++++++++++++++++++++ tests/files/indentation.fountain.html | 6 ++++++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 tests/files/indentation.fountain create mode 100644 tests/files/indentation.fountain.fdx create mode 100644 tests/files/indentation.fountain.html 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 @@ + + + + + + EXT. INDENTATION TEST + + + Four spaces + + + Three spaces + + + Two spaces + + + One space + + + No spaces + + + 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 @@ +
EXT. INDENTATION TEST
+

    Four spaces

+

   Three spaces

+

  Two spaces

+

 One space

+

No spaces

-- cgit