npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

notion-dom-parser

v1.0.3

Published

a Javascript module which can parse notion post page to tree structure

Downloads

13

Readme

Notion dom parser

English / 中文

License: MIT npm version

介绍

Notion-dom-parser 是一个用于解析Notion文章页面DOM结构并将其转换为树形结构的JavaScript npm开源项目。这对于希望以编程方式处理Notion内容的开发者特别有用。

安装

通过npm安装:

npm install notion-dom-parser

使用方法

CommonJS

const parser = require('notion-dom-parser');
const html = '';
const result = parser.parse(html);

ESM

import parser from 'notion-dom-parser';
const html = '';
const result = parser.parse(html);

结构

解析结果是树形数组,数组中每个对象都遵循以下结构

type NotionNode = {
  type: string;
  children: NotionNode[];
  href?: string; // 只有type为'a'时才存在,表示链接地址
  text?: string; // 只有type为'text'时才存在,表示文本节点内容
  olLevel?: number; // 只有type为'ol'时才存在,表示列表在嵌套时的层级
  ulLevel?: number; // 只有type为'ul'时才存在,表示列表在嵌套时的层级
};

示例

  • header block
{
  "type": "h1",
  "children": [
    {
      "type": "text",
      "text": "一级标题"
    },
    {
      "type": "a",
      "children": [
        {
          "type": "text",
          "text": "链接"
        }
      ],
      "href": "/a8c83cfad753461585db3f063c24c13d?pvs=25"
    }
  ]
}
  • paragraph block
{
  "type": "p",
  "children": [
    {
      "type": "text",
      "text": "这里是正文,"
    },
    {
      "type": "a",
      "children": [
        {
          "type": "text",
          "text": "链接"
        }
      ],
      "href": "http://www.baidu.com/"
    },
    {
      "type": "text",
      "text": "会生成脚注,重点请"
    },
    {
      "type": "bold",
      "children": [
        {
          "type": "text",
          "text": "加粗,"
        }
      ]
    },
    {
      "type": "italic",
      "children": [
        {
          "type": "text",
          "text": "斜体,"
        }
      ]
    },
    {
      "type": "text",
      "text": "代码"
    },
    {
      "type": "p",
      "children": [
        {
          "type": "text",
          "text": "缩进"
        }
      ]
    }
  ]
}
  • quote block
{
  "type": "quote",
  "children": [
    {
      "type": "p",
      "children": [
        {
          "type": "text",
          "text": "这里是"
        },
        {
          "type": "bold",
          "children": [
            {
              "type": "text",
              "text": "引用"
            }
          ]
        }
      ]
    },
    {
      "type": "p",
      "children": [
        {
          "type": "text",
          "text": "拖进去的"
        }
      ]
    }
  ]
}

功能和优势

  • 快速解析:可以非常快速地将Notion页面转换为树形结构。
  • 易于集成:支持CommonJS和ESM,可以轻松集成到现有的JavaScript项目中。

如何贡献

欢迎通过GitHub提交pull请求来贡献代码。在提交前,请确保遵循项目的代码规范和提交指南。## License

许可证

本项目采用MIT许可证。有关详细信息,请查看LICENSE文件。