You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1.6 KiB

Using CSS selectors on Markdown in JS

This is a source code repository for the blog post

https://peterbabic.dev/blog/using-css-selectors-on-markdown

Setup

git clone https://git.peterbabic.dev/demo/css-selectors-markdown.git
cd css-selectors-markdown
npm install
node .

This should produce the JSON ouput containing all the level 2 headings (##) from the post.md

[
  {
    "type": "heading",
    "depth": 2,
    "children": [
      {
        "type": "text",
        "value": "Second level heading A",
        "position": {
          "start": {
            "line": 5,
            "column": 4,
            "offset": 48
          },
          "end": {
            "line": 5,
            "column": 26,
            "offset": 70
          }
        }
      }
    ],
    "position": {
      "start": {
        "line": 5,
        "column": 1,
        "offset": 45
      },
      "end": {
        "line": 5,
        "column": 26,
        "offset": 70
      }
    }
  },
  {
    "type": "heading",
    "depth": 2,
    "children": [
      {
        "type": "text",
        "value": "Second level heading B",
        "position": {
          "start": {
            "line": 9,
            "column": 4,
            "offset": 86
          },
          "end": {
            "line": 9,
            "column": 26,
            "offset": 108
          }
        }
      }
    ],
    "position": {
      "start": {
        "line": 9,
        "column": 1,
        "offset": 83
      },
      "end": {
        "line": 9,
        "column": 26,
        "offset": 108
      }
    }
  }
]

License

MIT