yoshiki / yaml-mode

The emacs major mode for editing files in the YAML data serialization format.
GNU General Public License v3.0
482 stars 132 forks source link

Fix propertization for sequences of mappings with literal block #81

Closed strutt closed 3 years ago

strutt commented 4 years ago

The syntax highlighting is broken for lists of dicts where one of the dictionary elements is a literal block. This small fix handles this case.

example:
  - key1: Correctly highlighted
    key2: |
      Correctly highlighted.
  - key3: |
      Correctly highlighted
    key4: Incorrectly highlighted as part of preceding yaml-literal-block

In submitting this PR I'm noticing that the github markdown rendering is incorrect too ^^^. I double checked with the python parser you get a two element list, each of which is a dict with two entries. e.g:

import yaml
import json

doc = """
example:
  - key1: Correctly highlighted
    key2: |
      Correctly highlighted.
  - key3: |
      Correctly highlighted
    key4: Incorrectly highlighted as part of preceding yaml-literal-block
"""

print(json.dumps(yaml.load(doc, Loader=yaml.CLoader), indent=2))

Prints

{
  "Example": [
    {
      "key1": "Correctly highlighted",
      "key2": "Correctly highlighted.\n"
    },
    {
      "key3": "Correctly highlighted\n",
      "key4": "Incorrectly highlighted as part of preceding yaml-literal-block"
    }
  ]
}