npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@unified-latex/unified-latex-util-html-like

v1.8.0

Published

Tools working with HTML-like nodes via unified-latex ASTs

Downloads

127

Readme

unified-latex-util-html-like

What is this?

Functions to help with making html-like nodes in a unified-latex Abstract Syntax Tree (AST).

For example, <p>foo</p> can be stored as \html-tag:p{foo} in unified-latex. Because - and : are special characters, they cannot appear in a macro name, so there is no risk of name conflicts. These macros are created programmatically, so special characters can be inserted.

When should I use this?

If you are converting LaTeX to HTML, these functions may be used as an intermediate format.

Using with unified-latex-to-hast

unified-latex-to-hast first processes a document into html-like nodes and then converts the resulting document to HAST/HTML. Any html-like macros that are created will be transparently converted to HAST/HTML. For example, if you wanted to convert all \foo macros into <br /> tags, you could first preprocess your unified-latex AST and replace all occurrences of \foo with htmlLike({ tag: "br" }). When the AST is converted to HTML, the html-like macros will be rendered as <br /> tags.

Install

npm install @unified-latex/unified-latex-util-html-like

This package contains both esm and commonjs exports. To explicitly access the esm export, import the .js file. To explicitly access the commonjs export, import the .cjs file.

Functions

extractFromHtmlLike(macro)

Extract the contents/attributes/tag from an html-like macro.

function extractFromHtmlLike(macro: Ast.Macro): {
  tag: string;
  attributes: Record<string, string | number | boolean | object>;
  content: Ast.Node[];
};

Parameters

| Param | Type | | :---- | :---------- | | macro | Ast.Macro |

htmlLike({ tag, content, attributes, })

Make an html-like node storing content. The node is a macro and content as well as any attributes can be extracted or further processed. Collisions are avoided with existing macros because all macros are prefixed with html-tag: or html-attribute:, which contain special characters that normal macros cannot have.

function htmlLike({
  tag,
  content,
  attributes,
}: {
  tag: string;
  content?: Ast.Node | Ast.Node[];
  attributes?: object;
}): Ast.Macro;

Parameters

| Param | Type | | :-------------------------------------------------------- | :-------------------------------- | | { tag, content, attributes, } | Omitted |

isHtmlLike(node)

Determine whether the node is an html-like macro.

function isHtmlLike(node: any): boolean;

Parameters

| Param | Type | | :---- | :---- | | node | any |

isHtmlLikeAttribute(node)

Determine whether the node is an html-like macro for an attribute.

function isHtmlLikeAttribute(node: any): boolean;

Parameters

| Param | Type | | :---- | :---- | | node | any |

isHtmlLikeTag(node)

Determine whether the node is an html-like macro for a tag.

function isHtmlLikeTag(node: any): boolean;

Parameters

| Param | Type | | :---- | :---- | | node | any |