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

myst-transforms

Package Overview
Dependencies
Maintainers
3
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

myst-transforms - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

2

dist/admonitions.d.ts
import type { Plugin } from 'unified';
import type { GenericParent } from 'myst-common';
import { AdmonitionKind } from './types.js';
type Options = {

@@ -8,3 +7,2 @@ /** Replace the admonition title with the first paragraph if it is all bold. */

};
export declare function admonitionKindToTitle(kind: AdmonitionKind | string): string;
/**

@@ -11,0 +9,0 @@ * Visit all admonitions and add headers if necessary

import { selectAll } from 'unist-util-select';
import { AdmonitionKind } from './types.js';
import { AdmonitionKind, admonitionKindToTitle } from 'myst-common';
const githubAdmonitionKinds = ['note', 'important', 'warning'];
export function admonitionKindToTitle(kind) {
const transform = {
attention: 'Attention',
caution: 'Caution',
danger: 'Danger',
error: 'Error',
important: 'Important',
hint: 'Hint',
note: 'Note',
seealso: 'See Also',
tip: 'Tip',
warning: 'Warning',
};
return transform[kind] || `Unknown Admonition "${kind}"`;
}
/**

@@ -20,0 +5,0 @@ * Visit all admonitions and add headers if necessary

@@ -5,2 +5,3 @@ import type { Plugin } from 'unified';

import type { GenericParent } from 'myst-common';
import { TargetKind } from 'myst-common';
type ResolvableCrossReference = Omit<CrossReference, 'kind'> & {

@@ -16,9 +17,2 @@ kind?: TargetKind | string;

};
export declare enum TargetKind {
heading = "heading",
equation = "equation",
figure = "figure",
table = "table",
code = "code"
}
export declare enum ReferenceKind {

@@ -25,0 +19,0 @@ ref = "ref",

import { visit } from 'unist-util-visit';
import { select, selectAll } from 'unist-util-select';
import { findAndReplace } from 'mdast-util-find-and-replace';
import { createHtmlId, fileWarn, normalizeLabel, setTextAsChild, copyNode, liftChildren, } from 'myst-common';
import { createHtmlId, fileWarn, normalizeLabel, setTextAsChild, copyNode, liftChildren, TargetKind, } from 'myst-common';
const TRANSFORM_NAME = 'myst-transforms:enumerate';
export var TargetKind;
(function (TargetKind) {
TargetKind["heading"] = "heading";
TargetKind["equation"] = "equation";
TargetKind["figure"] = "figure";
TargetKind["table"] = "table";
TargetKind["code"] = "code";
})(TargetKind || (TargetKind = {}));
function getDefaultNumberedReferenceLabel(kind) {

@@ -15,0 +7,0 @@ switch (kind) {

9

dist/html.d.ts
import type { Plugin } from 'unified';
import type { GenericParent } from 'myst-common';
import type { Handle } from 'hast-util-to-mdast';
import type { GenericParent } from 'myst-common';
export type HtmlTransformOptions = {

@@ -11,3 +11,10 @@ keepBreaks?: boolean;

export declare function htmlTransform(tree: GenericParent, opts?: HtmlTransformOptions): GenericParent;
/**
* Traverse mdast tree to reconstruct html elements split across mdast nodes into a single node
*
* This function identifies html "opening" nodes, then collects the subsequent mdast nodes until
* it encounters a "closing" node, when it consolidates all the nodes into a single html node.
*/
export declare function reconstructHtmlTransform(tree: GenericParent): GenericParent;
export declare const htmlPlugin: Plugin<[HtmlTransformOptions?], GenericParent, GenericParent>;
//# sourceMappingURL=html.d.ts.map
import { unified } from 'unified';
import { liftChildren } from 'myst-common';
import { mystToHtml } from 'myst-to-html';
import { fromHtml } from 'hast-util-from-html';
import { all } from 'hast-util-to-mdast';
import { remove } from 'unist-util-remove';
import { selectAll } from 'unist-util-select';

@@ -7,3 +11,2 @@ import { visit } from 'unist-util-visit';

