Giter VIP home page Giter VIP logo

hast-util-to-html's Introduction

hast-util-to-html

Build Coverage Downloads Size Sponsors Backers Chat

hast utility to serialize hast as HTML.

Contents

What is this?

This package is a utility that turns a hast tree into a string of HTML.

When should I use this?

You can use this utility when you want to get the serialized HTML that is represented by the syntax tree, either because you’re done with the syntax tree, or because you’re integrating with another tool that does not support syntax trees.

This utility has many options to configure how the HTML is serialized. These options help when building tools that make output pretty (such as formatters) or ugly (such as minifiers).

The utility hast-util-from-html does the inverse of this utility. It turns HTML into hast.

The rehype plugin rehype-stringify wraps this utility to also serialize HTML at a higher-level (easier) abstraction.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install hast-util-to-html

In Deno with esm.sh:

import {toHtml} from "https://esm.sh/hast-util-to-html@9"

In browsers with esm.sh:

<script type="module">
  import {toHtml} from "https://esm.sh/hast-util-to-html@9?bundle"
</script>

Use

Show install command for this example
npm install hastscript hast-util-to-html
import {h} from 'hastscript'
import {toHtml} from 'hast-util-to-html'

const tree = h('.alpha', [
  'bravo ',
  h('b', 'charlie'),
  ' delta ',
  h('a.echo', {download: true}, 'foxtrot')
])

console.log(toHtml(tree))

Yields:

<div class="alpha">bravo <b>charlie</b> delta <a class="echo" download>foxtrot</a></div>

API

This package exports the identifier toHtml. There is no default export.

toHtml(tree[, options])

Serialize hast as HTML.

Parameters
  • tree (Node or Array<Node>) — tree to serialize
  • options (Options, optional) — configuration
Returns

Serialized HTML (string).

CharacterReferences

How to serialize character references (TypeScript type).

Fields
useNamedReferences

Prefer named character references (&amp;) where possible (boolean, default: false).

omitOptionalSemicolons

Whether to omit semicolons when possible (boolean, default: false).

⚠️ Note: this creates what HTML calls “parse errors” but is otherwise still valid HTML — don’t use this except when building a minifier. Omitting semicolons is possible for certain named and numeric references in some cases.

useShortestReferences

Prefer the shortest possible reference, if that results in less bytes (boolean, default: false).

⚠️ Note: useNamedReferences can be omitted when using useShortestReferences.

Options

Configuration (TypeScript type).

Fields
allowDangerousCharacters

Do not encode some characters which cause XSS vulnerabilities in older browsers (boolean, default: false).

⚠️ Danger: only set this if you completely trust the content.

allowDangerousHtml

Allow raw nodes and insert them as raw HTML (boolean, default: false).

When false, Raw nodes are encoded.

⚠️ Danger: only set this if you completely trust the content.

allowParseErrors

Do not encode characters which cause parse errors (even though they work), to save bytes (boolean, default: false).

Not used in the SVG space.

👉 Note: intentionally creates parse errors in markup (how parse errors are handled is well defined, so this works but isn’t pretty).

bogusComments

Use “bogus comments” instead of comments to save byes: <?charlie> instead of <!--charlie--> (boolean, default: false).

👉 Note: intentionally creates parse errors in markup (how parse errors are handled is well defined, so this works but isn’t pretty).

characterReferences

Configure how to serialize character references (CharacterReferences, optional).

closeEmptyElements

Close SVG elements without any content with slash (/) on the opening tag instead of an end tag: <circle /> instead of <circle></circle> (boolean, default: false).

See tightSelfClosing to control whether a space is used before the slash.

Not used in the HTML space.

closeSelfClosing

Close self-closing nodes with an extra slash (/): <img /> instead of <img> (boolean, default: false).

See tightSelfClosing to control whether a space is used before the slash.

Not used in the SVG space.

collapseEmptyAttributes

Collapse empty attributes: get class instead of class="" (boolean, default: false).

Not used in the SVG space.

👉 Note: boolean attributes (such as hidden) are always collapsed.

omitOptionalTags

Omit optional opening and closing tags (boolean, default: false).

For example, in <ol><li>one</li><li>two</li></ol>, both </li> closing tags can be omitted. The first because it’s followed by another li, the last because it’s followed by nothing.

Not used in the SVG space.

preferUnquoted

Leave attributes unquoted if that results in less bytes (boolean, default: false).

Not used in the SVG space.

quote

Preferred quote to use (Quote, default: '"').

quoteSmart

Use the other quote if that results in less bytes (boolean, default: false).

space

Which space the document is in (Space, default: 'html').

When an <svg> element is found in the HTML space, this package already automatically switches to and from the SVG space when entering and exiting it.

👉 Note: hast is not XML. It supports SVG as embedded in HTML. It does not support the features available in XML. Passing SVG might break but fragments of modern SVG should be fine. Use xast if you need to support SVG as XML.

tightAttributes

Join attributes together, without whitespace, if possible: get class="a b"title="c d" instead of class="a b" title="c d" to save bytes (boolean, default: false).

Not used in the SVG space.

👉 Note: intentionally creates parse errors in markup (how parse errors are handled is well defined, so this works but isn’t pretty).

tightCommaSeparatedLists

Join known comma-separated attribute values with just a comma (,), instead of padding them on the right as well (,␠, where represents a space) (boolean, default: false).

tightDoctype

Drop unneeded spaces in doctypes: <!doctypehtml> instead of <!doctype html> to save bytes (boolean, default: false).

👉 Note: intentionally creates parse errors in markup (how parse errors are handled is well defined, so this works but isn’t pretty).

tightSelfClosing

Do not use an extra space when closing self-closing elements: <img/> instead of <img /> (boolean, default: false).

👉 Note: only used if closeSelfClosing: true or closeEmptyElements: true.

upperDoctype

Use a <!DOCTYPE… instead of <!doctype… (boolean, default: false).

Useless except for XHTML.

voids

Tag names of elements to serialize without closing tag (Array<string>, default: html-void-elements).

Not used in the SVG space.

👉 Note: It’s highly unlikely that you want to pass this, because hast is not for XML, and HTML will not add more void elements.

Quote

HTML quotes for attribute values (TypeScript type).

Type
type Quote = '"' | "'"

Space

Namespace (TypeScript type).

Type
type Space = 'html' | 'svg'

Syntax

HTML is serialized according to WHATWG HTML (the living standard), which is also followed by browsers such as Chrome and Firefox.

Types

This package is fully typed with TypeScript. It exports the additional types CharacterReferences, Options, Quote, and Space.

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, hast-util-to-html@^9, compatible with Node.js 16.

Security

Use of hast-util-to-html can open you up to a cross-site scripting (XSS) attack if the hast tree is unsafe. Use hast-util-santize to make the hast tree safe.

Related

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

hast-util-to-html's People

Contributors

bluwy avatar christianmurphy avatar greenkeeperio-bot avatar remcohaszing avatar rokt33r avatar wooorm avatar zirionneft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hast-util-to-html's Issues

re: missing whitespace in root node

Initial checklist

Affected packages and versions

#33

Link to runnable example

No response

Steps to reproduce

#33

This is required by the HTML standard, which we follow.

so my input html is invalid?

<!doctype html>
<html lang="en">
  <head>
    <title>test</title>
  </head>
  <body>
    <div>test</div>
  </body>
</html>

is valid html per https://validator.w3.org/nu/#textarea

the unified toolchain mangles this to

<!doctype html><html lang="en"><head>
    <title>test</title>
  </head>
  <body>
    <div>test</div>
  

</body></html>

the unified toolchain

i dont know where exactly the bug is.
maybe in hast-util-to-html, maybe somewhere else

That behavior is not always useful.

its certainly useful for writing lossless transformers, which produce minimal diffs

maybe this could cause trouble in some tree consumers like hast-util-select
which expect "no whitespace in the root node"?

If you want pretty HTML, use rehype-format!

no, i want to preserve the original whitespace

Expected behavior

#33

Actual behavior

#33

Affected runtime and version

#33

Affected package manager and version

No response

Affected OS and version

No response

Build and bundle tools

No response

Add support to format the HTML in a tidy fashion

Initial checklist

Problem

It would be great if there is an option to specify formatting options, such as indenting.
using html-tidy or other tools is IMO overkill, as they parse the HTML again.

Solution

have a minimal option: indent which will specify the number of spaces to use as indent.

Alternatives

using a 3rd party html tidy tool. but this is overkill as it usually reparses the html.

Do not use `Omit` type

  types/index.d.ts:25:7
  ✖  25:7  Don't use Omit as a type. Prefer the Except type in the type-fest package instead as it's stricter.  @typescript-eslint/ban-types

dtslint 3 complains about these lines, what should we do?

entities: Partial<
Omit<StringifyEntitiesOptions, 'escapeOnly' | 'attribute' | 'subset'>
>

/cc @Rokt33r as you wrote the types

Text is encoded even when setting allowDangerousCharacters/allowDangerousHtml

Affected packages and versions

8.0.2

Steps to reproduce

import { toHtml } from 'hast-util-to-html';

let test = {
  "type": "element",
  "tagName": "text",
  "children": [
      {
          "type": "text",
          "value": "-&#xa;"
      }
  ]
}

console.log(toHtml(test, {allowDangerousCharacters: true, allowDangerousHtml: true}))

Expected behavior

<text>-&#xa;</text>

Actual behavior

<text>-&#x26;#xa;</text>

Reduce dependencies size

Initial checklist

Problem

I am working on a project using unified, remark and rehype and trying to improve deploying times I realized that the size of this dependency is huge because of parse5.
A let you part of the installation sizes.
Screenshot 2023-05-18 at 11 06 56 AM

Solution

Don't use parse5; try to replace it with another solution or use the unified system to parse.

Alternatives

A custom parser.

Prevent kebab case datatype?

I'm running into the following issue when serializing RDFa: the datatype attribute gets serialized as data-type. This prevents the rdf parser I'm using further down the chain from parsing tag content as the correct type (rdf:HTML in my case).

I understand that datatype is a non-standard attribute and in some situations this might be the desired behavior. I've looked into https://github.com/wooorm/property-information/ for a workaround. When I modify the html schema, I can make find return the datatype attribute name unmodified. But judging by

schema: settings.space === 'svg' ? svg : html,
, the only possible configuration option atm is setting 'space' to 'svg' or 'html'.

In short: I'm stuck. How do I get out of this situation?

  • Is there another way to prevent converting the datatype attribute to kebab case?
  • Would it be possible/desirable to set the space configuration option to a custom schema?
  • or, is the best option to deal with this in the property-information package after all?

missing whitespace in root node

Initial checklist

Affected packages and versions

hast-util-from-parse5 7.1.0
hast-util-to-html 8.0.3
parse5 7.1.1

Link to runnable example

https://codepen.io/milahu/pen/eYKRmBW?editors=1010

Steps to reproduce

import {parse} from 'parse5'
import {fromParse5} from 'hast-util-from-parse5'
import {toHtml} from 'hast-util-to-html'

const source = `
<html>
  <head>
    <title>asdf</title>
  </head>
  <body>
    <div>asdf</div>
  </body>
</html>
`

function normalize(source) {
  const p5ast = parse(source, {
    sourceCodeLocationInfo: true,
  })
  const hast = fromParse5(p5ast)
  return toHtml(hast)
}

async function main() {

  console.log("input:")
  console.log(source)

  console.log("output:")
  console.log(normalize(source))
}

main()

Expected behavior

<html>
  <head>
    <title>asdf</title>
  </head>
  <body>
    <div>asdf</div>
  </body>
</html>

Actual behavior

<html><head>
    <title>asdf</title>
  </head>
  <body>
    <div>asdf</div>
  

</body></html>

Affected runtime and version

not relevant

Affected package manager and version

No response

Affected OS and version

No response

Build and bundle tools

No response

Force self-closing tags to be manually closed tags

Initial checklist

Problem

I'm trying to generate XHTML ePub documents from Markdown files for my book.

However, many popular epub readers do not support self-closing tags for tags such as img (including seemingly Google Play Books).

Solution

I'd love to have a way to force a tag to be fully closed tag. This means that instead of:

<img>

Or

<img  />

(using closeSelfClosing)

We'd have:

<img></img>

Alternatives

Alternatively, instead of having all closing tags handles, we could have a:

dontClose:  ['img']

Style API

failed to compile ts code using hast-util-to-html

Initial checklist

Affected packages and versions

8.0.2

Link to runnable example

No response

Steps to reproduce

Install hast-util-to-html on a new project.

$ npm install hast-util-to-html

Create test.ts file which just imports from hast-util-to-html,

import { toHtml } from 'hast-util-to-html';

and compile it.

$ tsc test.ts

Expected behavior

Run without errors.

Actual behavior

Error occured.

$ npx tsc a.ts
node_modules/hast-util-to-html/lib/types.d.ts:15:32 - error TS2694: Namespace '"/tmp/test_pjoject/node_modules/stringify-entities/index"' has no exported member 'StringifyEntitiesOptions'.

