Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Node type not exported #63

Copy link
Copy link
@lazd

Description

@lazd
Issue body actions

The same way postcss-parser exports NodeText and NodeTag, I would export posthtml-render to export Node. This would be helpful when constructing objects for use with posthtml-render.

Details

My use case is as follows:

  1. Manually create an entire Node tree in a TypeScript project (no parsing involved)
  2. Render the tree, return the HTML

I would expect to be able to do something like this:

import { Node, render } from 'posthtml-render';

const node: Node = {
  tag: 'div',
  content: [
    { tag: 'div', content: 'Hi' }
  ]
};

const html = render(node);

Instead, I have to do something like:

import render from 'posthtml-render';

import { NodeText, NodeTag } from 'posthtml-parser';

// re-declare the node union type manually (will be compatible since closeAs is optional)
type Node = NodeText | NodeTag;

const node: Node = {
  tag: 'div',
  content: [
    { tag: 'div', content: 'Hi' }
  ]
};

const html = render(node);

Of course, I could omit the Node type completely and just use an implicit any or object, but it is a better development experience to know the type of the object I'm constructing.

I realize that posthtml-render is mainly just a dependency of posthtml and this use case is probably uncommon, but this would open up some additional uses of the package.

Environment

OS node yarn package
macOS 10.15.7 v14.17.1 v1.22.4 v2.0.6

Note: I had to work around #62 to test the above code sample (change types to dist/index.d.ts in node_modules/posthtml-render/package.json).

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.