Socket
Socket
Sign inDemoInstall

hast-util-raw

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hast-util-raw - npm Package Compare versions

Comparing version 9.0.2 to 9.0.3

lib/index.d.ts.map

24

index.d.ts

@@ -1,2 +0,22 @@

export { raw } from "./lib/index.js";
export type Options = import('./lib/index.js').Options;
import type {Nodes} from 'hast'
import type {VFile} from 'vfile'
export {raw} from './lib/index.js'
/**
* Configuration.
*/
export interface Options {
/**
* Corresponding virtual file representing the input document (optional).
*/
file?: VFile | null | undefined
/**
* List of custom hast node types to pass through (as in, keep) (optional).
*
* If the passed through nodes have children, those children are expected to
* be hast again and will be handled.
*/
passThrough?: Array<string> | null | undefined
}

5

index.js

@@ -1,5 +0,2 @@

/**
* @typedef {import('./lib/index.js').Options} Options
*/
// Note: types exposed from `index.d.ts`.
export {raw} from './lib/index.js'

@@ -20,2 +20,3 @@ /**

export type Text = import('hast').Text;
export type Options = import('hast-util-raw').Options;
export type Raw = import('mdast-util-to-hast').Raw;

@@ -30,20 +31,3 @@ export type DefaultTreeAdapterMap = import('parse5').DefaultTreeAdapterMap;

export type Point = import('unist').Point;
export type VFile = import('vfile').VFile;
/**
* Configuration.
*/
export type Options = {
/**
* Corresponding virtual file representing the input document (optional).
*/
file?: VFile | null | undefined;
/**
* List of custom hast node types to pass through (as in, keep) (optional).
*
* If the passed through nodes have children, those children are expected to
* be hast again and will be handled.
*/
passThrough?: Array<Nodes['type']> | null | undefined;
};
/**
* Info passed around about the current state.

@@ -74,3 +58,9 @@ */