15   import('stringify-entities').StringifyEntitiesOptions
                                  ~~~~~~~~~~~~~~~~~~~~~~~~

Runtime

Node v16

Package manager

npm v7

OS

No response

Build and bundle tools

No response

Better SVG minification

When embedded in HTML, attributes can be left unquoted (but apparently they can't collapse), also: the SVG element is an HTML element, whereas elements inside it are in the SVG space.

allowDangerousCharacters is still encoding '&' when its set to true

Hi am trying to create an HTML by setting option allowDangerousCharacters: true & allowDangerousHTML: true but still the characters are being encoded.

Here is the example for what I am trying
<span v-if="(activeTab >= 3) && (activeTab < 5)">This is the fourth tab</span> but the characters are being encoded to this
<span v-if="(activeTab >= 3) &#x26;&#x26; (activeTab < 5)">This is the fourth tab</span>

Add missing "type": "module" to package.json for Vite resolution

Initial checklist

Affected packages and versions

latest

Link to runnable example

No response

Steps to reproduce

  • import { toHtml } from 'hast-util-to-html' in a JS file
  • Run with Vite (e.g. dev server)

image

Expected behavior

Some developer tools assume any module is a CommonJS module unless "type":"module" is specified in package.json.
I don't particularly agree with that approach and I'm not sure why the Vite maintainers decided to be more "dumb" about it in their resolution logic versus what they had before, but it seems to me that providing this meta information doesn't hurt and helps tools understand more clearly what format a module is.

Expected: "type": "module" in package.json

Actual behavior

Missing "type": "module" in package.json, results in tools thinking the module is CommonJS format.

Affected runtime and version

[email protected]

Affected package manager and version

[email protected]

Affected OS and version

No response

Build and bundle tools

Vite

Circular dependencies breaks rollup and vite builds

Initial checklist

Affected packages and versions

7.1.3

Link to runnable example

No response

Steps to reproduce

  1. Use rollup for bundling with this library as a dependency (or a peer dependency)
  2. Build the project and run it in a browser

Expected behavior

It runs

Actual behavior

Rollup (and by extension vite) doesn't bundle circular dependencies properly which results in the app failing during production builds.

Related issue: syntax-tree/mdast-util-to-hast#55

Runtime

Other (please specify in steps to reproduce)

Package manager

yarn v1

OS

Windows

Build and bundle tools

Rollup, Vite

How do I allow camel cased properties?

My use case is that some 3rd party library uses camel case properties

<div forLibrary='thing'> ... <div>

but this gets converted automatically to

<div for-library='thing'> ... <div>

Head elements are not wrapped in a Head tag

Subject of the issue

If this utility is run with a Hast-formatted HTML document containing a DocumentType, Head, and Body, the converted HTML is printed with the DocumentType, then the Body, and finally the contents of the Head are spit-out just before the closing Body tag without being wrapped in a Head tag. As a result, the generated HTML is invalid.

Your environment

Steps to reproduce

Provided with a minimal Hast object containing the HTML DocType, Head, and Body elements:
{ type: 'element', tagName: 'html', children: [ { type: 'element', tagName: 'head', children: [headContent] }, { type: 'element', tagName: 'body', children: [bodyContent] }, ] }

🎉 BONUS POINTS for creating a minimal reproduction and uploading it to GitHub. This will get you the fastest support. 🎉

Expected behaviour

<html>
<head>headContent</head>
<body>bodyContent</body>
</html>

Actual behaviour

<html>
<body>
bodyContent
headContent
</body>
</html>

What happens instead?
The contents of the Head are not wrapped in a Head tag, and are spit-out just before the closing body tag.

Problem when installing with npm

When I fork this repo and try to run npm install, I got this:

bash-3.2$ npm i
npm WARN deprecated [email protected]: Just use Array.isArray directly
npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "i"
npm ERR! node v7.3.0
npm ERR! npm  v3.10.10
npm ERR! path /Users/hwong/.npm/es6-weak-map/2.0.2
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir

npm ERR! Error: EACCES: permission denied, mkdir '/Users/hwong/.npm/es6-weak-map/2.0.2'
npm ERR!  { Error: EACCES: permission denied, mkdir '/Users/hwong/.npm/es6-weak-map/2.0.2'
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/Users/hwong/.npm/es6-weak-map/2.0.2',
npm ERR!   parent: 'escope' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/hwong/github/unional/hast-util-to-html/npm-debug.log

My guess is esrecurse. Here is the last part of npm-debug.log (as it is very long to post here):

23829 verbose get https://registry.npmjs.org/esrecurse not expired, no request
23830 silly addNameRange number 2 { name: 'esrecurse', range: '>=4.1.0 <5.0.0', hasData: true }
23831 silly addNameRange versions [ 'esrecurse',
23831 silly addNameRange   [ '1.0.0',
23831 silly addNameRange     '1.0.1',
23831 silly addNameRange     '1.1.0',
23831 silly addNameRange     '1.2.0',
23831 silly addNameRange     '2.0.0',
23831 silly addNameRange     '3.0.0',
23831 silly addNameRange     '3.1.0',
23831 silly addNameRange     '3.1.1',
23831 silly addNameRange     '4.0.0',
23831 silly addNameRange     '4.1.0' ] ]
23832 silly addNamed [email protected]
23833 verbose addNamed "4.1.0" is a plain semver version for esrecurse
23834 verbose get https://registry.npmjs.org/es6-weak-map not expired, no request
23835 silly addNameRange number 2 { name: 'es6-weak-map', range: '>=2.0.1 <3.0.0', hasData: true }
23836 silly addNameRange versions [ 'es6-weak-map',
23836 silly addNameRange   [ '0.0.0',
23836 silly addNameRange     '0.1.0',
23836 silly addNameRange     '0.1.1',
23836 silly addNameRange     '0.1.2',
23836 silly addNameRange     '0.1.3',
23836 silly addNameRange     '0.1.4',
23836 silly addNameRange     '1.0.0',
23836 silly addNameRange     '1.0.1',
23836 silly addNameRange     '1.0.2',
23836 silly addNameRange     '2.0.0',
23836 silly addNameRange     '2.0.1',
23836 silly addNameRange     '2.0.2' ] ]
23837 silly addNamed [email protected]
23838 verbose addNamed "2.0.2" is a plain semver version for es6-weak-map
23839 verbose get https://registry.npmjs.org/es6-map not expired, no request
23840 silly addNameRange number 2 { name: 'es6-map', range: '>=0.1.3 <0.2.0', hasData: true }
23841 silly addNameRange versions [ 'es6-map',
23841 silly addNameRange   [ '0.0.0',
23841 silly addNameRange     '0.0.1',
23841 silly addNameRange     '0.1.0',
23841 silly addNameRange     '0.1.1',
23841 silly addNameRange     '0.1.2',
23841 silly addNameRange     '0.1.3',
23841 silly addNameRange     '0.1.4',
23841 silly addNameRange     '0.1.5' ] ]
23842 silly addNamed [email protected]
23843 verbose addNamed "0.1.5" is a plain semver version for es6-map
23844 silly mapToRegistry name es6-weak-map
23845 silly mapToRegistry using default registry
23846 silly mapToRegistry registry https://registry.npmjs.org/
23847 silly mapToRegistry data Result {
23847 silly mapToRegistry   raw: 'es6-weak-map',
23847 silly mapToRegistry   scope: null,
23847 silly mapToRegistry   escapedName: 'es6-weak-map',
23847 silly mapToRegistry   name: 'es6-weak-map',
23847 silly mapToRegistry   rawSpec: '',
23847 silly mapToRegistry   spec: 'latest',
23847 silly mapToRegistry   type: 'tag' }
23848 silly mapToRegistry uri https://registry.npmjs.org/es6-weak-map
23849 verbose addRemoteTarball https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.2.tgz not in flight; adding
23850 verbose addRemoteTarball [ 'https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.2.tgz',
23850 verbose addRemoteTarball   '5e3ab32251ffd1538a1f8e5ffa1357772f92d96f' ]
23851 silly cache afterAdd [email protected]
23852 verbose afterAdd /Users/hwong/.npm/esrecurse/4.1.0/package/package.json not in flight; writing
23853 verbose correctMkdir /Users/hwong/.npm correctMkdir not in flight; initializing
23854 info retry fetch attempt 1 at 11:46:58 AM
23855 info attempt registry request try #1 at 11:46:58 AM
23856 http fetch GET https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.2.tgz
23857 silly cache afterAdd [email protected]
23858 verbose afterAdd /Users/hwong/.npm/es6-map/0.1.5/package/package.json not in flight; writing
23859 verbose correctMkdir /Users/hwong/.npm correctMkdir not in flight; initializing
23860 verbose afterAdd /Users/hwong/.npm/es6-map/0.1.5/package/package.json written
23861 verbose afterAdd /Users/hwong/.npm/esrecurse/4.1.0/package/package.json written
23862 http fetch 200 https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.2.tgz
23863 silly fetchAndShaCheck shasum 5e3ab32251ffd1538a1f8e5ffa1357772f92d96f
23864 verbose addTmpTarball /var/folders/zl/l_7sqkhd1zd84mbbrhtbx4j9yfd8z6/T/npm-91769-c13a28b7/registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.2.tgz not in flight; adding
23865 verbose addTmpTarball already have metadata; skipping unpack for [email protected]
23866 verbose correctMkdir /Users/hwong/.npm correctMkdir not in flight; initializing
23867 silly rollbackFailedOptional Starting
23868 silly rollbackFailedOptional Finishing
23869 silly runTopLevelLifecycles Finishing
23870 silly install printInstalled
23871 verbose stack Error: EACCES: permission denied, mkdir '/Users/hwong/.npm/es6-weak-map/2.0.2'
23872 verbose cwd /Users/hwong/github/unional/hast-util-to-html
23873 error Darwin 16.4.0
23874 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "i"
23875 error node v7.3.0
23876 error npm  v3.10.10
23877 error path /Users/hwong/.npm/es6-weak-map/2.0.2
23878 error code EACCES
23879 error errno -13
23880 error syscall mkdir
23881 error Error: EACCES: permission denied, mkdir '/Users/hwong/.npm/es6-weak-map/2.0.2'
23881 error  { Error: EACCES: permission denied, mkdir '/Users/hwong/.npm/es6-weak-map/2.0.2'
23881 error   errno: -13,
23881 error   code: 'EACCES',
23881 error   syscall: 'mkdir',
23881 error   path: '/Users/hwong/.npm/es6-weak-map/2.0.2',
23881 error   parent: 'escope' }
23882 error Please try running this command again as root/Administrator.
23883 verbose exit [ -13, true ]

Request more control over escaping

Initial checklist

Problem

I'm using toHtml to stringify highlighted code elements and then use them in MDsveX, a Svelte version of MDX. Though I need to escape [{}`] because those are special characters in Svelte. I was attempting to escape them at the base of the AST on the text values. But I they were getting double escaped. I then figured out toHtml escapes &.

Currently, I'm running the hast through toHTML and then escaping the other characters I need. Though this seems brittle and also much less targeted than having control at the Text.value level.

Solution

  • make it possible to disable escaping in toHtml
  • expose a escape option that allows overriding the default.

Alternatives

  • add the ability to add characters to subset

what do you think?

Head elements are not wrapped in a Head tag

Subject of the issue

If this utility is run with a Hast-formatted HTML document containing a DocumentType, Head, and Body, the converted HTML is printed with the DocumentType, then the Body, and finally the contents of the Head are spit-out just before the closing Body tag without being wrapped in a Head tag. As a result, the generated HTML is invalid.

Your environment

Steps to reproduce

Provided with a minimal Hast object containing the HTML DocType, Head, and Body elements:
{ type: 'element', tagName: 'html', children: [ { type: 'element', tagName: 'head', children: [headContent] }, { type: 'element', tagName: 'body', children: [bodyContent] }, ] }

🎉 BONUS POINTS for creating a minimal reproduction and uploading it to GitHub. This will get you the fastest support. 🎉

Expected behaviour

<html>
<head>headContent</head>
<body>bodyContent</body>
</html>

Actual behaviour

<html>
<body>
bodyContent
headContent
</body>
</html>

What happens instead?
The contents of the Head are not wrapped in a Head tag, and are spit-out just before the closing body tag.

`list-style-type` is stringified incorrectly

Initial checklist

Affected packages and versions

latest

Link to runnable example

No response

Steps to reproduce

toHtml(h("foo", {style: {"list-style-type": "'X'"}}))

Expected behavior

<foo style="list-style-type: 'X'"></foo>

Actual behavior

<foo style="list-style-type: &#x27;X&#x27;"></foo>

Runtime

Node v16

Package manager

npm v7

OS

No response

Build and bundle tools

No response

As per https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type list-style-type should accept a quoted string as one of its possible values. However, if a quoted string is supplied, the quotes are escaped producing invalid CSS.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.