Repository: hedyorg/hedy

Issue:
Bullet lists are not rendered in markdown
f.e. in the adventure mode, story, level 4, the markdown is:

![image](https://user-images.githubusercontent.com/1003685/116397375-cf97fc80-a826-11eb-911d-f65f33cb4e7b.png)

But it is rendered like this:

![image](https://user-images.githubusercontent.com/1003685/116397418-dc1c5500-a826-11eb-8613-4fd5581d0510.png)



Discussion:

Resolving patch:
diff --git a/app.py b/app.py
--- a/app.py
+++ b/app.py
@@ -710,11 +710,6 @@ def translate_fromto(source, target):
 
     files = []
 
-    files.append(translating.TranslatableFile(
-      'Adventures',
-      f'adventures/{target}.yaml',
-      translating.struct_to_sections(source_adventures, target_adventures)))
-
     files.append(translating.TranslatableFile(
       'Levels',
       f'level-defaults/{target}.yaml',
@@ -725,6 +720,11 @@ def translate_fromto(source, target):
       f'texts/{target}.yaml',
       translating.struct_to_sections(source_texts, target_texts)))
 
+    files.append(translating.TranslatableFile(
+      'Adventures',
+      f'adventures/{target}.yaml',
+      translating.struct_to_sections(source_adventures, target_adventures)))
+
     return render_template('translate-fromto.html',
         source_lang=source,
         target_lang=target,
@@ -743,11 +743,13 @@ def update_yaml():
     data = load_yaml_rt(filepath)
     for key, value in request.form.items():
         if key.startswith('c:'):
-            translating.apply_form_change(data, key[2:], value)
+            translating.apply_form_change(data, key[2:], translating.normalize_newlines(value))
+
+    data = translating.normalize_yaml_blocks(data)
 
     return Response(dump_yaml_rt(data),
         mimetype='application/x-yaml',
-        headers={'Content-disposition': 'attachment; filename=' + path.basename(filename)})
+        headers={'Content-disposition': 'attachment; filename=' + request.form['file'].replace('/', '-')})
 
 
 # *** AUTH ***
diff --git a/translating.py b/translating.py
--- a/translating.py
+++ b/translating.py
@@ -1,6 +1,7 @@
 """
 Helper routines for the translation page.
 """
+from ruamel import yaml
 
 
 class TranslatableFile:
@@ -114,7 +115,7 @@ def value_at(data, path):
   for p in path:
     if str(p).startswith('a:'):
       # Expecting to index into a list
-      index = int(key[2:])
+      index = int(p[2:])
       if not isinstance(data, list): return None
       if len(data) <= index: return None
       data = data[index]
@@ -138,3 +139,41 @@ def str_presenter(dumper, data):
   except TypeError as ex:
       return dumper.represent_scalar('tag:yaml.org,2002:str', data)
   return dumper.represent_scalar('tag:yaml.org,2002:str', data)
+
+
+def normalize_yaml_blocks(data):
+  """Replace all string containing newlines with a special string that the Yaml parser will serialize as a | block.
+
+  This will make your YAML pretty and easy to work with.
+  """
+  if isinstance(data, list):
+    for i, el in enumerate(data):
+      if isinstance(el, str):
+        pass
+        data[i] = maybe_translate_to_block(el)
+      else:
+        normalize_yaml_blocks(el)
+    return data
+
+  if isinstance(data, dict):
+    for key, value in list(data.items()):
+      if isinstance(value, str):
+        pass
+        data[key] = maybe_translate_to_block(value)
+      else:
+        normalize_yaml_blocks(value)
+    return data
+
+  return data
+
+
+def maybe_translate_to_block(x):
+  newlines = '\n' in x
+  if newlines and not isinstance(x, yaml.scalarstring.LiteralScalarString):
+    return yaml.scalarstring.LiteralScalarString(str(x))
+  return x
+
+
+def normalize_newlines(x):
+  """Turn Windows/web newlines into Linux newlines."""
+  return x.replace('\r\n', '\n')
diff --git a/utils.py b/utils.py
--- a/utils.py
+++ b/utils.py
@@ -48,9 +48,10 @@ def load_yaml_rt(filename):
     except IOError:
         return {}
 
+
 def dump_yaml_rt(data):
     """Dump round-tripped YAML."""
-    return yaml.round_trip_dump(data, indent=4)
+    return yaml.round_trip_dump(data, indent=4, width=999)
 
 
 # *** DYNAMO DB ***


Test patch: