extract-codefence
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

extract-codefence

A lightweight utility to extract code from codefence blocks in markdown-like text.

Installation

npm install extract-codefence

or if you're using Bun:

bun add extract-codefence

Usage

import { extractCodefence } from 'extract-codefence';

const markdownText = `
# Example

Here's some code:

\`\`\`tsx
const greeting = "Hello, World!";
console.log(greeting);
\`\`\`
`;

const extractedCode = extractCodefence(markdownText);
console.log(extractedCode);
// Output: const greeting = "Hello, World!";
//         console.log(greeting);

API

extractCodefence(text: string): string | undefined

Extracts the code from the first codefence block in the given text.

  • text: The input text containing codefence blocks.
  • Returns: The extracted code as a string, or undefined if no codefence block is found.

Development

To set up the project for development:

  1. Clone the repository
  2. Install dependencies:
bun install
  1. Run tests:
bun test
  1. Build the project:
bun run build

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Package Sidebar

Install

npm i extract-codefence

Weekly Downloads

1,226

Version

0.0.4

License

MIT

Unpacked Size

3.18 kB

Total Files

5

Last publish

Collaborators

  • seveibar