Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax tree not recognising headings, separating full stops, and not separating lists #109

Open
uuykay opened this issue Aug 16, 2021 · 0 comments

Comments

@uuykay
Copy link

uuykay commented Aug 16, 2021

Hello!

I like this project, because I am looking to create a syntax tree out of markdown (in order to do my own JSX parsing). However, after running the example in the Readme, the syntax tree seems to have issues on even basic cases. For example, this is my node script:

// index.js
const fs = require("fs")
const SimpleMarkdown = require("simple-markdown")
const mdParse = SimpleMarkdown.defaultBlockParse

const testMarkdown = fs.readFileSync(__dirname + "/test.md", "utf-8")

const syntaxTree = mdParse(testMarkdown)

fs.writeFileSync(__dirname + "/temp.json", JSON.stringify(syntaxTree, null, 4))

And this was my test.md file

# This is a h1 title
## This is a h2 subtitle
This is a paragraph 1.

This is a paragraph 2. **This text should be bold.** *And this text should be italic.*

> This should be a blockquote

1. Ordered list 1
2. Ordered list 2
3. Ordered list 3

- Unordered list 1
- Unordered list 2

And finally, after running the script, this was the full output:

[
  {
    "content": [
      {
        "content": "# This is a h1 title\n",
        "type": "text"
      },
      {
        "content": "#",
        "type": "text"
      },
      {
        "content": "# This is a h2 subtitle\nThis is a paragraph 1",
        "type": "text"
      },
      {
        "content": ".",
        "type": "text"
      }
    ],
    "type": "paragraph"
  },
  {
    "content": [
      {
        "content": "This is a paragraph 2",
        "type": "text"
      },
      {
        "content": ". ",
        "type": "text"
      },
      {
        "content": [
          {
            "content": "This text should be bold",
            "type": "text"
          },
          {
            "content": ".",
            "type": "text"
          }
        ],
        "type": "strong"
      },
      {
        "content": " ",
        "type": "text"
      },
      {
        "content": [
          {
            "content": "And this text should be italic",
            "type": "text"
          },
          {
            "content": ".",
            "type": "text"
          }
        ],
        "type": "em"
      }
    ],
    "type": "paragraph"
  },
  {
    "content": [
      {
        "content": [
          {
            "content": "This should be a blockquote",
            "type": "text"
          }
        ],
        "type": "paragraph"
      }
    ],
    "type": "blockQuote"
  },
  {
    "ordered": true,
    "start": 1,
    "items": [
      [
        {
          "content": "Ordered list 1",
          "type": "text"
        }
      ],
      [
        {
          "content": "Ordered list 2",
          "type": "text"
        }
      ],
      [
        {
          "content": [
            {
              "content": "Ordered list 3",
              "type": "text"
            }
          ],
          "type": "paragraph"
        }
      ],
      [
        {
          "content": "Unordered list 1",
          "type": "text"
        }
      ],
      [
        {
          "content": "Unordered list 2",
          "type": "text"
        }
      ]
    ],
    "type": "list"
  }
]

Some things to highlight:

  • Headings are not picked up at all
  • Full stops get separated into their own blocks, even though they should have the same formatting like in the bold or italic test.
  • There is no separation between the ordered list and unordered list I created.

Is there an easy way to extend this work so it fixes the cases I mentioned above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant