Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/liolle/mdparser
markdown parser
https://github.com/liolle/mdparser
markdown npm-package parser typescript
Last synced: 2 months ago
JSON representation
markdown parser
- Host: GitHub
- URL: https://github.com/liolle/mdparser
- Owner: liolle
- License: mit
- Created: 2024-09-20T04:22:47.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-10-23T21:15:36.000Z (4 months ago)
- Last Synced: 2024-10-25T09:13:40.348Z (4 months ago)
- Topics: markdown, npm-package, parser, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@edllx/md-parser
- Size: 144 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## mdParser
Generate an
[Abstract Syntax Tree ](https://en.wikipedia.org/wiki/Abstract_syntax_tree) from
a Markdown file, providing a structured representation that you can manipulate
or render in various formats such as HTML, plain text, or any custom output.## Installation
```bash
npm install @edllx/md-parser
```## Features
| Name | | | |
| -------------- | -------- | ------------ | -------- |
| Heading | ✅ | Tables | ❌ |
| Unordered list | ✅ | Ordered list | ❌ |
| Bold | ✅ | Quotes | ❌ |
| Italic | ✅ | Unicode | ❌ |
| Links | ✅ | | |
| Inline code | ✅ | | |
| Code block | ✅ | | |## Usage
```ts
import { Factory, tokenize, Token } from '@edllx/md-parser';const tokens: Token[] = tokenize(`## Header2`);
const root: Token = Factory.ROOT(tokens);
```### Create and adapter
Here is an
[example](https://github.com/liolle/mdPreviewer/blob/main/src/components/preview/mdadapter.tsx)```ts
import {
Token,
TokenCompiler,
Word,
NewLine,
Paragraph,
LinkToken,
Heading,
ListToken,
Decoration,
InlineCode,
CodeToken,
CheckBoxToken,
} from '@edllx/md-parser';import { JSXElement } from 'solid-js';
/**
interface TokenCompiler {
compile: (token: Token) => T;
}
**/export class TokenToTsxAdapter implements TokenCompiler {
compile(token: Token) {
return this.#recursiveCompile(token);
}#recursiveCompile(token: Token): JSXElement {
switch (true) {
case token instanceof Word:
return TODO;case token instanceof NewLine:
return TODO;case token instanceof Paragraph:
return TODO;case token instanceof LinkToken:
return TODO;case token instanceof ListToken:
return TODO;case token instanceof Heading:
return TODO;case token instanceof Decoration:
return TODO;case token instanceof InlineCode:
return TODO;case token instanceof CodeToken:
return TODO;default:
return TODO;
}
}
}
```### use the adapter
```ts
import { Factory, tokenize, Token } from '@edllx/md-parser';
import { JSXElement } from 'solid-js';
import { TokenToTsxAdapter } from 'path-to-adapter';const compiler = new TokenToTsxAdapter();
const tokens: Token[] = tokenize(`## Header2`);
const root: Token = Factory.ROOT(tokens);
const component: JSXElement = compiler.compile(root);
```[Demo](https://md-viewer.kodevly.com/)