From 55f33736b2efdb21507abb0714cd2ff36357334b Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Thu, 10 Sep 2015 12:04:12 +0100 Subject: [PATCH 1/7] Preserve newlines in wrapped text --- templating/build.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templating/build.py b/templating/build.py index dadf91ce..258e4a17 100755 --- a/templating/build.py +++ b/templating/build.py @@ -78,8 +78,10 @@ def main(input_module, file_stream=None, out_dir=None, verbose=False): def wrap(input, wrap=80, initial_indent=""): if len(input) == 0: return initial_indent + input_lines = input.split('\n') wrapper = TextWrapper(initial_indent=initial_indent, width=wrap) - return wrapper.fill(input) + output_lines = [wrapper.fill(line) for line in input_lines] + return '\n'.join(output_lines) # make Jinja aware of the templates and filters env = Environment( From f67e27e843bd812360f095a242be584f40719052 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Thu, 10 Sep 2015 13:20:04 +0100 Subject: [PATCH 2/7] Split on double-newlines not single Otherwise all sorts of tables get horribly broken --- templating/build.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/templating/build.py b/templating/build.py index 258e4a17..6756bed9 100755 --- a/templating/build.py +++ b/templating/build.py @@ -76,12 +76,10 @@ def main(input_module, file_stream=None, out_dir=None, verbose=False): return " "*indent + input def wrap(input, wrap=80, initial_indent=""): - if len(input) == 0: - return initial_indent - input_lines = input.split('\n') + input_lines = input.split('\n\n') wrapper = TextWrapper(initial_indent=initial_indent, width=wrap) output_lines = [wrapper.fill(line) for line in input_lines] - return '\n'.join(output_lines) + return '\n\n'.join(output_lines) # make Jinja aware of the templates and filters env = Environment( From 6a56c8a96559b576aa6925d44d86785a6329f199 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Thu, 10 Sep 2015 13:20:56 +0100 Subject: [PATCH 3/7] Add trailing newline --- api/client-server/v1/presence.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/api/client-server/v1/presence.yaml b/api/client-server/v1/presence.yaml index 16665341..6f8311e4 100644 --- a/api/client-server/v1/presence.yaml +++ b/api/client-server/v1/presence.yaml @@ -206,4 +206,3 @@ paths: title: PresenceEvent allOf: - "$ref": "definitions/event.yaml" - \ No newline at end of file From ad595aea459eedf92f568ff63e0e3522cea8c86c Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Thu, 10 Sep 2015 13:21:08 +0100 Subject: [PATCH 4/7] Optionally don't delete intermediate rst files Useful for debugging Hackily hackily implemented :) --- scripts/gendoc.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/gendoc.py b/scripts/gendoc.py index e3e8d3d4..47141d7d 100755 --- a/scripts/gendoc.py +++ b/scripts/gendoc.py @@ -71,10 +71,11 @@ def main(): run_through_template("tmp/howto.rst") rst2html("tmp/full_spec.rst", "gen/specification.html") rst2html("tmp/howto.rst", "gen/howtos.html") - cleanup_env() + if "--nodelete" not in sys.argv: + cleanup_env() if __name__ == '__main__': - if len(sys.argv) > 1: + if len(sys.argv) > 1 and sys.argv[1:] != ["--nodelete"]: # we accept no args, so they don't know what they're doing! print "gendoc.py - Generate the Matrix specification as HTML." print "Usage:" From a74fb54053eb9c247a4af1f5fa3fe59e891204d5 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Thu, 10 Sep 2015 13:44:41 +0100 Subject: [PATCH 5/7] Correct comment --- scripts/gendoc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gendoc.py b/scripts/gendoc.py index 47141d7d..57a04717 100755 --- a/scripts/gendoc.py +++ b/scripts/gendoc.py @@ -76,7 +76,7 @@ def main(): if __name__ == '__main__': if len(sys.argv) > 1 and sys.argv[1:] != ["--nodelete"]: - # we accept no args, so they don't know what they're doing! + # we accept almost no args, so they don't know what they're doing! print "gendoc.py - Generate the Matrix specification as HTML." print "Usage:" print " python gendoc.py" From cdc06a8bf1c410147a7cd096c2a9169914285852 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Thu, 10 Sep 2015 13:53:38 +0100 Subject: [PATCH 6/7] Document --nodelete --- scripts/gendoc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/gendoc.py b/scripts/gendoc.py index 57a04717..e3c3797e 100755 --- a/scripts/gendoc.py +++ b/scripts/gendoc.py @@ -79,9 +79,11 @@ if __name__ == '__main__': # we accept almost no args, so they don't know what they're doing! print "gendoc.py - Generate the Matrix specification as HTML." print "Usage:" - print " python gendoc.py" + print " python gendoc.py [--nodelete]" print "" print "The specification can then be found in the gen/ folder." + print ("If --nodelete was specified, intermediate files will be " + "present in the tmp/ folder.") print "" print "Requirements:" print " - This script requires Jinja2 and rst2html (docutils)." From 99106bb6fefd0b2f44c1ff418491f7d54c52cc8c Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Thu, 10 Sep 2015 13:54:00 +0100 Subject: [PATCH 7/7] Add explanatory comments Also, remove line which was accidentally removed --- templating/build.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templating/build.py b/templating/build.py index 6756bed9..ac3d2491 100755 --- a/templating/build.py +++ b/templating/build.py @@ -76,6 +76,11 @@ def main(input_module, file_stream=None, out_dir=None, verbose=False): return " "*indent + input def wrap(input, wrap=80, initial_indent=""): + if len(input) == 0: + return initial_indent + # TextWrapper collapses newlines into single spaces; we do our own + # splitting on newlines to prevent this, so that newlines can actually + # be intentionally inserted in text. input_lines = input.split('\n\n') wrapper = TextWrapper(initial_indent=initial_indent, width=wrap) output_lines = [wrapper.fill(line) for line in input_lines]