@unified-latex/unified-latex-util-trim
TypeScript icon, indicating that this package has built-in type declarations

1.8.0 • Public • Published

unified-latex-util-trim

What is this?

Functions to help modify a unified-latex Abstract Syntax Tree (AST).

When should I use this?

If you want to remove whitespace from the ends of an array of nodes.

Note that whitespace can come from a Ast.Whitespace node or from an Ast.Comment node that has leading whitespace. These functions take care to deal with both situations.

Install

npm install @unified-latex/unified-latex-util-trim

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.

Plugins

unifiedLatexTrimEnvironmentContents

Unified plugin to trim the whitespace from the start/end of any environments, including math environments.

Usage

unified().use(unifiedLatexTrimEnvironmentContents)

Type

Plugin<void[], Ast.Root, Ast.Root>

function unifiedLatexTrimEnvironmentContents(): (tree: Ast.Root) => void;

unifiedLatexTrimRoot

Unified plugin to trim the whitespace from the start/end of the root element.

Usage

unified().use(unifiedLatexTrimRoot)

Type

Plugin<void[], Ast.Root, Ast.Root>

function unifiedLatexTrimRoot(): (tree: Ast.Root) => void;

Functions

hasWhitespaceEquivalent(nodes)

Returns whether the array has whitespace at the start/end. Comments with leadingWhitespace === true are counted as whitespace. Other comments are ignored.

function hasWhitespaceEquivalent(nodes: Ast.Node[]): {
  start: boolean;
  end: boolean;
};

Parameters

Param Type
nodes Ast.Node[]

trim(nodes)

Trims whitespace and parbreaks from the start and end of an array. The number of trimmed nodes is returned. Special care is taken to preserve comments, though any whitespace before the first comment(s) or after the last comment(s) is trimmed.

function trim(nodes: Ast.Node[]): { trimmedStart: number; trimmedEnd: number };

Parameters

Param Type
nodes Ast.Node[]

trimEnd(nodes)

Trim whitespace and parbreaks from the right of an array.

function trimEnd(nodes: Ast.Node[]): { trimmedEnd: number };

Parameters

Param Type
nodes Ast.Node[]

trimStart(nodes)

Trim whitespace and parbreaks from the left of an array.

function trimStart(nodes: Ast.Node[]): { trimmedStart: number };

Parameters

Param Type
nodes Ast.Node[]

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.8.03,123latest

Version History

VersionDownloads (Last 7 Days)Published
1.8.03,123
1.7.1361
1.7.02
1.6.12
1.6.05
1.4.25
1.4.022
1.3.20
1.3.11
1.3.00
1.2.20
1.2.10
1.2.00
1.1.00
1.0.121
1.0.110
1.0.100
1.0.80
1.0.70
1.0.60
1.0.50
1.0.10

Package Sidebar

Install

npm i @unified-latex/unified-latex-util-trim

Weekly Downloads

2,638

Version

1.8.0

License

MIT

Unpacked Size

33.5 kB

Total Files

7

Last publish

Collaborators

  • siefkenj