jeremyfa / yaml.js

Standalone JavaScript YAML 1.2 Parser & Encoder. Works under node.js and all major browsers. Also brings command line YAML/JSON conversion tools.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

blank lines stripped when they should be preserved.

DavidBiesack opened this issue · comments

Lines with leading content spaces are significant in the following, but yaml.js trimming them

text: >-
  Some Markdown text.
  
  Blank lines are significant. This is a second paragraph.
    
    * item a
    * item b
    * item c
    * item d
  
  A final paragraph.

version: '0.3.0'

Converting to json yields

{"text":"Some Markdown text.\nBlank lines are significant. This is a second paragraph.  \n  * item a\n  * item b\n  * item c\n  * item d\n\nA final paragraph.","version":"0.3.0"}

There should be another \n newline character between "This is a second paragraph" and the bullet list:

This is a second paragraph.\n  \n  * 

Note that the line before the bullet list contains significant leading space (i.e. indented by 2 additional space) an thus does not satisfy the YAML.org definition of an
empty line, "An empty line line consists of the non-content prefix followed by a line break."

The result is the leading space on the next line is folded up into the preceding line (that preceding line is trimmed) instead of the spaces being preserved as content:

This is a second paragraph.  \n

When the YAML contains Markdown notation, this results in incorrect Markdown; the content ends up flowed into the preceding paragraph instead of starting a new bullet list.

Similar YAML -> JSON conversion with Python's yaml library preserves these newlines/spaces:

{
    "text": "Some Markdown text.\nBlank lines are significant. This is a second paragraph.\n  \n  * item a\n  * item b\n  * item c\n  * item d\n\nA final paragraph.",
    "version": "0.3.0"
}