export type Stitch = {
/**
* Node type.
*/
type: 'comment';
/**
* Replacement value.
*/
value: {

@@ -81,13 +71,2 @@ stitch: Nodes;

import { Parser } from 'parse5';
/**
* Transform a stitch.
*
* @param {Nodes} node
* unknown node.
* @param {State} state
* Info passed around about the current state.
* @returns {undefined}
* Nothing.
*/
declare function stitch(node: Nodes, state: State): undefined;
export {};
//# sourceMappingURL=index.d.ts.map

@@ -10,2 +10,4 @@ /**

*
* @typedef {import('hast-util-raw').Options} Options
*
* @typedef {import('mdast-util-to-hast').Raw} Raw

@@ -22,17 +24,5 @@ *

* @typedef {import('unist').Point} Point
*
* @typedef {import('vfile').VFile} VFile
*/
/**
* @typedef Options
* Configuration.
* @property {VFile | null | undefined} [file]
* Corresponding virtual file representing the input document (optional).
* @property {Array<Nodes['type']> | null | undefined} [passThrough]
* List of custom hast node types to pass through (as in, keep) (optional).
*
* If the passed through nodes have children, those children are expected to
* be hast again and will be handled.
*
* @typedef State

@@ -48,6 +38,12 @@ * Info passed around about the current state.

* Whether there are stitches.
*
* @typedef {{type: 'comment', value: {stitch: Nodes}}} Stitch
*/
/**
* @typedef Stitch
* Custom comment-like value we pass through parse5, which contains a
* replacement node that we’ll swap back in afterwards.
* @property {'comment'} type
* Node type.
* @property {{stitch: Nodes}} value
* Replacement value.
*/

@@ -529,2 +525,4 @@

function startTag(node, state) {
const tagName = node.tagName.toLowerCase()
// Ignore tags if we’re in plain text.

@@ -538,3 +536,3 @@ if (state.parser.tokenizer.state === TokenizerMode.PLAINTEXT) return

if (ns === webNamespaces.html && node.tagName === 'svg') {
if (ns === webNamespaces.html && tagName === 'svg') {
ns = webNamespaces.svg

@@ -548,5 +546,2 @@ }

)
// Always element.
/* c8 ignore next */
const attrs = 'attrs' in result ? result.attrs : []

@@ -556,8 +551,10 @@ /** @type {TagToken} */

type: Token.TokenType.START_TAG,
tagName: node.tagName,
tagID: html.getTagID(node.tagName),
tagName,
tagID: html.getTagID(tagName),
// We always send start and end tags.
selfClosing: false,
ackSelfClosing: false,
attrs,
// Always element.
/* c8 ignore next */
attrs: 'attrs' in result ? result.attrs : [],
location: createParse5Location(node)

@@ -582,3 +579,3 @@ }

// Set a tag name, similar to how the tokenizer would do it.
state.parser.tokenizer.lastStartTagName = node.tagName
state.parser.tokenizer.lastStartTagName = tagName

@@ -599,6 +596,7 @@ // `inForeignNode` is correctly set by the parser.

function endTag(node, state) {
const tagName = node.tagName.toLowerCase()
// Do not emit closing tags for HTML void elements.
if (
!state.parser.tokenizer.inForeignNode &&
htmlVoidElements.includes(node.tagName)
htmlVoidElements.includes(tagName)
) {

@@ -616,4 +614,4 @@ return

type: Token.TokenType.END_TAG,
tagName: node.tagName,
tagID: html.getTagID(node.tagName),
tagName,
tagID: html.getTagID(tagName),
selfClosing: false,

@@ -644,3 +642,3 @@ ackSelfClosing: false,

// Current element is closed.
tag.tagName === state.parser.tokenizer.lastStartTagName &&
tagName === state.parser.tokenizer.lastStartTagName &&
// `<textarea>` and `<title>`

@@ -670,3 +668,3 @@ (state.parser.tokenizer.state === TokenizerMode.RCDATA ||

(head.type === 'doctype' ||
(head.type === 'element' && head.tagName === 'html'))
(head.type === 'element' && head.tagName.toLowerCase() === 'html'))
)

@@ -673,0 +671,0 @@ }

{
"name": "hast-util-raw",
"version": "9.0.2",
"version": "9.0.3",
"description": "hast utility to reparse a tree",

@@ -32,2 +32,3 @@ "license": "MIT",

"lib/",
"index.d.ts.map",
"index.d.ts",

@@ -59,8 +60,9 @@ "index.js"

"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"remark-api": "^1.0.0",
"remark-cli": "^12.0.0",
"remark-preset-wooorm": "^10.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"unist-builder": "^4.0.0",
"xo": "^0.56.0"
"xo": "^0.58.0"
},

@@ -85,3 +87,4 @@ "scripts": {

"plugins": [
"remark-preset-wooorm"
"remark-preset-wooorm",
"remark-api"
]

@@ -102,3 +105,18 @@ },

"rules": {
"@typescript-eslint/consistent-type-definitions": "off"
"@typescript-eslint/array-type": [
"error",
{
"default": "generic"
}
],
"@typescript-eslint/ban-types": [
"error",
{
"extendDefaults": true
}
],
"@typescript-eslint/consistent-type-definitions": [
"error",
"interface"
]
}

@@ -105,0 +123,0 @@ }

@@ -16,15 +16,15 @@ # hast-util-raw

* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`raw(tree[, options])`](#rawtree-options)
* [`Options`](#options)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`Options`](#options)
* [`raw(tree, options)`](#rawtree-options)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)

@@ -57,6 +57,6 @@ ## What is this?

* hast utilities need a proper syntax tree as they operate on actual nodes to
inspect or transform things, they can’t operate on strings of HTML
* other output formats (React, MDX, etc) need actual nodes and can’t handle
strings of HTML
* hast utilities need a proper syntax tree as they operate on actual nodes to
inspect or transform things, they can’t operate on strings of HTML
* other output formats (React, MDX, etc) need actual nodes and can’t handle
strings of HTML

@@ -122,34 +122,33 @@ The plugin [`rehype-raw`][rehype-raw] wraps this utility at a higher-level

This package exports the identifier [`raw`][api-raw].
There is no default export.
### `Options`
### `raw(tree[, options])`
Configuration.
Pass a hast tree through an HTML parser, which will fix nesting, and turn raw
nodes into actual nodes.
###### Fields
###### Parameters
* `file?` (`VFile | null | undefined`)
— corresponding virtual file representing the input document (optional)
* `passThrough?` (`Array<string> | null | undefined`)
* `tree` ([`Node`][node])
— original hast tree to transform
* `options` ([`Options`][api-options], optional)
— configuration
List of custom hast node types to pass through (as in, keep) (optional).
###### Returns
If the passed through nodes have children, those children are expected to
be hast again and will be handled.
Parsed again tree ([`Node`][node]).
### `raw(tree, options)`
### `Options`
Pass a hast tree through an HTML parser, which will fix nesting, and turn
raw nodes into actual nodes.
Configuration (TypeScript type).
###### Parameters
###### Fields
* `tree` (`Root | RootContent`)
— original hast tree to transform
* `options?` (`Options | null | undefined`)
— configuration (optional)
* `passThrough` (`Array<string>`, optional)
— list of custom hast node types to pass through (keep).
If the passed through nodes have children, those children are expected to be
hast and will be handled by this utility
* `file` ([`VFile`][vfile], optional)
— corresponding virtual file representing the input document
###### Returns
Parsed again tree (`Root | RootContent`).
## Types

@@ -195,6 +194,6 @@

* [`mdast-util-to-hast`][mdast-util-to-hast]
— transform mdast to hast
* [`rehype-raw`](https://github.com/rehypejs/rehype-raw)
— rehype plugin
* [`mdast-util-to-hast`][mdast-util-to-hast]
— transform mdast to hast
* [`rehype-raw`](https://github.com/rehypejs/rehype-raw)
— rehype plugin

@@ -267,4 +266,2 @@ ## Contribute

[node]: https://github.com/syntax-tree/hast#nodes
[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast

@@ -274,4 +271,2 @@

[vfile]: https://github.com/vfile/vfile
[rehype-raw]: https://github.com/rehypejs/rehype-raw

@@ -281,4 +276,2 @@

[api-raw]: #rawtree-options
[api-options]: #options
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc