From 28c9f12c27ae98cc9cf02c09fc2060b9ec92c109 Mon Sep 17 00:00:00 2001 From: "Matthew M. Keeler" Date: Sat, 26 Dec 2020 22:40:04 -0500 Subject: [PATCH] fix: Handle returns in open ended questions When generating bullet points, any newline we write is treated as a new bullet point. This is problematic if the survey responses include a new line. To prevent this issue, we replace newlines in answers with \u000b which is the line tabulation unicode character. In this way, we preserve the breaks without creating new bullet points. --- surveydoc/google.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/surveydoc/google.py b/surveydoc/google.py index 326bc6e..fc9a6e0 100644 --- a/surveydoc/google.py +++ b/surveydoc/google.py @@ -83,15 +83,14 @@ def divergent_bar_chart(self, question, image_path): self.insert_text("Comments") self.change_style("HEADING_2", "START") self.insert_text("") - # TODO(mmk) We are going to have to generate something for the images in inline_objects def text_summary(self, question, answers): self.insert_text(question) self.change_style("HEADING_1", "START") - # TODO(mmk) If the answers have a newline in them, then they are being - # separated out into different bullet points. We need to convert the newlines to the line tabulation character (\u000b) - self.insert_text("\n".join(answers)) + formatted = [answer.replace("\n", u"\u000b") for answer in answers] + + self.insert_text("\n".join(formatted)) self.change_to_bullets() self.insert_text("Comments")