New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@unified-latex/unified-latex-util-parse

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unified-latex/unified-latex-util-parse - npm Package Compare versions

Comparing version 1.6.1 to 1.7.0

162

index.d.ts

@@ -1,20 +0,148 @@

export * from "./libs/compiler-ast";
export * from "./libs/plugin-from-string";
export * from "./libs/plugin-from-string-minimal";
export * from "./libs/process-at-letter-and-expl-macros";
export * from "./libs/process-macros-and-environments";
export * from "./libs/parse-minimal";
export * from "./libs/parse";
export * from "./libs/parse-math";
export * from "./libs/reparse-math";
import * as Ast from '@unified-latex/unified-latex-types';
import { EnvInfoRecord } from '@unified-latex/unified-latex-types';
import { FrozenProcessor } from 'unified';
import { MacroInfoRecord } from '@unified-latex/unified-latex-types';
import { Plugin as Plugin_2 } from 'unified';
/**
* ## What is this?
* Returns the default `unified-latex` parser, or create a new one with the
* provided `unifiedLatexFromString` options
* @param options Plugin options of `unifiedLatexFromString` plugin.
* @returns The default `unified-latex` parser if `options` is `undefined`, or a
* newly created `unified-latex` parser with the provided `options`.
*/
export declare function getParser(options?: PluginOptions): FrozenProcessor<Ast.Root, Ast.Root, Ast.Root, void>;
/**
* Parse the string into an AST.
*/
export declare function parse(str: string): Ast.Root;
/**
* Parse `str` into an AST. Parsing starts in math mode and a list of
* nodes is returned (instead of a "root" node).
*/
export declare function parseMath(str: string | Ast.Ast): Ast.Node[];
/**
* Parse `str` to an AST with minimal processing. E.g., macro
* arguments are not attached to macros, etc. when parsed with this
* function.
*
* Functions parse strings to a `unified-latex` Abstract Syntax Tree (AST).
*
* ## When should I use this?
*
* If you have a string that you would like to parse to a `unified-latex` `Ast.Ast`, or
* if you are building a plugin for `unified()` that manipulates LaTeX.
* The parsing assumes a math-mode context, so, for example, `^` and `_` are
* parsed as macros (even though arguments are not attached to them).
*/
//# sourceMappingURL=index.d.ts.map
export declare function parseMathMinimal(str: string): Ast.Node[];
/**
* Parse `str` to an AST with minimal processing. E.g., macro
* arguments are not attached to macros, etc. when parsed with this
* function.
*/
export declare function parseMinimal(str: string): Ast.Root;
export declare type PluginOptions = {
mode?: "math" | "regular";
macros?: MacroInfoRecord;
environments?: EnvInfoRecord;
flags?: {
/**
* Whether to parse macros as if `\makeatletter` is set (i.e., parse `@` as a regular macro character)
*/
atLetter?: boolean;
/**
* Whether to parse macros as if `\ExplSyntaxOn` is set (i.e., parse `_` and `:` as a regular macro character)
*/
expl3?: boolean;
/**
* Attempt to autodetect whether there are macros that look like they should contain `@`, `_`, or `:`.
* Defaults to `false`.
*/
autodetectExpl3AndAtLetter?: boolean;
};
} | undefined;
declare type PluginOptions_2 = {
/**
* Whether the text will be parsed assuming math mode or not.
*/
mode: "math" | "regular";
} | void;
declare type PluginOptions_3 = {
/**
* Whether to parse macros as if `\makeatletter` is set (i.e., parse `@` as a regular macro character).
* If this option is true, it disables autodetect.
*/
atLetter?: boolean;
/**
* Whether to parse macros as if `\ExplSyntaxOn` is set (i.e., parse `_` and `:` as a regular macro character)
* If this option is true, it disables autodetect.
*/
expl3?: boolean;
/**
* Attempt to autodetect whether there are macros that look like they should contain `@`, `_`, or `:`.
* Defaults to `true`.
*/
autodetectExpl3AndAtLetter?: boolean;
} | undefined;
declare type PluginOptions_4 = {
environments: EnvInfoRecord;
macros: MacroInfoRecord;
} | undefined;
declare type PluginOptions_5 = {
/**
* List of environments whose body should be parsed in math mode
*/
mathEnvs: string[];
/**
* List of macros whose bodies should be parsed in math mode
*/
mathMacros: string[];
} | undefined;
/**
* Unified complier plugin that passes through a LaTeX AST without modification.
*/
export declare const unifiedLatexAstComplier: Plugin_2<void[], Ast.Root, Ast.Root>;
/**
* Parse a string to a LaTeX AST.
*/
export declare const unifiedLatexFromString: Plugin_2<PluginOptions[], string, Ast.Root>;
/**
* Parse a string to a LaTeX AST with no post processing. For example,
* no macro arguments will be attached, etc.
*/
export declare const unifiedLatexFromStringMinimal: Plugin_2<PluginOptions_2[], string, Ast.Root>;
/**
* Unified plugin to reprocess macros names to possibly include `@`, `_`, or `:`.
* This plugin detects the `\makeatletter` and `\ExplSyntaxOn` commands and reprocesses macro names
* inside of those blocks to include those characters.
*/
export declare const unifiedLatexProcessAtLetterAndExplMacros: Plugin_2<PluginOptions_3[], Ast.Root, Ast.Root>;
/**
* Unified plugin to process macros and environments. Any environments that contain math content
* are reparsed (if needed) in math mode.
*/
export declare const unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse: Plugin_2<PluginOptions_4[], Ast.Root, Ast.Root>;
/**
* Reparse math environments/macro contents that should have been parsed in math mode but weren't.
*/
export declare const unifiedLatexReparseMath: Plugin_2<PluginOptions_5[], Ast.Root, Ast.Root>;
/**
* Construct the inner function for the `unifiedLatexReparseMath` plugin. This function should not be used by libraries.
*/
export declare function unifiedLatexReparseMathConstructPlugin({ mathEnvs, mathMacros, }: {
mathEnvs: string[];
mathMacros: string[];
}): (tree: Ast.Root) => void;
export { }

