Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cd3b6d24fe | |||
| 84b4f355f8 | |||
| 2eae324908 | |||
| 4738e1e0e5 | |||
| 1d518b4f55 | |||
| 99718af936 | |||
| 7a02eeb0dd | |||
| 65ade5137b |
-140
@@ -1,140 +0,0 @@
|
|||||||
# gitzone ci_default
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: '$CI_BUILD_STAGE'
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- npm install -g @shipzone/npmci
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
auditProductionDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --production --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
auditDevDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command npm audit --audit-level=high --only=dev
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testStable:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testBuild:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run build
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
allow_failure: true
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g typescript
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci command npm install -g @git.zone/tsdoc
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command tsdoc
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
||||||
@@ -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
|
||||||
|
|||||||
+31
-6
@@ -1,17 +1,42 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"@ship.zone/szci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmRegistryUrl": "registry.npmjs.org"
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"@git.zone/cli": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "push.rocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartmarkdown",
|
"gitrepo": "smartmarkdown",
|
||||||
"description": "do more with markdown files",
|
"shortDescription": "Markdown parsing and conversion utilities",
|
||||||
|
"description": "Enhances Markdown file handling with parsing, conversion, and frontmatter support.",
|
||||||
"npmPackagename": "@push.rocks/smartmarkdown",
|
"npmPackagename": "@push.rocks/smartmarkdown",
|
||||||
"license": "MIT"
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Generated
-13034
File diff suppressed because it is too large
Load Diff
+40
-15
@@ -1,35 +1,39 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartmarkdown",
|
"name": "@push.rocks/smartmarkdown",
|
||||||
"version": "3.0.3",
|
"version": "3.1.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "do more with markdown files",
|
"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,10 +44,31 @@
|
|||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
|
".smartconfig.json",
|
||||||
|
"license",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
],
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
]
|
],
|
||||||
|
"keywords": [
|
||||||
|
"markdown",
|
||||||
|
"html conversion",
|
||||||
|
"markdown parsing",
|
||||||
|
"frontmatter",
|
||||||
|
"remark",
|
||||||
|
"unified",
|
||||||
|
"turndown",
|
||||||
|
"YAML",
|
||||||
|
"plugin system",
|
||||||
|
"text processing",
|
||||||
|
"documentation",
|
||||||
|
"content management"
|
||||||
|
],
|
||||||
|
"homepage": "https://code.foss.global/push.rocks/smartmarkdown",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://code.foss.global/push.rocks/smartmarkdown.git"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+7307
-5831
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
@@ -1,39 +1,189 @@
|
|||||||
# @push.rocks/smartmarkdown
|
# @push.rocks/smartmarkdown
|
||||||
do more with markdown files
|
|
||||||
|
|
||||||
## Availabililty and Links
|
Markdown utilities for modern TypeScript projects: parse Markdown into HTML, read YAML frontmatter, and convert HTML back into clean GitHub-flavored Markdown.
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartmarkdown)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartmarkdown)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartmarkdown)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartmarkdown/)
|
|
||||||
|
|
||||||
## Status for master
|
`@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.
|
||||||
|
|
||||||
Status Category | Status Badge
|
## Issue Reporting and Security
|
||||||
-- | --
|
|
||||||
GitLab Pipelines | [](https://lossless.cloud)
|
|
||||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
|
||||||
npm | [](https://lossless.cloud)
|
|
||||||
Snyk | [](https://lossless.cloud)
|
|
||||||
TypeScript Support | [](https://lossless.cloud)
|
|
||||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
Code Style | [](https://lossless.cloud)
|
|
||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
|
||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
|
||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
|
||||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
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.
|
||||||
|
|
||||||
Use TypeScript for best in class intellisense.
|
## Install
|
||||||
|
|
||||||
## Contribution
|
```bash
|
||||||
|
pnpm add @push.rocks/smartmarkdown
|
||||||
|
```
|
||||||
|
|
||||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
## What It Does
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
`@push.rocks/smartmarkdown` is intentionally focused:
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
- Convert Markdown strings to HTML.
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
- 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`.
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
## Quick Start
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
||||||
|
|
||||||
|
const html = await SmartMarkdown.easyMarkdownToHtml(`# Hello Markdown
|
||||||
|
|
||||||
|
- fast
|
||||||
|
- typed
|
||||||
|
- practical
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log(html);
|
||||||
|
// <h1>Hello Markdown</h1>
|
||||||
|
// <ul>
|
||||||
|
// <li>fast</li>
|
||||||
|
// <li>typed</li>
|
||||||
|
// <li>practical</li>
|
||||||
|
// </ul>
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### `SmartMarkdown.easyMarkdownToHtml(markdown)`
|
||||||
|
|
||||||
|
Static convenience method for the most common path: Markdown in, HTML out.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
||||||
|
|
||||||
|
const html = await SmartMarkdown.easyMarkdownToHtml('# Hi!');
|
||||||
|
|
||||||
|
console.log(html);
|
||||||
|
// <h1>Hi!</h1>
|
||||||
|
```
|
||||||
|
|
||||||
|
### `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
|
||||||
|
---
|
||||||
|
|
||||||
|
# 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'] }
|
||||||
|
```
|
||||||
|
|
||||||
|
The returned object exposes:
|
||||||
|
|
||||||
|
- `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.
|
||||||
|
|
||||||
|
### `new SmartMarkdown().htmlToMarkdown(html)`
|
||||||
|
|
||||||
|
Converts HTML back to Markdown using Turndown with GitHub-flavored Markdown support.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
||||||
|
|
||||||
|
const smartMarkdown = new SmartMarkdown();
|
||||||
|
|
||||||
|
const markdown = smartMarkdown.htmlToMarkdown(`
|
||||||
|
<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.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Frontmatter
|
||||||
|
|
||||||
|
Frontmatter is detected with `remark-frontmatter` and parsed through `@push.rocks/smartyaml`.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { SmartMarkdown } from '@push.rocks/smartmarkdown';
|
||||||
|
|
||||||
|
const smartMarkdown = new SmartMarkdown();
|
||||||
|
|
||||||
|
const result = await smartMarkdown.getMdParsedResultFromMarkdown(`---
|
||||||
|
layout: guide
|
||||||
|
draft: false
|
||||||
|
order: 10
|
||||||
|
---
|
||||||
|
|
||||||
|
# Guide
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log(result.frontmatterData.layout); // 'guide'
|
||||||
|
console.log(result.frontmatterData.draft); // false
|
||||||
|
console.log(result.frontmatterData.order); // 10
|
||||||
|
```
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
### 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 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
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District Court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
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.
|
||||||
|
|||||||
+4
-4
@@ -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;
|
||||||
@@ -25,13 +25,13 @@ hello: yes
|
|||||||
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