import rehypeRemark from 'rehype-remark';
import { liftChildren } from 'myst-common';
const defaultHtmlToMdastOptions = {

@@ -60,4 +63,81 @@ keepBreaks: true,

}
/**
* Convert html nodes and children to single html node
*
* This function takes the html nodes with opening and closing tags; all the mdast content
* between these nodes is present as 'children' on the opening node. The mdast content is
* then converted to html, wrapped by the opening and closing tag, and saved to a single html
* node. All of the processed nodes are then marked for deletion.
*/
function finalizeNode(htmlOpenNodeWithChildren, htmlCloseNode) {
var _a, _b;
const innerHtml = mystToHtml({ type: 'root', children: htmlOpenNodeWithChildren.children }, {
hast: {
handlers: {
html: (h, node) => {
return fromHtml(node.value, { fragment: true }).children;
},
},
},
});
// This would be good to sanitize, but the best solution requires jsdom, increasing build size by 50%...
htmlOpenNodeWithChildren.value = `${(_a = htmlOpenNodeWithChildren.value) === null || _a === void 0 ? void 0 : _a.trim()}${innerHtml}${(_b = htmlCloseNode.value) === null || _b === void 0 ? void 0 : _b.trim()}`;
htmlOpenNodeWithChildren.children.forEach((child) => {
child.type = '__delete__';
});
htmlCloseNode.type = '__delete__';
delete htmlOpenNodeWithChildren.children;
}
function reconstructHtml(tree) {
const htmlOpenNodes = [];
tree.children.forEach((child) => {
var _a;
if (child.type === 'html') {
const value = (_a = child.value) === null || _a === void 0 ? void 0 : _a.trim();
if (value === null || value === void 0 ? void 0 : value.startsWith('</')) {
// In this case, child is a standalone closing html node
const htmlOpenNode = htmlOpenNodes.pop();
if (!htmlOpenNode) {
return;
}
finalizeNode(htmlOpenNode, child);
if (htmlOpenNodes.length) {
htmlOpenNodes[htmlOpenNodes.length - 1].children.push(htmlOpenNode);
}
}
else if (!(value === null || value === void 0 ? void 0 : value.endsWith('/>')) && !(value === null || value === void 0 ? void 0 : value.endsWith('-->'))) {
// In this case, child is a standalone opening html node
child.children = [];
htmlOpenNodes.push(child);
}
}
else {
if (child.children) {
// Recursively process children
reconstructHtml(child);
}
if (htmlOpenNodes.length) {
// If we are between an opening and closing node, add this to the html content to be processed
htmlOpenNodes[htmlOpenNodes.length - 1].children.push(child);
}
}
});
// At this point, any htmlOpenNodes are errors; just clean them up.
htmlOpenNodes.forEach((node) => {
delete node.children;
});
}
/**
* Traverse mdast tree to reconstruct html elements split across mdast nodes into a single node
*
* This function identifies html "opening" nodes, then collects the subsequent mdast nodes until
* it encounters a "closing" node, when it consolidates all the nodes into a single html node.
*/
export function reconstructHtmlTransform(tree) {
reconstructHtml(tree);
remove(tree, '__delete__');
return tree;
}
export const htmlPlugin = (opts) => (tree) => {
htmlTransform(tree, opts);
};

@@ -1,6 +0,5 @@

export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionBlockquotePlugin, admonitionBlockquoteTransform, admonitionKindToTitle, } from './admonitions.js';
export { AdmonitionKind } from './types.js';
export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionBlockquotePlugin, admonitionBlockquoteTransform, } from './admonitions.js';
export { captionParagraphPlugin, captionParagraphTransform } from './caption.js';
export { footnotesPlugin, footnotesTransform } from './footnotes.js';
export { htmlPlugin, htmlTransform } from './html.js';
export { htmlPlugin, htmlTransform, reconstructHtmlTransform } from './html.js';
export { htmlIdsPlugin, htmlIdsTransform } from './htmlIds.js';

@@ -19,3 +18,3 @@ export { keysPlugin, keysTransform } from './keys.js';

export { abbreviationPlugin, abbreviationTransform } from './abbreviations.js';
export type { IReferenceState, NumberingOptions, TargetKind, ReferenceKind } from './enumerate.js';
export type { IReferenceState, NumberingOptions, ReferenceKind } from './enumerate.js';
export { enumerateTargetsTransform, enumerateTargetsPlugin, resolveReferencesTransform, resolveReferencesPlugin, ReferenceState, MultiPageReferenceState, } from './enumerate.js';

@@ -22,0 +21,0 @@ export { basicTransformationsPlugin, basicTransformations } from './basic.js';

@@ -1,6 +0,5 @@

export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionBlockquotePlugin, admonitionBlockquoteTransform, admonitionKindToTitle, } from './admonitions.js';
export { AdmonitionKind } from './types.js';
export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionBlockquotePlugin, admonitionBlockquoteTransform, } from './admonitions.js';
export { captionParagraphPlugin, captionParagraphTransform } from './caption.js';
export { footnotesPlugin, footnotesTransform } from './footnotes.js';
export { htmlPlugin, htmlTransform } from './html.js';
export { htmlPlugin, htmlTransform, reconstructHtmlTransform } from './html.js';
export { htmlIdsPlugin, htmlIdsTransform } from './htmlIds.js';

@@ -7,0 +6,0 @@ export { keysPlugin, keysTransform } from './keys.js';

{
"name": "myst-transforms",
"version": "1.1.0",
"version": "1.1.1",
"sideEffects": false,

@@ -23,2 +23,3 @@ "type": "module",

"doi-utils": "^2.0.0",
"hast-util-from-html": "^2.0.1",
"intersphinx": "^1.0.2",

@@ -28,5 +29,6 @@ "js-yaml": "^4.1.0",

"mdast-util-find-and-replace": "^2.1.0",
"myst-common": "^1.1.2",
"myst-common": "^1.1.5",
"myst-spec": "^0.0.4",
"myst-spec-ext": "^1.1.2",
"myst-spec-ext": "^1.1.5",
"myst-to-html": "1.0.7",
"rehype-parse": "^8.0.4",

@@ -33,0 +35,0 @@ "rehype-remark": "^9.1.2",

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

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