86

index.js

@@ -1,16 +0,14 @@

// libs/compiler-ast.ts
var unifiedLatexAstComplier = function unifiedLatexAstComplier2() {
import { unified } from "unified";
import { macroInfo, environmentInfo } from "@unified-latex/unified-latex-ctan";
import { unifiedLatexTrimEnvironmentContents, unifiedLatexTrimRoot } from "@unified-latex/unified-latex-util-trim";
import { LatexPegParser } from "@unified-latex/unified-latex-util-pegjs";
import { visit } from "@unified-latex/unified-latex-util-visit";
import { match } from "@unified-latex/unified-latex-util-match";
import { printRaw } from "@unified-latex/unified-latex-util-print-raw";
import { attachMacroArgsInArray } from "@unified-latex/unified-latex-util-arguments";
import { processEnvironment } from "@unified-latex/unified-latex-util-environments";
import { reparseExpl3AndAtLetterRegions, hasReparsableMacroNames, reparseMacroNames } from "@unified-latex/unified-latex-util-catcode";
const unifiedLatexAstComplier = function unifiedLatexAstComplier2() {
Object.assign(this, { Compiler: (x) => x });
};
// libs/plugin-from-string.ts
import { unified } from "unified";
import { environmentInfo, macroInfo } from "@unified-latex/unified-latex-ctan";
import {
unifiedLatexTrimEnvironmentContents,
unifiedLatexTrimRoot
} from "@unified-latex/unified-latex-util-trim";
// libs/parse-minimal.ts
import { LatexPegParser } from "@unified-latex/unified-latex-util-pegjs";
function parseMinimal(str) {

@@ -22,5 +20,3 @@ return LatexPegParser.parse(str);

}
// libs/plugin-from-string-minimal.ts
var unifiedLatexFromStringMinimal = function unifiedLatexFromStringMinimal2(options) {
const unifiedLatexFromStringMinimal = function unifiedLatexFromStringMinimal2(options) {
const parser2 = (str) => {

@@ -38,13 +34,3 @@ if ((options == null ? void 0 : options.mode) === "math") {

};
// libs/process-macros-and-environments.ts
import { visit as visit2 } from "@unified-latex/unified-latex-util-visit";
import { match as match2 } from "@unified-latex/unified-latex-util-match";
import { printRaw as printRaw2 } from "@unified-latex/unified-latex-util-print-raw";
// libs/reparse-math.ts
import { match } from "@unified-latex/unified-latex-util-match";
import { printRaw } from "@unified-latex/unified-latex-util-print-raw";
import { visit } from "@unified-latex/unified-latex-util-visit";
var unifiedLatexReparseMath = function unifiedLatexReparseMath2(options) {
const unifiedLatexReparseMath = function unifiedLatexReparseMath2(options) {
const { mathEnvs = [], mathMacros = [] } = options || {};

@@ -93,7 +79,3 @@ return unifiedLatexReparseMathConstructPlugin({ mathMacros, mathEnvs });

}
// libs/process-macros-and-environments.ts
import { attachMacroArgsInArray } from "@unified-latex/unified-latex-util-arguments";
import { processEnvironment } from "@unified-latex/unified-latex-util-environments";
var unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse = function unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse2(options) {
const unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse = function unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse2(options) {
const { environments = {}, macros = {} } = options || {};

@@ -120,6 +102,6 @@ const mathMacros = Object.fromEntries(

});
const isRelevantEnvironment = match2.createEnvironmentMatcher(environments);
const isRelevantMathEnvironment = match2.createEnvironmentMatcher(mathEnvs);
const isRelevantEnvironment = match.createEnvironmentMatcher(environments);
const isRelevantMathEnvironment = match.createEnvironmentMatcher(mathEnvs);
return (tree) => {
visit2(
visit(
tree,

@@ -137,3 +119,3 @@ {

}
const envName = printRaw2(node.env);
const envName = printRaw(node.env);
const envInfo = environments[envName];

@@ -151,3 +133,3 @@ if (!envInfo) {

mathReparser(tree);
visit2(
visit(
tree,

@@ -165,3 +147,3 @@ {

}
const envName = printRaw2(node.env);
const envName = printRaw(node.env);
const envInfo = environments[envName];

@@ -180,10 +162,3 @@ if (!envInfo) {

};
// libs/process-at-letter-and-expl-macros.ts
import { reparseExpl3AndAtLetterRegions } from "@unified-latex/unified-latex-util-catcode";
import {
hasReparsableMacroNames,
reparseMacroNames
} from "@unified-latex/unified-latex-util-catcode";
var unifiedLatexProcessAtLetterAndExplMacros = function unifiedLatexProcessAtLetterAndExplMacros2(options) {
const unifiedLatexProcessAtLetterAndExplMacros = function unifiedLatexProcessAtLetterAndExplMacros2(options) {
let {

@@ -216,5 +191,3 @@ atLetter = false,

};
// libs/plugin-from-string.ts
var unifiedLatexFromString = function unifiedLatexFromString2(options) {
const unifiedLatexFromString = function unifiedLatexFromString2(options) {
const {

@@ -254,6 +227,3 @@ mode = "regular",

};
// libs/parse.ts
import { unified as unified2 } from "unified";
var parser = unified2().use(unifiedLatexFromString).freeze();
let parser = unified().use(unifiedLatexFromString).freeze();
function parse(str) {

@@ -263,13 +233,9 @@ return parser.parse(str);

function getParser(options) {
return options ? unified2().use(unifiedLatexFromString, options).freeze() : parser;
return options ? unified().use(unifiedLatexFromString, options).freeze() : parser;
}
// libs/parse-math.ts
import { unified as unified3 } from "unified";
import { printRaw as printRaw3 } from "@unified-latex/unified-latex-util-print-raw";
function parseMath(str) {
if (typeof str !== "string") {
str = printRaw3(str);
str = printRaw(str);
}
const file = unified3().use(unifiedLatexFromString, { mode: "math" }).use(unifiedLatexAstComplier).processSync({ value: str });
const file = unified().use(unifiedLatexFromString, { mode: "math" }).use(unifiedLatexAstComplier).processSync({ value: str });
return file.result.content;

@@ -276,0 +242,0 @@ }

{
"name": "@unified-latex/unified-latex-util-parse",
"version": "1.6.1",
"version": "1.7.0",
"description": "Tools for manipulating unified-latex ASTs",

@@ -8,12 +8,12 @@ "main": "index.js",

"dependencies": {
"@unified-latex/unified-latex-ctan": "^1.6.1",
"@unified-latex/unified-latex-types": "^1.6.1",
"@unified-latex/unified-latex-util-arguments": "^1.6.1",
"@unified-latex/unified-latex-util-catcode": "^1.6.1",
"@unified-latex/unified-latex-util-environments": "^1.6.1",
"@unified-latex/unified-latex-util-match": "^1.6.1",
"@unified-latex/unified-latex-util-pegjs": "^1.6.1",
"@unified-latex/unified-latex-util-print-raw": "^1.6.1",
"@unified-latex/unified-latex-util-trim": "^1.6.1",
"@unified-latex/unified-latex-util-visit": "^1.6.1",
"@unified-latex/unified-latex-ctan": "^1.7.0",
"@unified-latex/unified-latex-types": "^1.7.0",
"@unified-latex/unified-latex-util-arguments": "^1.7.0",
"@unified-latex/unified-latex-util-catcode": "^1.7.0",
"@unified-latex/unified-latex-util-environments": "^1.7.0",
"@unified-latex/unified-latex-util-match": "^1.7.0",
"@unified-latex/unified-latex-util-pegjs": "^1.7.0",
"@unified-latex/unified-latex-util-print-raw": "^1.7.0",
"@unified-latex/unified-latex-util-trim": "^1.7.0",
"@unified-latex/unified-latex-util-visit": "^1.7.0",
"unified": "^10.1.2"

@@ -20,0 +20,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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