Socket
Socket
Sign inDemoInstall

@times-components/markup-forest

Package Overview
Dependencies
0
Maintainers
3
Versions
86
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @times-components/markup-forest

Utility functions for traversing The Times' AST


Version published
Maintainers
3
Install size
36.4 kB
Created

Readme

Source

Markup Forest

The exported renderTree and renderTrees methods take AST data as the first argument, and a renderer object as the second argument. Each renderer should return an object with an element property (the component to be rendered), and an optional shouldRenderChildren boolean that can ensure the renderer does not render that node's children.

renderTrees is used typically because an AST is a list of trees, however renderTree can be used if it's known that it is a single tree being traversed.

For most usages you will want to use the markup package which provides renderers out of the box for all simple elements. These functions will only render elements which have a renderer with no fallback.

How to use

renderTrees

import { renderTrees } from "@times-components/markup-forest";
import coreRenderers from "@times-components/markup";

const trees = [
  {
    "name": "paragraph",
    "attributes": {},
    "children": [
      {
        "name": "text",
        "attributes": {
          "value": "I am one paragraph"
        }
        "children": []
      }
    ]
  },
  {
    "name": "paragraph",
    "attributes": {},
    "children": [
      {
        "name": "text",
        "attributes": {
          "value": "I am another paragraph"
        }
        "children": []
      }
    ]
  }
];


// element is now
// <View>
//   <Text key="1">I am one paragraph</Text>
//   <Text key="2">I am another paragraph</Text>
// </View>
const element = <View>{renderTrees(trees, coreRenderers)}<View>

renderTree

import { renderTree } from "@times-components/markup-forest";
import coreRenderers from "@times-components/markup";

const tree = {
  "name": "bold",
  "attributes": {},
  "children": [
    {
      "name": "text",
      "attributes": {
        "value": "I am bold"
      }
      "children": []
    }
  ]
}

// element is now
// <Text style={{fontWeight: bold}}>
//   I am bold
// </Text>
const element = renderTree(tree, coreRenderers)

Contributing

Please read CONTRIBUTING.md before contributing to this package

Running the code

Please see our main README.md to get the project running locally

Development

The code can be formatted and linted in accordance with the agreed standards.

yarn fmt
yarn lint

Testing

Testing can be done on each platform individually

yarn test

Keywords

FAQs

Last updated on 19 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc