{"id":22119558,"url":"https://github.com/blackglory/romast","last_synced_at":"2026-02-03T19:32:19.692Z","repository":{"id":44838361,"uuid":"398485368","full_name":"BlackGlory/romast","owner":"BlackGlory","description":"🌿 Renderable Org-Mode Abstract Syntax Tree.","archived":false,"fork":false,"pushed_at":"2024-02-27T13:15:24.000Z","size":1542,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-28T17:00:59.932Z","etag":null,"topics":["browser","esm","library","nodejs","npm-package","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/romast","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BlackGlory.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-08-21T06:33:27.000Z","updated_at":"2023-02-21T02:57:58.000Z","dependencies_parsed_at":"2024-02-27T14:44:57.703Z","dependency_job_id":null,"html_url":"https://github.com/BlackGlory/romast","commit_stats":{"total_commits":189,"total_committers":2,"mean_commits":94.5,"dds":"0.042328042328042326","last_synced_commit":"49347e2debe81f5151f182fd50010395d3366b49"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackGlory%2Fromast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackGlory%2Fromast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackGlory%2Fromast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackGlory%2Fromast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlackGlory","download_url":"https://codeload.github.com/BlackGlory/romast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232330600,"owners_count":18506562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","esm","library","nodejs","npm-package","typescript"],"created_at":"2024-12-01T14:15:15.344Z","updated_at":"2026-02-03T19:32:19.659Z","avatar_url":"https://github.com/BlackGlory.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# romast\n**R**enderable **O**rg-**M**ode **A**bstract **S**yntax **T**ree.\n\nromast is an easy-to-render version of [oast v3],\nthe new AST is designed to render nodes directly from AST to any platform, e.g. React.\n\n[oast v3]: https://github.com/orgapp/orgajs\n\n## Install\n```sh\nnpm install --save romast\n# or\nyarn add romast\n```\n\n## Usage\n```ts\nimport { parse } from 'romast'\nimport { dedent } from 'extra-tags'\n\nconst org = dedent`\n* Romast\nLorem ipsum dolor sit amet,\nconsectetur adipiscing elit,\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n\nDuis aute irure dolor in reprehenderit in voluptate\nvelit esse cillum dolore eu fugiat nulla pariatur.\n`\n\nconst romast = parse(org)\n// {\n//   \"type\": \"document\",\n//   \"children\": [\n//     {\n//       \"type\": \"section\",\n//       \"level\": 1,\n//       \"headline\": {\n//         \"type\": \"headline\",\n//         \"tags\": [],\n//         \"children\": [\n//           {\n//             \"type\": \"text\",\n//             \"value\": \"Romast\"\n//           }\n//         ]\n//       },\n//       \"children\": [\n//         {\n//           \"type\": \"paragraph\",\n//           \"children\": [\n//             {\n//               \"type\": \"text\",\n//               \"value\": \"Lorem ipsum dolor sit amet,\"\n//             },\n//             {\n//               \"type\": \"newline\"\n//             },\n//             {\n//               \"type\": \"text\",\n//               \"value\": \"consectetur adipiscing elit,\"\n//             },\n//             {\n//               \"type\": \"newline\"\n//             },\n//             {\n//               \"type\": \"text\",\n//               \"value\": \"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\"\n//             }\n//           ]\n//         },\n//         {\n//           \"type\": \"paragraph\",\n//           \"children\": [\n//             {\n//               \"type\": \"text\",\n//               \"value\": \"Duis aute irure dolor in reprehenderit in voluptate\"\n//             },\n//             {\n//               \"type\": \"newline\"\n//             },\n//             {\n//               \"type\": \"text\",\n//               \"value\": \"velit esse cillum dolore eu fugiat nulla pariatur.\"\n//             }\n//           ]\n//         }\n//       ]\n//     }\n//   ]\n// }\n```\n\n## API\n### AST\n```ts\ninterface Node {\n  type: string\n}\n\ninterface Parent {\n  children: Node[]\n}\n\ninterface ParentOf\u003cT extends Node[]\u003e extends Parent {\n  children: T\n}\n\ntype BlockNode =\n| Document\n| Section\n| Headline\n| Paragraph\n| Example\n| Source\n| Quote\n| List\n| ListItem\n| Table\n| TableRowGroup\n| TableRow\n| TableCell\n| HorizontalRule\n| Drawer\n\ntype InlineNode =\n| Footnote\n| InlineFootnote\n| Link\n| Text\n| Bold\n| Verbatim\n| Italic\n| Strikethrough\n| Underlined\n| Code\n| Newline\n\ntype DocumentContent =\n| UniversalBlockContent\n| Section\n| Newline\n\ntype SectionContent =\n| UniversalBlockContent\n| Section\n\ntype ListContent = List | ListItem\n\ntype UniversalBlockContent =\n| Paragraph\n| Example\n| Source\n| Quote\n| Drawer\n| List\n| Table\n| HorizontalRule\n\ntype UniversalInlineContent =\n| Link\n| Text\n| Bold\n| Verbatim\n| Italic\n| Strikethrough\n| Underlined\n| Code\n| Footnote\n| InlineFootnote\n| Newline\n\ninterface Document extends ParentOf\u003cDocumentContent[]\u003e {\n  type: 'document'\n}\n\ninterface Section extends ParentOf\u003cSectionContent[]\u003e {\n  type: 'section'\n  level: number\n  headline: Headline\n}\n\ninterface Headline extends Node, ParentOf\u003cUniversalInlineContent[]\u003e {\n  type: 'headline'\n  tags: string[]\n}\n\ninterface Paragraph extends Node, ParentOf\u003cUniversalInlineContent[]\u003e {\n  type: 'paragraph'\n}\n\ninterface Example extends Node {\n  type: 'example'\n  params: string[]\n  value: string\n}\n\ninterface Source extends Node {\n  type: 'source'\n  params: string[]\n  value: string\n}\n\ninterface Quote extends Node {\n  type: 'quote'\n  value: string\n}\n\ninterface List extends Node, ParentOf\u003cListContent[]\u003e {\n  type: 'list'\n  indent: number\n  ordered: boolean\n}\n\ninterface ListItem extends Node, ParentOf\u003cUniversalInlineContent[]\u003e {\n  type: 'listItem'\n  indent: number\n  checked: boolean | null\n  term: string | null\n}\n\ninterface Table extends Node, ParentOf\u003cTableRowGroup[]\u003e {\n  type: 'table'\n  header: TableRowGroup | null\n}\n\ninterface TableRowGroup extends Node, ParentOf\u003cTableRow[]\u003e {\n  type: 'tableRowGroup'\n}\n\ninterface TableRow extends Node, ParentOf\u003cTableCell[]\u003e {\n  type: 'tableRow'\n}\n\ninterface TableCell extends Node, ParentOf\u003cUniversalInlineContent[]\u003e {\n  type: 'tableCell'\n}\n\ninterface HorizontalRule extends Node {\n  type: 'horizontalRule'\n}\n\ninterface Footnote extends Node, ParentOf\u003cUniversalBlockContent[]\u003e {\n  type: 'footnote'\n}\n\ninterface InlineFootnote extends Node, ParentOf\u003cUniversalInlineContent[]\u003e {\n  type: 'inlineFootnote'\n}\n\ninterface Newline extends Node {\n  type: 'newline'\n}\n\ninterface Drawer extends Node, ParentOf\u003cUniversalInlineContent[]\u003e {\n  type: 'drawer'\n  name: string\n}\n\ninterface Link extends Node, ParentOf\u003cUniversalInlineContent[]\u003e {\n  type: 'link'\n  protocol: 'internal' | string\n  url: string\n}\n\ninterface Text extends Node {\n  type: 'text'\n  value: string\n}\n\ninterface Bold extends Node {\n  type: 'bold'\n  value: string\n}\n\ninterface Verbatim extends Node {\n  type: 'verbatim'\n  value: string\n}\n\ninterface Italic extends Node {\n  type: 'italic'\n  value: string\n}\n\ninterface Strikethrough extends Node {\n  type: 'strikethrough'\n  value: string\n}\n\ninterface Underlined extends Node {\n  type: 'underlined'\n  value: string\n}\n\ninterface Code extends Node {\n  type: 'code'\n  value: string\n}\n```\n\n### parse\n```ts\nfunction parse(text: string, strict: boolean = false): AST.Document\n```\n\nLimited by the parser, The analysis results may have non-compliant nodes.\nIf `strict` is `true`, an `UnknownNodeError` will be thrown when there are non-compliant nodes.\nIf `strict` is `false`, theses non-compliant are simply ignored.\n\n### utils\n#### builder\n```ts\nimport * as Builder from 'romast/utils/builder'\n```\n\nEach romast node has a corresponding builder.\n\n#### is\n```ts\nimport * as Is from 'romast/utils/is'\n```\n\nEach romast node has a corresponding `is` function.\n\n#### flatMap\n```ts\nimport { flatMap } from 'romast/utils/flat-map'\n\nfunction flatMap(\n  node: AST.Node\n, fn: (node: AST.Node) =\u003e AST.Node[]\n): AST.Node[]\n```\n\n#### map\n```ts\nimport { map } from 'romast/utils/map'\n\nfunction map(\n  node: AST.Node\n, fn: (node: AST.Node) =\u003e AST.Node\n): AST.Node\n```\n\n#### filter\n```ts\nimport { filter } from 'romast/utils/filter'\n\nfunction filter(\n  node: AST.Node\n, predicate: (node: AST.Node) =\u003e unknown\n): AST.Node | undefined\n```\n\n#### find\n```ts\nimport { find } from 'romast/utils/find'\n\nfunction find\u003cT extends AST.Node\u003e(\n  node: AST.Node\n, predicate: (node: AST.Node) =\u003e boolean\n): T | undefined\n```\n\n#### findAll\n```ts\nimport { findAll } from 'romast/utils/find-all'\n\nfunction findAll\u003cT extends AST.Node\u003e(\n  node: AST.Node\n, predicate: (node: AST.Node) =\u003e boolean\n): Iterable\u003cT\u003e\n```\n\n#### traverseDescendantNodes\n```ts\nimport { traverseDescendantNodes } from 'romast/utils/traverse-descendant-nodes'\n\nfunction traverseDescendantNodes(node: AST.Node): Iterable\u003cAST.Node\u003e\n```\n\n#### addHelpers\n```ts\nimport { addHelpers, addHelpersInPlace } from 'romast/utils/add-helpers'\n\ntype NullOrNodeWithHelpers\u003cT extends AST.Node | null\u003e =\n  T extends null\n  ? null\n  : NodeWithHelpers\u003cNonNullable\u003cT\u003e\u003e\n\ntype NodeWithHelpers\u003c\n  Node extends AST.Node\n, Sibling extends AST.Node | null = AST.Node | null\n, Parent extends AST.Node | null = AST.Node | null\n\u003e =\n  Node extends AST.Document\n  ? Mixin\u003cNode, {\n      id: string\n      parent: null\n      index: null\n      previousSibling: null\n      nextSibling: null\n      children: Array\u003c\n        NodeWithHelpers\u003c\n          AST.DocumentContent\n        , AST.DocumentContent\n        , AST.Document\n        \u003e\n      \u003e\n    }\u003e\n: Node extends AST.Paragraph\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: number\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      children: Array\u003c\n        NodeWithHelpers\u003c\n          AST.UniversalInlineContent\n        , AST.UniversalInlineContent\n        , AST.Paragraph\n        \u003e\n      \u003e\n    }\u003e\n: Node extends AST.Section\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: number\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      headline: NodeWithHelpers\u003cAST.Headline, null, AST.Section\u003e\n      children: Array\u003c\n        NodeWithHelpers\u003c\n          AST.SectionContent\n        , AST.SectionContent\n        , AST.Section\n        \u003e\n      \u003e\n    }\u003e\n: Node extends AST.Headline\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: null\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      children: Array\u003c\n        NodeWithHelpers\u003c\n          AST.UniversalInlineContent\n        , AST.UniversalInlineContent\n        , AST.Headline\n        \u003e\n      \u003e\n    }\u003e\n: Node extends AST.Paragraph\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: number\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      children: Array\u003c\n        NodeWithHelpers\u003c\n          AST.UniversalInlineContent\n        , AST.UniversalInlineContent\n        , AST.Paragraph\n        \u003e\n      \u003e\n    }\u003e\n: Node extends AST.List\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: number\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      children: Array\u003cNodeWithHelpers\u003cAST.ListContent, AST.ListContent, AST.List\u003e\u003e\n    }\u003e\n: Node extends AST.ListItem\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: number\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      children: Array\u003c\n        NodeWithHelpers\u003c\n          AST.UniversalInlineContent\n        , AST.UniversalInlineContent\n        , AST.ListItem\n        \u003e\n      \u003e\n    }\u003e\n: Node extends AST.Table\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: number\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      header: NodeWithHelpers\u003cAST.TableRowGroup, null, AST.Table\u003e | null\n      children: Array\u003cNodeWithHelpers\u003cAST.TableRowGroup, AST.TableRowGroup, AST.Table\u003e\u003e\n    }\u003e\n: Node extends AST.TableRowGroup\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: Sibling extends null ? null : number\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      children: Array\u003cNodeWithHelpers\u003cAST.TableRow, AST.TableRow, AST.TableRowGroup\u003e\u003e\n    }\u003e\n: Node extends AST.TableRow\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: number\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      children: Array\u003cNodeWithHelpers\u003cAST.TableCell, AST.TableCell, AST.TableRow\u003e\u003e\n    }\u003e\n: Node extends AST.TableCell\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: number\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      children: Array\u003c\n        NodeWithHelpers\u003c\n          AST.UniversalInlineContent\n        , AST.UniversalInlineContent\n        , AST.TableCell\n        \u003e\n      \u003e\n    }\u003e\n: Node extends AST.Footnote\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: number\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      children: Array\u003c\n        NodeWithHelpers\u003c\n          AST.UniversalBlockContent\n        , AST.UniversalBlockContent\n        , AST.Footnote\n        \u003e\n      \u003e\n    }\u003e\n: Node extends AST.InlineFootnote\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: number\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      children: Array\u003c\n        NodeWithHelpers\u003c\n          AST.UniversalInlineContent\n        , AST.UniversalInlineContent\n        , AST.InlineFootnote\n        \u003e\n      \u003e\n    }\u003e\n: Node extends AST.Link\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: number\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      children: Array\u003c\n        NodeWithHelpers\u003c\n          AST.UniversalInlineContent\n        , AST.UniversalInlineContent\n        , AST.Link\n        \u003e\n      \u003e\n    }\u003e\n: Node extends AST.Drawer\n  ? Mixin\u003cNode, {\n      id: string\n      parent: NullOrNodeWithHelpers\u003cParent\u003e\n      index: number\n      previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n      children: Array\u003c\n        NodeWithHelpers\u003c\n          AST.UniversalInlineContent\n        , AST.UniversalInlineContent\n        , AST.Drawer\n        \u003e\n      \u003e\n    }\u003e\n: Mixin\u003cNode, {\n    id: string\n    parent: NullOrNodeWithHelpers\u003cParent\u003e\n    index: number | null\n    previousSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n    nextSibling: NullOrNodeWithHelpers\u003cSibling\u003e\n  }\u003e\n\nfunction addHelpers\u003cT extends AST.Node\u003e(node: T): NodeWithHelpers\u003cT\u003e\nfunction addHelpersInPlace\u003cT extends AST.Node\u003e(node: T): NodeWithHelpers\u003cT\u003e\n```\n\n#### removeHelpers\n```ts\nimport { removeHelpers, removeHelpersInPlace } from 'romast/utils/remove-helpers'\n\nfunction removeHelpers\u003cT extends AST.Node\u003e(node: NodeWithHelpers\u003cT\u003e): T\nfunction removeHelpersInPlace\u003cT extends AST.Node\u003e(node: NodeWithHelpers\u003cT\u003e): T\n```\n\n#### withHelpers\n```ts\nimport { withHelpers, withHelpersInPlace } from 'romast/utils/with-helpers'\n\nfunction withHelpers\u003cT extends AST.Node, U\u003e(\n  node: T\n, fn: (node: NodeWithHelpers\u003cT\u003e) =\u003e U\n): U\nfunction withHelpersInPlace\u003cT extends AST.Node, U\u003e(\n  node: T\n, fn: (node: NodeWithHelpers\u003cT\u003e) =\u003e U\n): U\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblackglory%2Fromast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblackglory%2Fromast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblackglory%2Fromast/lists"}