Compare commits

...

34 Commits

Author SHA1 Message Date
jkunz cd3b6d24fe v3.1.0 2026-05-01 21:57:01 +00:00
jkunz 84b4f355f8 feat(package): modernize package metadata, typings, and test setup for ESM builds 2026-05-01 21:57:01 +00:00
jkunz 2eae324908 chore: remove .gitlab-ci.yml 2026-03-01 18:56:59 +00:00
philkunz 4738e1e0e5 update description 2024-05-29 14:14:38 +02:00
philkunz 1d518b4f55 update tsconfig 2024-04-14 17:57:02 +02:00
philkunz 99718af936 update npmextra.json: githost 2024-04-01 21:36:29 +02:00
philkunz 7a02eeb0dd update npmextra.json: githost 2024-04-01 19:58:55 +02:00
philkunz 65ade5137b update npmextra.json: githost 2024-03-30 21:47:54 +01:00
philkunz dfd39b406a 3.0.3 2024-01-19 21:10:15 +01:00
philkunz 2c9515fb86 fix(core): update 2024-01-19 21:10:14 +01:00
philkunz cfa7807f8f 3.0.2 2024-01-19 21:09:28 +01:00
philkunz ba3210c7f5 fix(core): update 2024-01-19 21:09:27 +01:00
philkunz 91424492ba switch to new org scheme 2023-07-11 01:08:41 +02:00
philkunz d524a86921 switch to new org scheme 2023-07-10 10:16:25 +02:00
philkunz 6a1d91d5da 3.0.1 2022-06-26 20:45:40 +02:00
philkunz 035e8dc0cd fix(core): update 2022-06-26 20:45:40 +02:00
philkunz 57cadd079c 3.0.0 2022-05-28 21:05:37 +02:00
philkunz 0ead80750a BREAKING CHANGE(core): switch to esm 2022-05-28 21:05:37 +02:00
philkunz 3b2f8928de 2.0.14 2022-05-20 16:03:36 +02:00
philkunz 92a1b589e7 fix(core): update 2022-05-20 16:03:35 +02:00
philkunz 23f2cc9e6d 2.0.13 2022-05-19 13:42:28 +02:00
philkunz 813af0c232 fix(core): update 2022-05-19 13:42:28 +02:00
philkunz 16b21ff6bc 2.0.12 2022-05-19 09:37:00 +02:00
philkunz c42f3ee1b7 fix(core): update 2022-05-19 09:36:59 +02:00
philkunz dd1f8c928f 2.0.11 2021-10-04 13:55:00 +02:00
philkunz 75c62c01f5 fix(core): update 2021-10-04 13:54:59 +02:00
philkunz 6bd015e5bb 2.0.10 2021-10-04 13:43:40 +02:00
philkunz 97248d63db fix(core): update 2021-10-04 13:43:40 +02:00
philkunz e6ef461347 2.0.9 2021-10-04 13:39:56 +02:00
philkunz fd52655e63 fix(core): update 2021-10-04 13:39:56 +02:00
philkunz 9a8dd46cdb 2.0.8 2021-10-04 13:36:51 +02:00
philkunz d29d5dd07a fix(core): update 2021-10-04 13:36:51 +02:00
philkunz 8732b27445 2.0.7 2021-10-04 13:35:21 +02:00
philkunz 2a5013fb56 fix(core): update 2021-10-04 13:35:20 +02:00
21 changed files with 8772 additions and 12032 deletions
-137
View File
@@ -1,137 +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
# ====================
# 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
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 tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
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 @gitzone/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
+42
View File
@@ -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"
}
}
+3 -21
View File
@@ -2,28 +2,10 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "current file", "command": "npm test",
"type": "node", "name": "Run npm test",
"request": "launch", "request": "launch",
"args": [ "type": "node-terminal"
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
} }
] ]
} }
+50
View File
@@ -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.03.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.52.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.21.0.5
-3
View File
@@ -1,3 +0,0 @@
merge:
- ../gitignore
- ../ci_default
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2026 Task Venture Capital GmbH <hello@task.vc>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
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
SOFTWARE.
+33 -8
View File
@@ -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": "pushrocks", "gitscope": "push.rocks",
"gitrepo": "smartmarkdown", "gitrepo": "smartmarkdown",
"shortDescription": "do more with markdown files", "shortDescription": "Markdown parsing and conversion utilities",
"npmPackagename": "@pushrocks/smartmarkdown", "description": "Enhances Markdown file handling with parsing, conversion, and frontmatter support.",
"license": "MIT" "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"
} }
} }
-11764
View File
File diff suppressed because it is too large Load Diff
+47 -18
View File
@@ -1,31 +1,39 @@
{ {
"name": "@pushrocks/smartmarkdown", "name": "@push.rocks/smartmarkdown",
"version": "2.0.6", "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",
"author": "Lossless GmbH", "type": "module",
"author": "Task Venture Capital GmbH <hello@task.vc>",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "tstest test/", "test": "tstest test/",
"build": "tsbuild --web" "build": "tsbuild --web",
"buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.25", "@git.zone/tsbuild": "^4.4.0",
"@gitzone/tsrun": "^1.2.12", "@git.zone/tsdoc": "^2.0.3",
"@gitzone/tstest": "^1.0.52", "@git.zone/tstest": "^3.6.3",
"@pushrocks/tapbundle": "^3.2.14", "@types/mdast": "^4.0.4",
"@types/node": "^14.14.37", "@types/node": "^25.6.0"
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@types/marked": "^2.0.1", "@push.rocks/smartyaml": "^3.0.5",
"@types/turndown": "^5.0.0", "@types/turndown": "^5.0.6",
"marked": "^2.0.3", "remark-frontmatter": "^5.0.0",
"turndown": "^7.0.0", "remark-gfm": "^4.0.1",
"turndown-plugin-gfm": "^1.0.2" "remark-html": "^16.0.1",
"remark-parse": "^11.0.0",
"remark-stringify": "^11.0.0",
"turndown": "^7.2.4",
"turndown-plugin-gfm": "^1.0.2",
"unified": "^11.0.5"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@@ -36,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"
}
} }
+8234
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -0,0 +1 @@
+177 -30
View File
@@ -1,42 +1,189 @@
# @pushrocks/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/@pushrocks/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 | [![pipeline status](https://gitlab.com/pushrocks/smartmarkdown/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartmarkdown/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartmarkdown)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartmarkdown)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartmarkdown)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartmarkdown)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartmarkdown)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](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.
## Contribution ## Install
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). :) ```bash
pnpm add @push.rocks/smartmarkdown
```
## What It Does
## Contribution `@push.rocks/smartmarkdown` is intentionally focused:
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). :) - 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`.
For further information read the linked docs at the top of this readme. ## Quick Start
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh) ```typescript
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) import { SmartMarkdown } from '@push.rocks/smartmarkdown';
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com) 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.
+37
View File
@@ -0,0 +1,37 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as smartmarkdown from '../ts/index.js';
let smartMarkdownInstance: smartmarkdown.SmartMarkdown;
tap.test('should create a valid instance of SmartMarkdown', async () => {
smartMarkdownInstance = new smartmarkdown.SmartMarkdown();
expect(smartMarkdownInstance).toBeInstanceOf(smartmarkdown.SmartMarkdown);
});
tap.test('should convert a markdown string to html', async () => {
const markdownString = '# Hi!';
const mdParsedResult = await smartMarkdownInstance.getMdParsedResultFromMarkdown(markdownString);
const htmlString = mdParsedResult.html;
expect(htmlString).toEqual('<h1>Hi!</h1>\n');
});
tap.test('should get frontmatter', async () => {
const markdownString = `---
hello: yes
---
# hello there
`;
const mdParsedResult = await smartMarkdownInstance.getMdParsedResultFromMarkdown(markdownString);
expect(mdParsedResult.frontmatterData.hello).toEqual('yes');
});
tap.test('should convert a html string to markdown', async () => {
const htmlString = '<h1 id="hi">Hi!</h1>\n<h2>This is it!</h2>';
const markdownString = smartMarkdownInstance.htmlToMarkdown(htmlString);
expect(markdownString).toContain('# Hi!');
expect(markdownString).toContain('## This is it!');
});
export default tap.start();
-23
View File
@@ -1,23 +0,0 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartmarkdown from '../ts/index';
let smartMarkdownInstance: smartmarkdown.SmartMarkdown;
tap.test('should create a valid instance of SmartMarkdown', async () => {
smartMarkdownInstance = new smartmarkdown.SmartMarkdown();
expect(smartMarkdownInstance).to.be.instanceOf(smartmarkdown.SmartMarkdown);
});
tap.test('should convert a markdown string to html', async () => {
const markdownString = '# Hi!';
const htmlString = smartMarkdownInstance.markdownToHtml(markdownString);
expect(htmlString).to.equal('<h1 id="hi">Hi!</h1>\n');
});
tap.test('should convert a html string to markdown', async () => {
const htmlString = '<h1 id="hi">Hi!</h1>\n<h2>This is it!</h2>';
const markdownString = smartMarkdownInstance.htmlToMarkdown(htmlString);
console.log(markdownString);
});
tap.start();
+8
View File
@@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartmarkdown',
version: '3.1.0',
description: 'Enhances Markdown file handling with parsing, conversion, and frontmatter support.'
}
+14 -6
View File
@@ -1,17 +1,25 @@
import * as plugins from './smartmarkdown.plugins'; import * as plugins from './smartmarkdown.plugins.js';
import { MdParsedResult } from './smartmarkdown.classes.mdparsedresult.js';
export class SmartMarkdown { export class SmartMarkdown {
public static async easyMarkdownToHtml(mdStringArg: string) {
const smartmarkdownInstance = new SmartMarkdown();
const mdParsedResult = await smartmarkdownInstance.getMdParsedResultFromMarkdown(mdStringArg);
return mdParsedResult.html;
}
constructor() {} constructor() {}
/** /**
* converts markdown to html * create a MdParsedResult from markdown
* @param mdString * @param mdStringArg
*/ */
public markdownToHtml(mdString: string): string { public async getMdParsedResultFromMarkdown(mdStringArg: string): Promise<MdParsedResult> {
return plugins.marked(mdString); const result = await MdParsedResult.createFromMarkdownString(mdStringArg);
return result;
} }
public htmlToMarkdown(htmlString): string { public htmlToMarkdown(htmlString: string): string {
const turndownInstance = new plugins.turndown({ const turndownInstance = new plugins.turndown({
headingStyle: 'atx', headingStyle: 'atx',
codeBlockStyle: 'fenced', codeBlockStyle: 'fenced',
@@ -0,0 +1,49 @@
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 {
public static async createFromMarkdownString(mdStringArg: string): Promise<MdParsedResult> {
const mdParsedResult = new MdParsedResult();
await mdParsedResult.updateFromMarkdownString(mdStringArg);
return mdParsedResult;
}
public originalString = '';
public title = '';
public html = '';
public frontmatterData: TFrontmatterData = {};
public async updateFromMarkdownString(mdStringArg: string): Promise<void> {
this.originalString = mdStringArg;
let yamlString: string | undefined;
const result = await plugins.unified()
.use(plugins.remarkParse)
.use(plugins.remarkGfm)
.use(plugins.remarkFrontmatter, ['yaml', 'toml'])
.use(plugins.remarkStringify)
.use(plugins.remarkHtml)
.use((): plugins.Transformer<plugins.Root> => (tree) => {
const yamlChild = tree.children.find(isYamlNode);
if (yamlChild) {
yamlString = yamlChild.value;
}
})
.process(mdStringArg);
this.html = result.toString();
if (yamlString) {
this.frontmatterData = await plugins.smartyaml.yamlStringToObject(yamlString);
} else {
this.frontmatterData = {};
}
}
}
+35 -4
View File
@@ -1,5 +1,36 @@
import marked = require('marked'); /// <reference path="./smartmarkdown.types.d.ts" />
import turndown from 'turndown';
import * as turndownPluginGfm from 'turndown-plugin-gfm';
export { marked, turndown, turndownPluginGfm }; // pushrocks scope
import * as smartyaml from '@push.rocks/smartyaml';
export {
smartyaml
};
// third party remark
import { unified } from 'unified';
import type { Plugin, Transformer } from 'unified';
import type { Root, RootContent } from 'mdast';
import remarkGfm from 'remark-gfm';
import remarkParse from 'remark-parse';
import remarkFrontmatter from 'remark-frontmatter';
import remarkHtml from 'remark-html';
import remarkStringify from 'remark-stringify';
export { unified, remarkGfm, remarkParse, remarkFrontmatter, remarkHtml, remarkStringify };
export type { Plugin, Transformer, Root, RootContent };
// other third party stuff
import turndown from 'turndown';
import * as rawTurndownPluginGfm 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 };
+6
View File
@@ -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;
}
+16
View File
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noImplicitAny": true,
"esModuleInterop": true,
"verbatimModuleSyntax": true,
"types": ["node"]
},
"exclude": [
"dist_*/**/*.d.ts"
]
}
-17
View File
@@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}