Merge pull request #38 from matrix-org/newlines

Preserve newlines in wrapped text
pull/977/head
Kegsay 9 years ago
commit b9c04cd9ca

@ -206,4 +206,3 @@ paths:
title: PresenceEvent title: PresenceEvent
allOf: allOf:
- "$ref": "definitions/event.yaml" - "$ref": "definitions/event.yaml"

@ -71,16 +71,19 @@ def main():
run_through_template("tmp/howto.rst") run_through_template("tmp/howto.rst")
rst2html("tmp/full_spec.rst", "gen/specification.html") rst2html("tmp/full_spec.rst", "gen/specification.html")
rst2html("tmp/howto.rst", "gen/howtos.html") rst2html("tmp/howto.rst", "gen/howtos.html")
if "--nodelete" not in sys.argv:
cleanup_env() cleanup_env()
if __name__ == '__main__': 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! # we accept almost no args, so they don't know what they're doing!
print "gendoc.py - Generate the Matrix specification as HTML." print "gendoc.py - Generate the Matrix specification as HTML."
print "Usage:" print "Usage:"
print " python gendoc.py" print " python gendoc.py [--nodelete]"
print "" print ""
print "The specification can then be found in the gen/ folder." 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 ""
print "Requirements:" print "Requirements:"
print " - This script requires Jinja2 and rst2html (docutils)." print " - This script requires Jinja2 and rst2html (docutils)."

@ -78,8 +78,13 @@ def main(input_module, file_stream=None, out_dir=None, verbose=False):
def wrap(input, wrap=80, initial_indent=""): def wrap(input, wrap=80, initial_indent=""):
if len(input) == 0: if len(input) == 0:
return initial_indent 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) wrapper = TextWrapper(initial_indent=initial_indent, width=wrap)
return wrapper.fill(input) output_lines = [wrapper.fill(line) for line in input_lines]
return '\n\n'.join(output_lines)
# make Jinja aware of the templates and filters # make Jinja aware of the templates and filters
env = Environment( env = Environment(

Loading…
Cancel
Save