myst-transforms
Advanced tools
Comparing version 0.0.17 to 0.0.18
@@ -12,5 +12,6 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports.admonitionHeadersPlugin = exports.admonitionHeadersTransform = exports.admonitionKindToTitle = void 0; | ||
exports.admonitionBlockquotePlugin = exports.admonitionHeadersPlugin = exports.admonitionBlockquoteTransform = exports.admonitionHeadersTransform = exports.admonitionKindToTitle = void 0; | ||
var unist_util_select_1 = require("unist-util-select"); | ||
var types_1 = require("./types"); | ||
var githubAdmonitionKinds = ['note', 'warning']; | ||
function admonitionKindToTitle(kind) { | ||
@@ -68,2 +69,33 @@ var transform = { | ||
exports.admonitionHeadersTransform = admonitionHeadersTransform; | ||
/** | ||
* Visit all blockquote notes and add headers if necessary, support GitHub style admonitions | ||
*/ | ||
function admonitionBlockquoteTransform(tree) { | ||
var blockquote = (0, unist_util_select_1.selectAll)('blockquote', tree); | ||
blockquote.forEach(function (node) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
if (!node.children || | ||
((_b = (_a = node.children) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type) !== 'paragraph' || | ||
((_d = (_c = node.children[0].children) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.type) !== 'strong') { | ||
return; | ||
} | ||
var strong = node.children[0].children[0]; | ||
if (((_e = strong.children) === null || _e === void 0 ? void 0 : _e[0].type) !== 'text') | ||
return; | ||
var kind = (_g = (_f = strong.children[0].value) === null || _f === void 0 ? void 0 : _f.trim().toLowerCase()) !== null && _g !== void 0 ? _g : ''; | ||
if (!githubAdmonitionKinds.includes(kind)) | ||
return; | ||
node.type = 'admonition'; | ||
node.kind = kind; | ||
node["class"] = node["class"] ? node["class"] + ' simple' : 'simple'; | ||
node.children[0].children.splice(0, 1); // Get rid of the strong node | ||
node.children = __spreadArray([ | ||
{ | ||
type: 'admonitionTitle', | ||
children: [{ type: 'text', value: admonitionKindToTitle(node.kind) }] | ||
} | ||
], node.children, true); | ||
}); | ||
} | ||
exports.admonitionBlockquoteTransform = admonitionBlockquoteTransform; | ||
var admonitionHeadersPlugin = function (opts) { return function (tree) { | ||
@@ -73,1 +105,5 @@ admonitionHeadersTransform(tree, opts); | ||
exports.admonitionHeadersPlugin = admonitionHeadersPlugin; | ||
var admonitionBlockquotePlugin = function () { return function (tree) { | ||
admonitionBlockquoteTransform(tree); | ||
}; }; | ||
exports.admonitionBlockquotePlugin = admonitionBlockquotePlugin; |
@@ -25,2 +25,3 @@ "use strict"; | ||
(0, targets_1.headingLabelTransform)(tree); | ||
(0, admonitions_1.admonitionBlockquoteTransform)(tree); // Must be before header transforms | ||
(0, admonitions_1.admonitionHeadersTransform)(tree); | ||
@@ -27,0 +28,0 @@ (0, blocks_1.blockNestingTransform)(tree); |
@@ -38,2 +38,8 @@ "use strict"; | ||
return h(node, '_break'); | ||
}, | ||
comment: function (h, node) { | ||
// Prevents HTML comments from showing up as text in web | ||
var result = h(node, 'comment'); | ||
result.value = node.value; | ||
return result; | ||
} | ||
@@ -40,0 +46,0 @@ } |
@@ -17,6 +17,8 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports.getFrontmatter = exports.unnestTransform = exports.basicTransformations = exports.basicTransformationsPlugin = exports.MultiPageReferenceState = exports.ReferenceState = exports.resolveReferencesPlugin = exports.resolveReferencesTransform = exports.enumerateTargetsPlugin = exports.enumerateTargetsTransform = exports.headingLabelTransform = exports.headingLabelPlugin = exports.mystTargetsTransform = exports.mystTargetsPlugin = exports.liftMystDirectivesAndRolesTransform = exports.liftMystDirectivesAndRolesPlugin = exports.imageAltTextTransform = exports.imageAltTextPlugin = exports.blockquoteTransform = exports.blockquotePlugin = exports.codeTransform = exports.codePlugin = exports.blockMetadataTransform = exports.blockMetadataPlugin = exports.blockNestingTransform = exports.blockNestingPlugin = exports.mathNestingTransform = exports.mathLabelTransform = exports.mathTransform = exports.mathNestingPlugin = exports.mathLabelPlugin = exports.mathPlugin = exports.keysTransform = exports.keysPlugin = exports.htmlIdsTransform = exports.htmlIdsPlugin = exports.htmlTransform = exports.htmlPlugin = exports.footnotesTransform = exports.footnotesPlugin = exports.captionParagraphTransform = exports.captionParagraphPlugin = exports.AdmonitionKind = exports.admonitionKindToTitle = exports.admonitionHeadersTransform = exports.admonitionHeadersPlugin = void 0; | ||
exports.getFrontmatter = exports.unnestTransform = exports.basicTransformations = exports.basicTransformationsPlugin = exports.MultiPageReferenceState = exports.ReferenceState = exports.resolveReferencesPlugin = exports.resolveReferencesTransform = exports.enumerateTargetsPlugin = exports.enumerateTargetsTransform = exports.headingLabelTransform = exports.headingLabelPlugin = exports.mystTargetsTransform = exports.mystTargetsPlugin = exports.liftMystDirectivesAndRolesTransform = exports.liftMystDirectivesAndRolesPlugin = exports.imageAltTextTransform = exports.imageAltTextPlugin = exports.blockquoteTransform = exports.blockquotePlugin = exports.codeTransform = exports.codePlugin = exports.blockMetadataTransform = exports.blockMetadataPlugin = exports.blockNestingTransform = exports.blockNestingPlugin = exports.mathNestingTransform = exports.mathLabelTransform = exports.mathTransform = exports.mathNestingPlugin = exports.mathLabelPlugin = exports.mathPlugin = exports.keysTransform = exports.keysPlugin = exports.htmlIdsTransform = exports.htmlIdsPlugin = exports.htmlTransform = exports.htmlPlugin = exports.footnotesTransform = exports.footnotesPlugin = exports.captionParagraphTransform = exports.captionParagraphPlugin = exports.AdmonitionKind = exports.admonitionKindToTitle = exports.admonitionBlockquoteTransform = exports.admonitionBlockquotePlugin = exports.admonitionHeadersTransform = exports.admonitionHeadersPlugin = void 0; | ||
var admonitions_1 = require("./admonitions"); | ||
__createBinding(exports, admonitions_1, "admonitionHeadersPlugin"); | ||
__createBinding(exports, admonitions_1, "admonitionHeadersTransform"); | ||
__createBinding(exports, admonitions_1, "admonitionBlockquotePlugin"); | ||
__createBinding(exports, admonitions_1, "admonitionBlockquoteTransform"); | ||
__createBinding(exports, admonitions_1, "admonitionKindToTitle"); | ||
@@ -23,0 +25,0 @@ var types_1 = require("./types"); |
@@ -12,2 +12,3 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
import { AdmonitionKind } from './types'; | ||
var githubAdmonitionKinds = ['note', 'warning']; | ||
export function admonitionKindToTitle(kind) { | ||
@@ -63,4 +64,37 @@ var transform = { | ||
} | ||
/** | ||
* Visit all blockquote notes and add headers if necessary, support GitHub style admonitions | ||
*/ | ||
export function admonitionBlockquoteTransform(tree) { | ||
var blockquote = selectAll('blockquote', tree); | ||
blockquote.forEach(function (node) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
if (!node.children || | ||
((_b = (_a = node.children) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type) !== 'paragraph' || | ||
((_d = (_c = node.children[0].children) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.type) !== 'strong') { | ||
return; | ||
} | ||
var strong = node.children[0].children[0]; | ||
if (((_e = strong.children) === null || _e === void 0 ? void 0 : _e[0].type) !== 'text') | ||
return; | ||
var kind = (_g = (_f = strong.children[0].value) === null || _f === void 0 ? void 0 : _f.trim().toLowerCase()) !== null && _g !== void 0 ? _g : ''; | ||
if (!githubAdmonitionKinds.includes(kind)) | ||
return; | ||
node.type = 'admonition'; | ||
node.kind = kind; | ||
node["class"] = node["class"] ? node["class"] + ' simple' : 'simple'; | ||
node.children[0].children.splice(0, 1); // Get rid of the strong node | ||
node.children = __spreadArray([ | ||
{ | ||
type: 'admonitionTitle', | ||
children: [{ type: 'text', value: admonitionKindToTitle(node.kind) }] | ||
} | ||
], node.children, true); | ||
}); | ||
} | ||
export var admonitionHeadersPlugin = function (opts) { return function (tree) { | ||
admonitionHeadersTransform(tree, opts); | ||
}; }; | ||
export var admonitionBlockquotePlugin = function () { return function (tree) { | ||
admonitionBlockquoteTransform(tree); | ||
}; }; |
import { liftMystDirectivesAndRolesTransform } from './liftMystDirectivesAndRoles'; | ||
import { mystTargetsTransform, headingLabelTransform } from './targets'; | ||
import { captionParagraphTransform } from './caption'; | ||
import { admonitionHeadersTransform } from './admonitions'; | ||
import { admonitionBlockquoteTransform, admonitionHeadersTransform } from './admonitions'; | ||
import { blockMetadataTransform, blockNestingTransform } from './blocks'; | ||
@@ -22,2 +22,3 @@ import { htmlIdsTransform } from './htmlIds'; | ||
headingLabelTransform(tree); | ||
admonitionBlockquoteTransform(tree); // Must be before header transforms | ||
admonitionHeadersTransform(tree); | ||
@@ -24,0 +25,0 @@ blockNestingTransform(tree); |
@@ -32,2 +32,8 @@ var __assign = (this && this.__assign) || function () { | ||
return h(node, '_break'); | ||
}, | ||
comment: function (h, node) { | ||
// Prevents HTML comments from showing up as text in web | ||
var result = h(node, 'comment'); | ||
result.value = node.value; | ||
return result; | ||
} | ||
@@ -34,0 +40,0 @@ } |
@@ -1,2 +0,2 @@ | ||
export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionKindToTitle, } from './admonitions'; | ||
export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionBlockquotePlugin, admonitionBlockquoteTransform, admonitionKindToTitle, } from './admonitions'; | ||
export { AdmonitionKind } from './types'; | ||
@@ -3,0 +3,0 @@ export { captionParagraphPlugin, captionParagraphTransform } from './caption'; |
@@ -13,4 +13,9 @@ import type { Plugin } from 'unified'; | ||
export declare function admonitionHeadersTransform(tree: Root, opts?: Options): void; | ||
/** | ||
* Visit all blockquote notes and add headers if necessary, support GitHub style admonitions | ||
*/ | ||
export declare function admonitionBlockquoteTransform(tree: Root): void; | ||
export declare const admonitionHeadersPlugin: Plugin<[Options?], Root, Root>; | ||
export declare const admonitionBlockquotePlugin: Plugin<[], Root, Root>; | ||
export {}; | ||
//# sourceMappingURL=admonitions.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionKindToTitle, } from './admonitions'; | ||
export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionBlockquotePlugin, admonitionBlockquoteTransform, admonitionKindToTitle, } from './admonitions'; | ||
export { AdmonitionKind } from './types'; | ||
@@ -3,0 +3,0 @@ export { captionParagraphPlugin, captionParagraphTransform } from './caption'; |
{ | ||
"name": "myst-transforms", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"sideEffects": false, | ||
@@ -30,3 +30,3 @@ "main": "./dist/cjs/index.js", | ||
"myst-spec": "^0.0.4", | ||
"myst-spec-ext": "^0.0.5", | ||
"myst-spec-ext": "^0.0.6", | ||
"unified": "^10.0.0", | ||
@@ -33,0 +33,0 @@ "unist-util-modify-children": "^3.1.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
Sorry, the diff of this file is not supported yet
198524
4262
+ Addedmyst-spec-ext@0.0.6(transitive)
- Removedmyst-spec-ext@0.0.5(transitive)
Updatedmyst-spec-ext@^0.0.6