Skip to content

Commit 262103e

Browse files
[Merge Task]: markdown-remark migration and rework (#1356)
* feat(markdown-remark): add initial implementation and configuration for markdown processing * feat(markdown-remark): enhance error handling and improve type definitions with detailed documentation * Migrate markdown-remark-processor into markdown-remark/core * feat(styles): add new callout styles for GitHub, Obsidian, and VitePress themes, and implement heading styles * feat(markdown-remark): add rehypeHeadingIds plugin for collecting headings and assigning unique IDs * refactor(markdown-remark): reorganize plugin loading utilities and separate import logic into dedicated files * fix(package): remove redundant test script from package.json * fix(package): add missing module type declaration in package.json and update import path in tsdown.config.ts * feat(package): add types and default exports for integration module in package.json * fix(package): update @astrojs/internal-helpers dependency to use catalog:min in package.json and pnpm files * feat(package): add publint dependency and update pnpm-lock.yaml * feat(package): integrate @withstudiocms/internal_helpers and update related configurations * Resetup integration * feat(markdown-remark): export StudioCMSMarkdownRemarkIntegrationOptions type from types.ts * fix(virtual): update comments to clarify type handling and remove unnecessary biome ignore * feat(config): add 'markdown-remark' to StudioCMS package list and clean up pnpm workspace dependencies * feat(markdown-remark): enhance error handling and logging in Markdown component integration * feat(markdown-remark): update default integration options and enhance configuration types * feat(markdown-remark): enhance documentation with detailed comments for plugins and configurations * feat(markdown-remark): migrate to main mono repo, add frontmatter parsing, and enhance tests * fix(docs): update changelog links in README for correct repository path * feat(markdown-remark): improve error handling and clean up code in integration and plugins
1 parent 9d2bf80 commit 262103e

63 files changed

Lines changed: 4870 additions & 11 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/fifty-years-relax.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@studiocms/markdown-remark": minor
3+
---
4+
5+
Migrate to main withstudiocms/studiocms mono repo and refactor

.codecov.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ flags:
4646
paths:
4747
- packages/studiocms/**
4848
- packages/@studiocms/devapps/**
49+
- packages/@studiocms/markdown-remark/**
4950
plugins:
5051
carryforward: false
5152
# These have to be listed individually due to
@@ -78,6 +79,10 @@ component_management:
7879
name: "@studiocms/devapps"
7980
paths:
8081
- packages/@studiocms/devapps/**
82+
- component_id: studiocms_markdown_remark
83+
name: "@studiocms/markdown-remark"
84+
paths:
85+
- packages/@studiocms/markdown-remark/**
8186

8287
# StudioCMS Plugins
8388
- component_id: studiocms_auth0

cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,12 @@
189189
"SDKAPI",
190190
"searchlist",
191191
"seti",
192+
"shiki",
192193
"shikijs",
193194
"signup",
194195
"simpleicons",
195196
"sitemapindex",
197+
"smol",
196198
"Sogou",
197199
"Sosospider",
198200
"stefanzweifel",

knip.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const atStudioCMSPackages = [
6363
'github',
6464
'google',
6565
'markdoc',
66+
'markdown-remark',
6667
'mdx',
6768
'md',
6869
'html',

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "root",
33
"private": true,
4+
"type": "module",
45
"repository": {
56
"type": "git",
67
"url": "git+https://github.com/withstudiocms/studiocms.git"
@@ -35,7 +36,7 @@
3536
"clean:pnpm-lock": "pnpm clean:node && node ./scripts/clean-pnpm-lockfile.mjs",
3637
"reset:pnpm": "pnpm clean:pnpm-lock && pnpm install",
3738

38-
"allure:clean": "node -e \"require('fs').rmSync('allure-results', { recursive: true, force: true })\"",
39+
"allure:clean": "node -e \"import('node:fs').then(({rmSync})=>rmSync('allure-results',{recursive:true,force:true}))\"",
3940
"allure:serve": "allure serve allure-results",
4041

4142
"test": "pnpm allure:clean && vitest run",
@@ -105,10 +106,12 @@
105106
"execa": "^9.6.1",
106107
"knip": "^5.83.1",
107108
"pkg-pr-new": "^0.0.63",
109+
"publint": "^0.3.17",
108110
"studiocms": "workspace:^",
109111
"tinyglobby": "catalog:",
110112
"typescript": "catalog:",
111113
"ts-patch": "^3.3.0",
114+
"tsdown": "catalog:",
112115
"vite": "catalog:astrojs",
113116
"vitest": "^3.2.4",
114117
"jsdom": "^28.1.0"
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# @studiocms/markdown-remark
2+
3+
## 1.2.0
4+
5+
### Minor Changes
6+
7+
- [#32](https://github.com/withstudiocms/markdown-remark/pull/32) [`06f0668`](https://github.com/withstudiocms/markdown-remark/commit/06f0668b4c50fff7d56e21006cded86748fecc2c) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Update to support all features and functionality of `@astrojs/markdown-remark@6.3.1`
8+
9+
### Patch Changes
10+
11+
- Updated dependencies [[`06f0668`](https://github.com/withstudiocms/markdown-remark/commit/06f0668b4c50fff7d56e21006cded86748fecc2c)]:
12+
- @studiocms/markdown-remark-processor@1.2.0
13+
14+
## 1.1.0
15+
16+
### Patch Changes
17+
18+
- Updated dependencies [[`6a05fec`](https://github.com/withstudiocms/markdown-remark/commit/6a05fecf27c68f57168cf522a9cec178d71a9f7c)]:
19+
- @studiocms/markdown-remark-processor@1.1.0
20+
21+
## 1.0.0
22+
23+
### Major Changes
24+
25+
- [#15](https://github.com/withstudiocms/markdown-remark/pull/15) [`ab0142b`](https://github.com/withstudiocms/markdown-remark/commit/ab0142bc28ba51de5884c0f6ee0d655400532009) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - First Major Release
26+
27+
Package has been divided into multiple smaller packages:
28+
29+
- `@studiocms/markdown-remark`: The Primary Astro integration that includes the underlying processor as well as custom functionality to allow custom markdown rendering pipelines.
30+
- `@studiocms/markdown-remark-processor`: The Main markdown processor for `@studiocms/markdown-remark`.
31+
- `@studiocms/markdown-remark-processor-web`: A Client side browser-first version of our main processor.
32+
33+
### Minor Changes
34+
35+
- [#15](https://github.com/withstudiocms/markdown-remark/pull/15) [`ab0142b`](https://github.com/withstudiocms/markdown-remark/commit/ab0142bc28ba51de5884c0f6ee0d655400532009) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Add support for Discord subtext `-#` syntax using custom remark plugin
36+
37+
### Patch Changes
38+
39+
- Updated dependencies [[`ab0142b`](https://github.com/withstudiocms/markdown-remark/commit/ab0142bc28ba51de5884c0f6ee0d655400532009), [`ab0142b`](https://github.com/withstudiocms/markdown-remark/commit/ab0142bc28ba51de5884c0f6ee0d655400532009)]:
40+
- @studiocms/markdown-remark-processor@1.0.0
41+
42+
## 0.3.1
43+
44+
### Patch Changes
45+
46+
- [#13](https://github.com/withstudiocms/markdown-remark/pull/13) [`066838b`](https://github.com/withstudiocms/markdown-remark/commit/066838ba7775b48bbb9953d310fafd9c2b78af6d) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - update readme
47+
48+
## 0.3.0
49+
50+
### Minor Changes
51+
52+
- [#11](https://github.com/withstudiocms/markdown-remark/pull/11) [`b9d4b7b`](https://github.com/withstudiocms/markdown-remark/commit/b9d4b7b79a62bcf52fe1445f4b9d333ce618e6c9) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Refactor integration exports and simplification
53+
54+
- Default package export `@studiocms/markdown-remark` now exports the same resources as `@studiocms/markdown-remark/integration`
55+
56+
New Export:
57+
58+
- `@studiocms/markdown-remark/integration` - Direct export of the included Astro integration
59+
60+
No longer depends on Astro-integration-kit.
61+
62+
### Patch Changes
63+
64+
- [#11](https://github.com/withstudiocms/markdown-remark/pull/11) [`b9d4b7b`](https://github.com/withstudiocms/markdown-remark/commit/b9d4b7b79a62bcf52fe1445f4b9d333ce618e6c9) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Remove need for entities dependency, and change the one place it was being used.
65+
66+
## 0.2.0
67+
68+
### Minor Changes
69+
70+
- [#8](https://github.com/withstudiocms/markdown-remark/pull/8) [`6b0053b`](https://github.com/withstudiocms/markdown-remark/commit/6b0053b37ec58e56bd757d68f1d4a27f78b233b7) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Introduce custom User-Defined component handling.
71+
72+
This update includes significant enhancements to the Markdown Remark processor Astro Integration, allowing for more flexible and powerful Markdown rendering with custom components.
73+
74+
### New Features:
75+
76+
- Added custom components support in the Markdown Remark processor Astro Integration.
77+
- Introduced utility functions in `utils.ts` for component proxy creation, indentation handling, dedenting strings, and merging records.
78+
- Moved zod schema to separate `schema.ts` file.
79+
80+
### Integration Updates:
81+
82+
- Enhanced Astro integration to support custom components configuration via `astro.config.mjs`.
83+
- Updated `markdown.ts` to include custom components during Markdown rendering.
84+
- Extended `index.ts` to utilize the new schema and utilities.
85+
86+
### Documentation:
87+
88+
- Updated `README.md` with instructions for setting up custom components in Astro integration.
89+
90+
### Dependencies:
91+
92+
- Added `entities` and `ultrahtml` as new dependencies.
93+
94+
## 0.1.1
95+
96+
### Patch Changes
97+
98+
- [#3](https://github.com/withstudiocms/markdown-remark/pull/3) [`74d2b32`](https://github.com/withstudiocms/markdown-remark/commit/74d2b320c9acc562f0c87f5c6cea69712bcfba88) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Update CSS and add flags to prevent vite dynamic import warnings
99+
100+
- [#5](https://github.com/withstudiocms/markdown-remark/pull/5) [`4beb076`](https://github.com/withstudiocms/markdown-remark/commit/4beb07632d18e05b3cece083512bdbd8197ebc31) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Add support for github Callouts/asides
101+
102+
## 0.1.0
103+
104+
### Minor Changes
105+
106+
- [`e5c6ea2`](https://github.com/withstudiocms/markdown-remark/commit/e5c6ea207285dc623f6879b0160c5b4b05542e52) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Initial Release
107+
108+
This package is heavily inspired by and based on `@astrojs/markdown-remark`. It provides seamless integration with Astro, allowing you to easily parse and transform Markdown content within your Astro projects. The package leverages the power of remark to offer a highly configurable and extensible Markdown parser and transformer.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024-present StudioCMS - withstudiocms (https://github.com/withstudiocms)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# @studiocms/markdown-remark
2+
3+
[![NPM Version](https://img.shields.io/npm/v/@studiocms/markdown-remark?style=for-the-badge&logo=npm)](https://npm.im/@studiocms/markdown-remark)
4+
[![Formatted with Biome](https://img.shields.io/badge/Formatted_with-Biome-60a5fa?style=for-the-badge&logo=biome)](https://biomejs.dev/)
5+
[![Built with Astro](https://img.shields.io/badge/built_with-astro-astro?style=for-the-badge&logo=astro&logoColor=fff&color=%23BC52EE)](https://astro.build)
6+
7+
## Overview
8+
9+
`@studiocms/markdown-remark` is a powerful Markdown parser and transformer built on top of [remark](https://github.com/remarkjs/remark). It provides seamless integration with [Astro](https://astro.build/), allowing you to easily parse and transform Markdown content within your Astro projects.
10+
11+
This project is heavily based on and compatible with Astro's built-in `@astrojs/markdown-remark`
12+
13+
## Features
14+
15+
- **Markdown Parsing**: Parse Markdown content into an abstract syntax tree (AST) using remark.
16+
- **Astro Integration**: Easily integrate with Astro to transform Markdown content into HTML.
17+
- **Custom Plugins**: Extend the functionality with custom remark plugins.
18+
- **Configurable**: Highly configurable to suit your specific needs.
19+
20+
## Installation
21+
22+
To install `@studiocms/markdown-remark`, use your preferred package manager:
23+
24+
```bash
25+
npm install @studiocms/markdown-remark
26+
# or
27+
yarn add @studiocms/markdown-remark
28+
# or
29+
pnpm add @studiocms/markdown-remark
30+
```
31+
32+
## Usage
33+
34+
### As an Astro Integration
35+
36+
With the Astro integration enabled, you can either pass in custom components into your astro config, or manually for the specific render your trying to do shown in the following methods.
37+
38+
#### Setup the integration
39+
40+
**`astro.config.mjs`**
41+
42+
```ts
43+
import markdownRemark from '@studiocms/markdown-remark';
44+
import { defineConfig } from 'astro/config';
45+
46+
export default defineConfig({
47+
markdown: {
48+
/*
49+
* Your Customizations here based on:
50+
* https://docs.astro.build/en/reference/configuration-reference/#markdown-options
51+
*/
52+
},
53+
integrations: [markdownRemark({
54+
// Used for injecting CSS for Headings and Callouts
55+
injectCSS: true,
56+
// User defined components that will be used when processing markdown
57+
components: {
58+
// Example of a custom defined component
59+
custom: "./src/components/Custom.astro",
60+
},
61+
// Custom Markdown config
62+
markdown: {
63+
// Configure the available callout themes
64+
callouts: {
65+
theme: 'obsidian' // Can also be 'github' or 'vitepress'
66+
},
67+
autoLinkHeadings: true,
68+
sanitize: {} // see https://github.com/natemoo-re/ultrahtml?tab=readme-ov-file#sanitization for full options
69+
}
70+
})],
71+
});
72+
```
73+
74+
#### Use the integration
75+
76+
**`src/pages/index.astro`**
77+
78+
```astro
79+
---
80+
import { Markdown } from 'studiocms:markdown-remark';
81+
import Custom from '../components/Custom.astro';
82+
---
83+
<html>
84+
<head>
85+
<meta charset="utf-8" />
86+
<meta name="viewport" content="width=device-width" />
87+
<title>Example</title>
88+
</head>
89+
<body>
90+
<Markdown content={`# Hello World! <custom></custom>`} components={{ custom: Custom }} />
91+
</body>
92+
</html>
93+
```
94+
95+
OR
96+
97+
```astro
98+
---
99+
import { render } from 'studiocms:markdown-remark';
100+
import Custom from '../components/Custom.astro';
101+
102+
// @ts-ignore
103+
const { html } = await render('# Hello World! <custom></custom>', {}, { $$result, {custom: Custom} })
104+
---
105+
<html>
106+
<head>
107+
<meta charset="utf-8" />
108+
<meta name="viewport" content="width=device-width" />
109+
<title>Example</title>
110+
</head>
111+
<body>
112+
{html}
113+
</body>
114+
</html>
115+
```
116+
117+
### Using the Markdown component directly without the integration
118+
119+
**`src/pages/index.astro`**
120+
121+
```astro
122+
---
123+
import { Markdown } from '@studiocms/markdown-remark/components';
124+
import H1 from '../components/H1.astro';
125+
---
126+
<html>
127+
<head>
128+
<meta charset="utf-8" />
129+
<meta name="viewport" content="width=device-width" />
130+
<title>Example</title>
131+
</head>
132+
<body>
133+
<Markdown content={`# Hello world!`} components={{ h1: H1 }} />
134+
</body>
135+
</html>
136+
```
137+
138+
## Changelog
139+
140+
See the [Changelog](https://github.com/withstudiocms/studiocms/blob/main/packages/@studiocms/markdown-remark/CHANGELOG.md) for the change history of this package.
141+
142+
## Contribution
143+
144+
If you see any errors or room for improvement, feel free to open an [issue or pull request](https://github.com/withstudiocms/studiocms/) . Thank you in advance for contributing! ❤️
145+
146+
## Licensing
147+
148+
[MIT Licensed](./LICENSE).

0 commit comments

Comments
 (0)