diff options
author | Martin Vilcans <martin@librador.com> | 2016-04-14 00:10:15 +0200 |
---|---|---|
committer | Martin Vilcans <martin@librador.com> | 2016-04-14 00:34:04 +0200 |
commit | e76e044308a8d3b5fa93bc9a2657897c480bb782 (patch) | |
tree | d1834af5806fcf7b4d609db2163a8f6fcc5d29db | |
parent | 355b16004a57d5b23ef0e31adb818b5dabae3c86 (diff) | |
download | screenplain-e76e044308a8d3b5fa93bc9a2657897c480bb782.tar.gz |
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
-rw-r--r-- | screenplain/richstring.py | 10 | ||||
-rw-r--r-- | tests/files/indentation.fountain | 11 | ||||
-rw-r--r-- | tests/files/indentation.fountain.fdx | 24 | ||||
-rw-r--r-- | tests/files/indentation.fountain.html | 6 |
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> Four spaces</p></div> +<div class="action"><p> Three spaces</p></div> +<div class="action"><p> Two spaces</p></div> +<div class="action"><p> One space</p></div> +<div class="action"><p>No spaces</p></div> |