@curvenote/schema

中文文档
0.12.18发布于 2022/11/24MITTypeScriptESM + CJS近 30 天下载 1.1万

Schema and markdown parser for @curvenote/editor

原始使用文档
文档目录6 节
  1. Overview & Goals
  2. Choices
  3. Schema
  4. Simple Example
  5. Roadmap
  6. See also:

@curvenote/schema

@curvenote/schema on npm MIT License CI

Schema for interactive scientific writing, with translations to MyST flavoured markdown, LaTeX, and HTML.

@curvenote/schema in curvenote.com

Overview & Goals

  • Provide a typed schema for writing reactive scientific documents using @curvenote/components
    • Uses Web Components in the rendered HTML output for non-standard components
    • Uses standard html for all other compnents, with no styling enforced
  • Interoperability with CommonMark markdown and MyST
    • Through fromMarkdown and toMarkdown methods
  • Provide components for WYSIWYG editing of reactive documents

Choices

  • The internal representation for the library is a ProseMirror Document structure (that can be rendered as JSON)
  • markdown-it is used parse and tokenize markdown content

Schema

The schema has Nodes and Marks where Nodes are basically a block of content (paragraph, code, etc.), and Marks are inline modifications to the content (bold, emphasis, links, etc.). See the ProseMirror docs for a visual explanation.

Overview of Nodes

Overview of Marks

  • link
  • code
  • em
  • strong
  • superscript
  • subscript
  • strikethrough
  • underline
  • abbr

Simple Example

This moves from markdown --> JSON --> HTML. The JSON is the intermediate representation for @curvenote/editor.

import { Schema, nodes, marks, fromMarkdown, toHTML } from '@curvenote/schema';
import { JSDOM } from 'jsdom';

const schema = new Schema({ nodes, marks });

const content = '# Hello `@curvenote/schema`!';
const doc = fromMarkdown(content, schema);

console.log(doc.toJSON());
>> {
    "type": "doc",
    "content": [
      {
        "type": "heading",
        "attrs": { "level": 1 },
        "content": [
          { "type": "text", "text": "Hello " },
          {
            "type": "text",
            "marks": [ { "type": "code" } ],
            "text": "@curvenote/schema"
          },
          { "type": "text", "text": "!" }
        ]
      }
    ]
  }

// Assuming we are in node, just use `document` if in a browser!
const { document } = new JSDOM('').window;

// Now move the document back out to html
const html = toHTML(doc, schema, document);

console.log(html);
>> "<h1>Hello <code>@curvenote/schema</code>!</h1>"

Roadmap

  • Integrate other @curvenote/components as nodes
  • Improve equation and start to go to/from various MyST syntax for this
  • Add figure properties (name, width, caption etc.)
  • Provide citations, probably bring in a bibtex parser
    • Introduce citation and reference component to curvenote/components or article
  • Add overlaping roles/directives with MyST (e.g. see executablebooks/meta#70) for pointers
    • Add the necessary pieces to curvenote/components that are not basic html (MyST uses sphinx for the heavy lifting, cross-refs etc.)
  • Provide other sereializers from the document strucutre (e.g. latex or simple html without curvenote/components, possibly idyll)

See also:

  • Idyll Lang has a different markdown-like serialization with very similar base components to curvenote - see curvenote/article#8 for a comparison.

版本与发布记录

@curvenote/schema 共发布 75 个版本,首次发布于 2021/02/15;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.12.18latest2022/11/243 年前
0.12.172022/08/044 年前
0.12.162022/06/284 年前
0.12.16-rc.12022/06/284 年前
0.12.15-rc.02022/06/284 年前
0.12.152022/06/214 年前

关于 @curvenote/schema 的常见问题

@curvenote/schema 是什么?

Schema and markdown parser for @curvenote/editor

如何安装 @curvenote/schema?

在项目目录运行 npm install @curvenote/schema,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:date-fns(^2.22.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@curvenote/schema 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@curvenote/schema 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@curvenote/schema 可以商用吗?

@curvenote/schema 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@curvenote/schema 的下载量有多少?

根据 npm 官方下载统计,@curvenote/schema 在 2026/10/11 – 2026/11/09 这 30 天内被下载 10,672 次,日均约 356 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@curvenote/schema 还在维护吗?

最新版本 0.12.18 发布于 2022/11/24(3 年前);至今共发布 75 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/02/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。