This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
type Plugin = any;
/**
* A remark plugin to extract the h1 heading found in Markdown files
* This is exposed as "data.contentTitle" to the processed vfile
* Also gives the ability to strip that content title (used for the blog plugin)
*/
declare const plugin: Plugin;
export default plugin;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/contentTitle/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,KAAK,MAAM,GAAG,GAAG,CAAC;AAMlB;;;;GAIG;AACH,QAAA,MAAM,MAAM,EAAE,MA0Bb,CAAC;AAEF,eAAe,MAAM,CAAC"}

View File

@@ -0,0 +1,38 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
/**
* A remark plugin to extract the h1 heading found in Markdown files
* This is exposed as "data.contentTitle" to the processed vfile
* Also gives the ability to strip that content title (used for the blog plugin)
*/
const plugin = function plugin(options = {}) {
// content title is
const removeContentTitle = options.removeContentTitle ?? false;
return async (root, vfile) => {
const { toString } = await import('mdast-util-to-string');
const { visit, EXIT } = await import('unist-util-visit');
visit(root, 'heading', (headingNode, index, parent) => {
if (headingNode.depth === 1) {
vfile.data.contentTitle = toString(headingNode);
if (removeContentTitle) {
// @ts-expect-error: TODO how to fix?
parent.children.splice(index, 1);
}
return EXIT; // We only handle the very first heading
}
// We only handle contentTitle if it's the very first heading found
if (headingNode.depth >= 1) {
return EXIT;
}
return undefined;
});
};
};
exports.default = plugin;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/contentTitle/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAgBH;;;;GAIG;AACH,MAAM,MAAM,GAAW,SAAS,MAAM,CACpC,UAAyB,EAAE;IAE3B,mBAAmB;IACnB,MAAM,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,IAAI,KAAK,CAAC;IAE/D,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC3B,MAAM,EAAC,QAAQ,EAAC,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;QACxD,MAAM,EAAC,KAAK,EAAE,IAAI,EAAC,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAEvD,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,WAAoB,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC7D,IAAI,WAAW,CAAC,KAAK,KAAK,CAAC,EAAE;gBAC3B,KAAK,CAAC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;gBAChD,IAAI,kBAAkB,EAAE;oBACtB,qCAAqC;oBACrC,MAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;iBACnC;gBACD,OAAO,IAAI,CAAC,CAAC,wCAAwC;aACtD;YACD,mEAAmE;YACnE,IAAI,WAAW,CAAC,KAAK,IAAI,CAAC,EAAE;gBAC1B,OAAO,IAAI,CAAC;aACb;YACD,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}