orgapp / orgajs

parse org-mode content into AST
https://orga.js.org
MIT License
614 stars 62 forks source link

The ASTs of CRLF and LF files are different #147

Open BlackGlory opened 3 years ago

BlackGlory commented 3 years ago

Is this expected behavior?

LF

const lf =
  '* Section1' + '\n'
+ '** Section2'
{
  "type": "document",
  "properties": {},
  "children": [
    {
      "type": "section",
      "level": 1,
      "properties": {},
      "children": [
        {
          "type": "headline",
          "actionable": false,
          "children": [
            {
              "type": "stars",
              "level": 1
            },
            {
              "type": "text",
              "value": "Section1"
            },
            {
              "type": "newline"
            }
          ],
          "level": 1
        },
        {
          "type": "section",
          "level": 2,
          "properties": {},
          "children": [
            {
              "type": "headline",
              "actionable": false,
              "children": [
                {
                  "type": "stars",
                  "level": 2
                },
                {
                  "type": "text",
                  "value": "Section2"
                }
              ],
              "level": 2
            }
          ]
        }
      ]
    }
  ]
}

CRLF

const crlf =
  '* Section1' + '\r\n'
+ '** Section2'
{
  "type": "document",
  "properties": {},
  "children": [
    {
      "type": "section",
      "level": 1,
      "properties": {},
      "children": [
        {
          "type": "headline",
          "actionable": false,
          "children": [
            {
              "type": "stars",
              "level": 1
            },
            {
              "type": "text",
              "value": "Section1"
            },
            {
              "type": "newline"
            }
          ],
          "level": 1
        },
        {
          "type": "newline"
        },
        {
          "type": "section",
          "level": 2,
          "properties": {},
          "children": [
            {
              "type": "headline",
              "actionable": false,
              "children": [
                {
                  "type": "stars",
                  "level": 2
                },
                {
                  "type": "text",
                  "value": "Section2"
                }
              ],
              "level": 2
            }
          ]
        }
      ]
    }
  ]
}
BlackGlory commented 3 years ago

I noticed that when files use CRLF, there are many incorrect results, so maybe all files should be converted to LF before parsing.