feat(package): modernize package metadata, typings, and test setup for ESM builds
This commit is contained in:
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"@ship.zone/szci": {
|
||||||
|
"npmGlobalTools": [],
|
||||||
|
"npmRegistryUrl": "registry.npmjs.org"
|
||||||
|
},
|
||||||
|
"@git.zone/cli": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "code.foss.global",
|
||||||
|
"gitscope": "push.rocks",
|
||||||
|
"gitrepo": "smartmarkdown",
|
||||||
|
"shortDescription": "Markdown parsing and conversion utilities",
|
||||||
|
"description": "Enhances Markdown file handling with parsing, conversion, and frontmatter support.",
|
||||||
|
"npmPackagename": "@push.rocks/smartmarkdown",
|
||||||
|
"license": "MIT",
|
||||||
|
"keywords": [
|
||||||
|
"markdown",
|
||||||
|
"html conversion",
|
||||||
|
"markdown parsing",
|
||||||
|
"frontmatter",
|
||||||
|
"remark",
|
||||||
|
"unified",
|
||||||
|
"turndown",
|
||||||
|
"YAML",
|
||||||
|
"plugin system",
|
||||||
|
"text processing",
|
||||||
|
"documentation",
|
||||||
|
"content management"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"release": {
|
||||||
|
"registries": [
|
||||||
|
"https://verdaccio.lossless.digital",
|
||||||
|
"https://registry.npmjs.org"
|
||||||
|
],
|
||||||
|
"accessLevel": "public"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@git.zone/tsdoc": {
|
||||||
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.\n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.\n\nUse of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District Court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-05-01 - 3.1.0 - feat(package)
|
||||||
|
modernize package metadata, typings, and test setup for ESM builds
|
||||||
|
|
||||||
|
- add an explicit package exports entry and include additional published config files
|
||||||
|
- upgrade build and test tooling dependencies and add documentation generation script
|
||||||
|
- improve TypeScript safety for frontmatter parsing and turndown GFM plugin typings
|
||||||
|
- refresh README usage examples and strengthen HTML-to-Markdown test assertions
|
||||||
|
|
||||||
|
## 2026-03-01 - 3.0.3 - maintenance
|
||||||
|
Project maintenance and repository metadata updates across the 3.0.3 release line.
|
||||||
|
|
||||||
|
- Removed the legacy `.gitlab-ci.yml` configuration
|
||||||
|
- Updated project description
|
||||||
|
- Updated TypeScript configuration
|
||||||
|
- Refreshed `npmextra.json` git host metadata
|
||||||
|
|
||||||
|
## 2024-01-19 - 3.0.2 - core
|
||||||
|
Core update release.
|
||||||
|
|
||||||
|
- Applied a core fix/update
|
||||||
|
|
||||||
|
## 2023-07-10 - 3.0.1 - project
|
||||||
|
Project organization updates during the 3.0.1 release cycle.
|
||||||
|
|
||||||
|
- Switched to the new organization scheme
|
||||||
|
- Included a core fix/update in the 3.0.0–3.0.1 range
|
||||||
|
|
||||||
|
## 2022-05-28 - 3.0.0 - core
|
||||||
|
Breaking core modernization release.
|
||||||
|
|
||||||
|
- BREAKING CHANGE: switched the project to ESM
|
||||||
|
|
||||||
|
## 2022-05-19 - 2.0.11 - core
|
||||||
|
Routine maintenance updates across versions 2.0.5 through 2.0.14.
|
||||||
|
|
||||||
|
- Applied repeated core fix/update releases for versions 2.0.5–2.0.14
|
||||||
|
|
||||||
|
## 2019-06-17 - 2.0.0 - core
|
||||||
|
Major core redesign release.
|
||||||
|
|
||||||
|
- BREAKING CHANGE: switched to a class-based design
|
||||||
|
- Added support for HTML to Markdown conversion
|
||||||
|
|
||||||
|
## 2018-09-22 - 1.0.1 - core
|
||||||
|
Initial stable release series.
|
||||||
|
|
||||||
|
- Initial core implementation
|
||||||
|
- Followed by routine core fix/update releases in versions 1.0.2–1.0.5
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2014 Lossless GmbH (hello@lossless.com)
|
Copyright (c) 2026 Task Venture Capital GmbH <hello@task.vc>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|||||||
+14
-6
@@ -1,14 +1,15 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"@ship.zone/szci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmRegistryUrl": "registry.npmjs.org"
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"@git.zone/cli": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "code.foss.global",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "push.rocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartmarkdown",
|
"gitrepo": "smartmarkdown",
|
||||||
|
"shortDescription": "Markdown parsing and conversion utilities",
|
||||||
"description": "Enhances Markdown file handling with parsing, conversion, and frontmatter support.",
|
"description": "Enhances Markdown file handling with parsing, conversion, and frontmatter support.",
|
||||||
"npmPackagename": "@push.rocks/smartmarkdown",
|
"npmPackagename": "@push.rocks/smartmarkdown",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -26,9 +27,16 @@
|
|||||||
"documentation",
|
"documentation",
|
||||||
"content management"
|
"content management"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"release": {
|
||||||
|
"registries": [
|
||||||
|
"https://verdaccio.lossless.digital",
|
||||||
|
"https://registry.npmjs.org"
|
||||||
|
],
|
||||||
|
"accessLevel": "public"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tsdoc": {
|
"@git.zone/tsdoc": {
|
||||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.\n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.\n\nUse of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District Court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
-13034
File diff suppressed because it is too large
Load Diff
+19
-13
@@ -3,33 +3,37 @@
|
|||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "Enhances Markdown file handling with parsing, conversion, and frontmatter support.",
|
"description": "Enhances Markdown file handling with parsing, conversion, and frontmatter support.",
|
||||||
|
"exports": {
|
||||||
|
".": "./dist_ts/index.js"
|
||||||
|
},
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Task Venture Capital GmbH <hello@task.vc>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tstest test/",
|
"test": "tstest test/",
|
||||||
"build": "tsbuild --web --allowimplicitany"
|
"build": "tsbuild --web",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.1.61",
|
"@git.zone/tsbuild": "^4.4.0",
|
||||||
"@git.zone/tsrun": "^1.2.37",
|
"@git.zone/tsdoc": "^2.0.3",
|
||||||
"@git.zone/tstest": "^1.0.86",
|
"@git.zone/tstest": "^3.6.3",
|
||||||
"@push.rocks/tapbundle": "^5.0.3",
|
"@types/mdast": "^4.0.4",
|
||||||
"@types/node": "^20.11.5"
|
"@types/node": "^25.6.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/smartyaml": "^2.0.5",
|
"@push.rocks/smartyaml": "^3.0.5",
|
||||||
"@types/turndown": "^5.0.1",
|
"@types/turndown": "^5.0.6",
|
||||||
"remark-frontmatter": "^5.0.0",
|
"remark-frontmatter": "^5.0.0",
|
||||||
"remark-gfm": "^4.0.0",
|
"remark-gfm": "^4.0.1",
|
||||||
"remark-html": "^16.0.1",
|
"remark-html": "^16.0.1",
|
||||||
"remark-parse": "^11.0.0",
|
"remark-parse": "^11.0.0",
|
||||||
"remark-stringify": "^11.0.0",
|
"remark-stringify": "^11.0.0",
|
||||||
"turndown": "^7.1.1",
|
"turndown": "^7.2.4",
|
||||||
"turndown-plugin-gfm": "^1.0.2",
|
"turndown-plugin-gfm": "^1.0.2",
|
||||||
"unified": "^11.0.4"
|
"unified": "^11.0.5"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
@@ -40,6 +44,8 @@
|
|||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
|
".smartconfig.json",
|
||||||
|
"license",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
],
|
||||||
@@ -65,4 +71,4 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://code.foss.global/push.rocks/smartmarkdown.git"
|
"url": "https://code.foss.global/push.rocks/smartmarkdown.git"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+7307
-5831
File diff suppressed because it is too large
Load Diff
@@ -1,129 +1,189 @@
|
|||||||
# @push.rocks/smartmarkdown
|
# @push.rocks/smartmarkdown
|
||||||
do more with markdown files
|
|
||||||
|
Markdown utilities for modern TypeScript projects: parse Markdown into HTML, read YAML frontmatter, and convert HTML back into clean GitHub-flavored Markdown.
|
||||||
|
|
||||||
|
`@push.rocks/smartmarkdown` wraps the Unified/Remark ecosystem for Markdown parsing and the Turndown ecosystem for HTML-to-Markdown conversion behind a small, typed API that works in Node.js and browser-oriented ESM builds.
|
||||||
|
|
||||||
|
## Issue Reporting and Security
|
||||||
|
|
||||||
|
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
To install `@push.rocks/smartmarkdown`, you can use npm or yarn. Run one of the following commands in your terminal:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install @push.rocks/smartmarkdown --save
|
pnpm add @push.rocks/smartmarkdown
|
||||||
```
|
```
|
||||||
|
|
||||||
or if you use yarn:
|
## What It Does
|
||||||
|
|
||||||
```bash
|
`@push.rocks/smartmarkdown` is intentionally focused:
|
||||||
yarn add @push.rocks/smartmarkdown
|
|
||||||
```
|
|
||||||
|
|
||||||
This module is designed to be used in a Node.js environment or in a frontend project that supports ES Modules.
|
- Convert Markdown strings to HTML.
|
||||||
|
- Parse YAML frontmatter into a JavaScript object.
|
||||||
|
- Preserve access to the original Markdown source.
|
||||||
|
- Convert HTML strings back to Markdown using ATX headings and fenced code blocks.
|
||||||
|
- Support GitHub-flavored Markdown through `remark-gfm` and `turndown-plugin-gfm`.
|
||||||
|
|
||||||
## Usage
|
## Quick Start
|
||||||
`@push.rocks/smartmarkdown` offers powerful tools to work with markdown files, including parsing markdown to HTML, extracting frontmatter data, and converting HTML back to markdown. Below, we'll explore how to utilize these features effectively.
|
|
||||||
|
|
||||||
### **Parsing Markdown to HTML**
|
|
||||||
|
|
||||||
Let's start by converting a simple Markdown string to HTML:
|
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
||||||
|
|
||||||
async function parseMarkdown() {
|
const html = await SmartMarkdown.easyMarkdownToHtml(`# Hello Markdown
|
||||||
const mdString = `# Hello World
|
|
||||||
|
|
||||||
This is a simple markdown string.`;
|
|
||||||
const htmlString = await SmartMarkdown.easyMarkdownToHtml(mdString);
|
|
||||||
console.log(htmlString); // Logs the HTML string
|
|
||||||
}
|
|
||||||
|
|
||||||
parseMarkdown();
|
- fast
|
||||||
|
- typed
|
||||||
|
- practical
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log(html);
|
||||||
|
// <h1>Hello Markdown</h1>
|
||||||
|
// <ul>
|
||||||
|
// <li>fast</li>
|
||||||
|
// <li>typed</li>
|
||||||
|
// <li>practical</li>
|
||||||
|
// </ul>
|
||||||
```
|
```
|
||||||
|
|
||||||
In this example, `SmartMarkdown.easyMarkdownToHtml` is a convenient static method that takes a markdown string and returns its HTML representation.
|
## API
|
||||||
|
|
||||||
### **Working with Frontmatter**
|
### `SmartMarkdown.easyMarkdownToHtml(markdown)`
|
||||||
|
|
||||||
Markdown files often contain frontmatter, which is metadata specified at the top of the file. `@push.rocks/smartmarkdown` can extract this data along with converting the content.
|
Static convenience method for the most common path: Markdown in, HTML out.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
||||||
|
|
||||||
async function parseMarkdownWithFrontmatter() {
|
const html = await SmartMarkdown.easyMarkdownToHtml('# Hi!');
|
||||||
const markdownWithFrontmatter = `---
|
|
||||||
title: "My First Post"
|
console.log(html);
|
||||||
date: 2023-01-01
|
// <h1>Hi!</h1>
|
||||||
tags: ["blog", "post"]
|
```
|
||||||
|
|
||||||
|
### `new SmartMarkdown().getMdParsedResultFromMarkdown(markdown)`
|
||||||
|
|
||||||
|
Parses a Markdown string into an `MdParsedResult` instance.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
||||||
|
|
||||||
|
const smartMarkdown = new SmartMarkdown();
|
||||||
|
|
||||||
|
const result = await smartMarkdown.getMdParsedResultFromMarkdown(`---
|
||||||
|
title: Smart Docs
|
||||||
|
published: true
|
||||||
|
tags:
|
||||||
|
- markdown
|
||||||
|
- docs
|
||||||
---
|
---
|
||||||
|
|
||||||
# Hello World
|
|
||||||
|
|
||||||
This is a post with frontmatter.`;
|
|
||||||
|
|
||||||
const smartmarkdownInstance = new SmartMarkdown();
|
|
||||||
const mdParsedResult = await smartmarkdownInstance.getMdParsedResultFromMarkdown(markdownWithFrontmatter);
|
|
||||||
console.log(mdParsedResult.frontmatterData); // Logs: { title: "My First Post", date: "2023-01-01", tags: ["blog", "post"] }
|
|
||||||
console.log(mdParsedResult.html); // Logs: HTML content
|
|
||||||
}
|
|
||||||
|
|
||||||
parseMarkdownWithFrontmatter();
|
# Smart Docs
|
||||||
|
|
||||||
|
Markdown with metadata.
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log(result.originalString); // the original Markdown input
|
||||||
|
console.log(result.html); // rendered HTML
|
||||||
|
console.log(result.frontmatterData); // { title: 'Smart Docs', published: true, tags: ['markdown', 'docs'] }
|
||||||
```
|
```
|
||||||
|
|
||||||
In the code above, we manually create an instance of `SmartMarkdown` to access the `getMdParsedResultFromMarkdown` method, which returns an object containing both the HTML and the frontmatter data.
|
The returned object exposes:
|
||||||
|
|
||||||
### **HTML to Markdown Conversion**
|
- `originalString`: the Markdown input string.
|
||||||
|
- `html`: the rendered HTML output.
|
||||||
|
- `frontmatterData`: parsed YAML frontmatter as `Record<string, unknown>`.
|
||||||
|
- `title`: currently initialized as an empty string for consumers that want to attach title metadata.
|
||||||
|
|
||||||
Sometimes, you may need to convert HTML back to Markdown. Here's how you can do it:
|
### `new SmartMarkdown().htmlToMarkdown(html)`
|
||||||
|
|
||||||
|
Converts HTML back to Markdown using Turndown with GitHub-flavored Markdown support.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
||||||
|
|
||||||
const smartmarkdownInstance = new SmartMarkdown();
|
const smartMarkdown = new SmartMarkdown();
|
||||||
const htmlString = '<h1>Hello World</h1><p>This is a simple HTML string.</p>';
|
|
||||||
const markdownString = smartmarkdownInstance.htmlToMarkdown(htmlString);
|
const markdown = smartMarkdown.htmlToMarkdown(`
|
||||||
console.log(markdownString);
|
<h1 id="hello">Hello</h1>
|
||||||
|
<p>This came from HTML.</p>
|
||||||
|
<ul>
|
||||||
|
<li>tables, strikethrough, and task lists are handled through GFM support</li>
|
||||||
|
</ul>
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log(markdown);
|
||||||
|
// # Hello
|
||||||
|
//
|
||||||
|
// This came from HTML.
|
||||||
```
|
```
|
||||||
|
|
||||||
In this example, we use the `htmlToMarkdown` method to convert an HTML string back to Markdown. This is particularly useful when working with content editing interfaces that support both formats.
|
## Frontmatter
|
||||||
|
|
||||||
### **Advanced Usage: Parsing Markdown with Custom Plugins**
|
Frontmatter is detected with `remark-frontmatter` and parsed through `@push.rocks/smartyaml`.
|
||||||
|
|
||||||
`@push.rocks/smartmarkdown` leverages Unified, Remark, and Turndown to provide its functionality. You can extend its capabilities by using custom plugins.
|
|
||||||
|
|
||||||
For instance, if you wanted to use a custom Remark plugin to highlight code blocks, you would:
|
|
||||||
|
|
||||||
1. Create a new SmartMarkdown instance.
|
|
||||||
2. Configure it to use your custom plugins.
|
|
||||||
3. Process your markdown content.
|
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// This is a hypothetical example. Please refer to the respective plugin documentation for actual implementation details.
|
|
||||||
|
|
||||||
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
||||||
import myRemarkPlugin from 'remark-myplugin';
|
|
||||||
|
|
||||||
async function parseMarkdownWithPlugin(mdString: string) {
|
const smartMarkdown = new SmartMarkdown();
|
||||||
const smartMarkdownInstance = new SmartMarkdown();
|
|
||||||
smartMarkdownInstance.useRemarkPlugin(myRemarkPlugin, pluginOptions);
|
const result = await smartMarkdown.getMdParsedResultFromMarkdown(`---
|
||||||
const result = await smartMarkdownInstance.getMdParsedResultFromMarkdown(mdString);
|
layout: guide
|
||||||
// Now `result` will include transformations done by your custom plugin.
|
draft: false
|
||||||
}
|
order: 10
|
||||||
|
---
|
||||||
|
|
||||||
|
# Guide
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log(result.frontmatterData.layout); // 'guide'
|
||||||
|
console.log(result.frontmatterData.draft); // false
|
||||||
|
console.log(result.frontmatterData.order); // 10
|
||||||
```
|
```
|
||||||
|
|
||||||
`@push.rocks/smartmarkdown` provides a solid base for performing various markdown related tasks in your projects. Whether parsing, transforming, or exporting content, its utilities and integrations offer flexibility for most needs. By leveraging ES Modules and TypeScript, it ensures type safety and enhances developer experience with excellent IntelliSense support.
|
If no frontmatter block is present, `frontmatterData` is an empty object.
|
||||||
|
|
||||||
|
## Markdown Features
|
||||||
|
|
||||||
|
Markdown parsing uses:
|
||||||
|
|
||||||
|
- `remark-parse` for Markdown parsing.
|
||||||
|
- `remark-gfm` for GitHub-flavored Markdown.
|
||||||
|
- `remark-frontmatter` for YAML/TOML frontmatter detection.
|
||||||
|
- `remark-html` for HTML output.
|
||||||
|
|
||||||
|
HTML-to-Markdown conversion uses:
|
||||||
|
|
||||||
|
- `turndown` with `headingStyle: 'atx'`.
|
||||||
|
- `turndown` with `codeBlockStyle: 'fenced'`.
|
||||||
|
- `turndown-plugin-gfm` for GitHub-flavored Markdown output.
|
||||||
|
|
||||||
|
## TypeScript and ESM
|
||||||
|
|
||||||
|
This package ships as an ES module and includes TypeScript declarations.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
||||||
|
```
|
||||||
|
|
||||||
|
The package export points to the built ESM entrypoint and is ready for TypeScript, Node.js ESM, and bundler-based frontend projects.
|
||||||
|
|
||||||
## License and Legal Information
|
## License and Legal Information
|
||||||
|
|
||||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
|
||||||
|
|
||||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
### Trademarks
|
### Trademarks
|
||||||
|
|
||||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
|
||||||
|
|
||||||
|
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
|
||||||
|
|
||||||
### Company Information
|
### Company Information
|
||||||
|
|
||||||
Task Venture Capital GmbH
|
Task Venture Capital GmbH
|
||||||
Registered at District court Bremen HRB 35230 HB, Germany
|
Registered at District Court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||||
|
|||||||
+5
-5
@@ -1,4 +1,4 @@
|
|||||||
import { expect, tap } from '@push.rocks/tapbundle';
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
import * as smartmarkdown from '../ts/index.js';
|
import * as smartmarkdown from '../ts/index.js';
|
||||||
|
|
||||||
let smartMarkdownInstance: smartmarkdown.SmartMarkdown;
|
let smartMarkdownInstance: smartmarkdown.SmartMarkdown;
|
||||||
@@ -23,15 +23,15 @@ hello: yes
|
|||||||
# hello there
|
# hello there
|
||||||
`;
|
`;
|
||||||
const mdParsedResult = await smartMarkdownInstance.getMdParsedResultFromMarkdown(markdownString);
|
const mdParsedResult = await smartMarkdownInstance.getMdParsedResultFromMarkdown(markdownString);
|
||||||
|
|
||||||
expect(mdParsedResult.frontmatterData.hello).toEqual('yes');
|
expect(mdParsedResult.frontmatterData.hello).toEqual('yes');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should convert a html string to markdown', async () => {
|
tap.test('should convert a html string to markdown', async () => {
|
||||||
const htmlString = '<h1 id="hi">Hi!</h1>\n<h2>This is it!</h2>';
|
const htmlString = '<h1 id="hi">Hi!</h1>\n<h2>This is it!</h2>';
|
||||||
const markdownString = smartMarkdownInstance.htmlToMarkdown(htmlString);
|
const markdownString = smartMarkdownInstance.htmlToMarkdown(htmlString);
|
||||||
console.log(markdownString);
|
expect(markdownString).toContain('# Hi!');
|
||||||
|
expect(markdownString).toContain('## This is it!');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
export default tap.start();
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartmarkdown',
|
name: '@push.rocks/smartmarkdown',
|
||||||
version: '3.0.3',
|
version: '3.1.0',
|
||||||
description: 'do more with markdown files'
|
description: 'Enhances Markdown file handling with parsing, conversion, and frontmatter support.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
import * as plugins from './smartmarkdown.plugins.js';
|
import * as plugins from './smartmarkdown.plugins.js';
|
||||||
|
|
||||||
|
export type TFrontmatterData = Record<string, unknown>;
|
||||||
|
|
||||||
|
type TYamlNode = plugins.RootContent & {
|
||||||
|
type: 'yaml';
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const isYamlNode = (nodeArg: plugins.RootContent): nodeArg is TYamlNode => {
|
||||||
|
return nodeArg.type === 'yaml' && 'value' in nodeArg && typeof nodeArg.value === 'string';
|
||||||
|
};
|
||||||
|
|
||||||
export class MdParsedResult {
|
export class MdParsedResult {
|
||||||
public static async createFromMarkdownString(mdStringArg: string): Promise<MdParsedResult> {
|
public static async createFromMarkdownString(mdStringArg: string): Promise<MdParsedResult> {
|
||||||
const mdParsedResult = new MdParsedResult();
|
const mdParsedResult = new MdParsedResult();
|
||||||
@@ -7,24 +18,24 @@ export class MdParsedResult {
|
|||||||
return mdParsedResult;
|
return mdParsedResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public originalString: string;
|
public originalString = '';
|
||||||
public title: string;
|
public title = '';
|
||||||
public html: string;
|
public html = '';
|
||||||
public frontmatterData: {[key: string]: any};
|
public frontmatterData: TFrontmatterData = {};
|
||||||
|
|
||||||
public async updateFromMarkdownString(mdStringArg: string) {
|
public async updateFromMarkdownString(mdStringArg: string): Promise<void> {
|
||||||
let yamlString: string;
|
this.originalString = mdStringArg;
|
||||||
|
let yamlString: string | undefined;
|
||||||
const result = await plugins.unified()
|
const result = await plugins.unified()
|
||||||
.use(plugins.remarkParse)
|
.use(plugins.remarkParse)
|
||||||
.use(plugins.remarkGfm)
|
.use(plugins.remarkGfm)
|
||||||
.use(plugins.remarkFrontmatter, ['yaml', 'toml'])
|
.use(plugins.remarkFrontmatter, ['yaml', 'toml'])
|
||||||
.use(plugins.remarkStringify)
|
.use(plugins.remarkStringify)
|
||||||
.use(plugins.remarkHtml)
|
.use(plugins.remarkHtml)
|
||||||
.use(() => (tree) => {
|
.use((): plugins.Transformer<plugins.Root> => (tree) => {
|
||||||
console.dir(tree);
|
const yamlChild = tree.children.find(isYamlNode);
|
||||||
const yamlChild = tree.children.find(objectArg => objectArg.type === 'yaml');
|
|
||||||
if (yamlChild) {
|
if (yamlChild) {
|
||||||
yamlString = (yamlChild as any).value;
|
yamlString = yamlChild.value;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.process(mdStringArg);
|
.process(mdStringArg);
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
|
/// <reference path="./smartmarkdown.types.d.ts" />
|
||||||
|
|
||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
import * as smartyaml from '@push.rocks/smartyaml';
|
import * as smartyaml from '@push.rocks/smartyaml';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
smartyaml
|
smartyaml
|
||||||
}
|
};
|
||||||
|
|
||||||
// third party remark
|
// third party remark
|
||||||
import { unified } from 'unified';
|
import { unified } from 'unified';
|
||||||
|
import type { Plugin, Transformer } from 'unified';
|
||||||
|
import type { Root, RootContent } from 'mdast';
|
||||||
import remarkGfm from 'remark-gfm';
|
import remarkGfm from 'remark-gfm';
|
||||||
import remarkParse from 'remark-parse';
|
import remarkParse from 'remark-parse';
|
||||||
import remarkFrontmatter from 'remark-frontmatter';
|
import remarkFrontmatter from 'remark-frontmatter';
|
||||||
@@ -14,10 +18,19 @@ import remarkHtml from 'remark-html';
|
|||||||
import remarkStringify from 'remark-stringify';
|
import remarkStringify from 'remark-stringify';
|
||||||
|
|
||||||
export { unified, remarkGfm, remarkParse, remarkFrontmatter, remarkHtml, remarkStringify };
|
export { unified, remarkGfm, remarkParse, remarkFrontmatter, remarkHtml, remarkStringify };
|
||||||
|
export type { Plugin, Transformer, Root, RootContent };
|
||||||
|
|
||||||
// other third party stuff
|
// other third party stuff
|
||||||
import turndown from 'turndown';
|
import turndown from 'turndown';
|
||||||
// @ts-ignore
|
import * as rawTurndownPluginGfm from 'turndown-plugin-gfm';
|
||||||
import * as turndownPluginGfm from 'turndown-plugin-gfm';
|
|
||||||
|
type TTurndownPlugin = (serviceArg: InstanceType<typeof turndown>) => void;
|
||||||
|
|
||||||
|
const turndownPluginGfm = rawTurndownPluginGfm as {
|
||||||
|
gfm: TTurndownPlugin;
|
||||||
|
strikethrough: TTurndownPlugin;
|
||||||
|
tables: TTurndownPlugin;
|
||||||
|
taskListItems: TTurndownPlugin;
|
||||||
|
};
|
||||||
|
|
||||||
export { turndown, turndownPluginGfm };
|
export { turndown, turndownPluginGfm };
|
||||||
|
|||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
declare module 'turndown-plugin-gfm' {
|
||||||
|
export const gfm: unknown;
|
||||||
|
export const strikethrough: unknown;
|
||||||
|
export const tables: unknown;
|
||||||
|
export const taskListItems: unknown;
|
||||||
|
}
|
||||||
+3
-1
@@ -5,8 +5,10 @@
|
|||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "NodeNext",
|
"moduleResolution": "NodeNext",
|
||||||
|
"noImplicitAny": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"verbatimModuleSyntax": true
|
"verbatimModuleSyntax": true,
|
||||||
|
"types": ["node"]
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"dist_*/**/*.d.ts"
|
"dist_*/**/*.d.ts"
|
||||||
|
|||||||
Reference in New Issue
Block a user