Compare commits

...

38 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
philkunz 64b50eeb1c 2.0.6 2021-04-12 09:20:28 +00:00
philkunz 7f1777e38b fix(core): update 2021-04-12 09:20:28 +00:00
philkunz 5654e6ed72 2.0.5 2020-01-18 16:55:30 +00:00
philkunz b3047fed9a fix(core): update 2020-01-18 16:55:29 +00:00
23 changed files with 8809 additions and 2512 deletions
+1 -3
View File
@@ -15,8 +15,6 @@ node_modules/
# builds # builds
dist/ dist/
dist_web/ dist_*/
dist_serve/
dist_ts_web/
# custom # custom
-117
View File
@@ -1,117 +0,0 @@
# gitzone ci_default
image: 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
tags:
- docker
- notpriv
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
# ====================
# test stage
# ====================
testLTS:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- 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"
}
}
+11
View File
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}
+26
View File
@@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}
+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
+1 -3
View File
@@ -1,6 +1,4 @@
The MIT License (MIT) Copyright (c) 2026 Task Venture Capital GmbH <hello@task.vc>
Copyright (c) 2016 Push.Rocks
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
+35 -9
View File
@@ -1,16 +1,42 @@
{ {
"npmci": { "@ship.zone/szci": {
"npmGlobalTools": [], "npmGlobalTools": [],
"npmAccessLevel": "public" "npmRegistryUrl": "registry.npmjs.org"
}, },
"gitzone": { "@git.zone/cli": {
"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"
} }
} }
-2281
View File
File diff suppressed because it is too large Load Diff
+59 -25
View File
@@ -1,40 +1,74 @@
{ {
"name": "@pushrocks/smartmarkdown", "name": "@push.rocks/smartmarkdown",
"version": "2.0.4", "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.",
"main": "dist/index.js", "exports": {
"typings": "dist/index.d.ts", ".": "./dist_ts/index.js"
"author": "Lossless GmbH", },
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"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.17", "@git.zone/tsbuild": "^4.4.0",
"@gitzone/tsrun": "^1.2.8", "@git.zone/tsdoc": "^2.0.3",
"@gitzone/tstest": "^1.0.28", "@git.zone/tstest": "^3.6.3",
"@pushrocks/tapbundle": "^3.2.0", "@types/mdast": "^4.0.4",
"@types/node": "^13.1.8", "@types/node": "^25.6.0"
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@types/marked": "^0.7.2", "@push.rocks/smartyaml": "^3.0.5",
"@types/turndown": "^5.0.0", "@types/turndown": "^5.0.6",
"marked": "^0.8.0", "remark-frontmatter": "^5.0.0",
"turndown": "^5.0.3", "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/**/*",
"ts_web/*", "ts_web/**/*",
"dist/*", "dist/**/*",
"dist_web/*", "dist_*/**/*",
"assets/*", "dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js", "cli.js",
".smartconfig.json",
"license",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
] ],
"browserslist": [
"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 @@
+183 -20
View File
@@ -1,26 +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.
[![build status](https://gitlab.com/pushrocks/smartmarkdown/badges/master/build.svg)](https://gitlab.com/pushrocks/smartmarkdown/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartmarkdown/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartmarkdown/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartmarkdown.svg)](https://www.npmjs.com/package/@pushrocks/smartmarkdown)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartmarkdown/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartmarkdown)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
## Usage ## Issue Reporting and Security
For further information read the linked docs at the top of this readme. 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.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh) ## Install
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com) ```bash
pnpm add @push.rocks/smartmarkdown
```
## What It Does
`@push.rocks/smartmarkdown` is intentionally focused:
- 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`.
## 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.
+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.'
}
+15 -7
View File
@@ -1,20 +1,28 @@
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',
}); });
turndownInstance.use(plugins.turndownPluginGfm.gfm); turndownInstance.use(plugins.turndownPluginGfm.gfm);
return turndownInstance.turndown(htmlString); return turndownInstance.turndown(htmlString);
@@ -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"
}