Skip to content

Commit 48d2806

Browse files
committed
feat: init commit
0 parents  commit 48d2806

File tree

17 files changed

+6411
-0
lines changed

17 files changed

+6411
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Created by nice-move
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 2
8+
indent_style = space
9+
insert_final_newline = true
10+
max_line_length = 80
11+
quote_type = single
12+
tab_width = 2
13+
trim_trailing_whitespace = true

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Created by nice-move
2+
3+
* text=auto eol=lf

.githooks/commit-msg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
npx --no-install nice-move lint commit

.githooks/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
npm run lint:staged || exit 1
4+
npm test

.github/workflows/bring-it.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: bring-it
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
test:
10+
strategy:
11+
matrix:
12+
os:
13+
- macos-latest
14+
- windows-latest
15+
- ubuntu-latest
16+
node:
17+
- current
18+
- lts/*
19+
- lts/-1
20+
exclude:
21+
- os: ubuntu-latest
22+
node: lts/*
23+
24+
runs-on: ${{ matrix.os }}
25+
steps:
26+
- name: Run
27+
uses: airkro/bring-it@actions
28+
with:
29+
node-version: ${{ matrix.node }}
30+
31+
publish:
32+
needs: [test]
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Run
36+
uses: airkro/bring-it@actions
37+
with:
38+
npm-token: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Created by https://gitignore.io/api/ssh,certificates,node,windows
2+
# Edit at https://gitignore.io?templates=ssh,certificates,node,windows
3+
4+
### certificates ###
5+
*.pem
6+
*.key
7+
*.crt
8+
*.cer
9+
*.der
10+
*.priv
11+
12+
### Node ###
13+
# Logs
14+
logs
15+
*.log
16+
npm-debug.log*
17+
yarn-debug.log*
18+
yarn-error.log*
19+
lerna-debug.log*
20+
.pnpm-debug.log*
21+
22+
# Diagnostic reports (https://nodejs.org/api/report.html)
23+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
24+
25+
# Runtime data
26+
pids
27+
*.pid
28+
*.seed
29+
*.pid.lock
30+
31+
# Directory for instrumented libs generated by jscoverage/JSCover
32+
lib-cov
33+
34+
# Coverage directory used by tools like istanbul
35+
coverage
36+
*.lcov
37+
38+
# nyc test coverage
39+
.nyc_output
40+
41+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
42+
.grunt
43+
44+
# Bower dependency directory (https://bower.io/)
45+
bower_components
46+
47+
# node-waf configuration
48+
.lock-wscript
49+
50+
# Compiled binary addons (https://nodejs.org/api/addons.html)
51+
build/Release
52+
53+
# Dependency directories
54+
node_modules/
55+
jspm_packages/
56+
57+
# Snowpack dependency directory (https://snowpack.dev/)
58+
web_modules/
59+
60+
# TypeScript cache
61+
*.tsbuildinfo
62+
63+
# Optional npm cache directory
64+
.npm
65+
66+
# Optional eslint cache
67+
.eslintcache
68+
69+
# Optional stylelint cache
70+
.stylelintcache
71+
72+
# Microbundle cache
73+
.rpt2_cache/
74+
.rts2_cache_cjs/
75+
.rts2_cache_es/
76+
.rts2_cache_umd/
77+
78+
# Optional REPL history
79+
.node_repl_history
80+
81+
# Output of 'npm pack'
82+
*.tgz
83+
84+
# Yarn Integrity file
85+
.yarn-integrity
86+
87+
# dotenv environment variable files
88+
.env
89+
.env.development.local
90+
.env.test.local
91+
.env.production.local
92+
.env.local
93+
94+
# parcel-bundler cache (https://parceljs.org/)
95+
.cache
96+
.parcel-cache
97+
98+
# Next.js build output
99+
.next
100+
out
101+
102+
# Nuxt.js build / generate output
103+
.nuxt
104+
dist
105+
106+
# Gatsby files
107+
.cache/
108+
# Comment in the public line in if your project uses Gatsby and not Next.js
109+
# https://nextjs.org/blog/next-9-1#public-directory-support
110+
# public
111+
112+
# vuepress build output
113+
.vuepress/dist
114+
115+
# vuepress v2.x temp and cache directory
116+
.temp
117+
118+
# Docusaurus cache and generated files
119+
.docusaurus
120+
121+
# Serverless directories
122+
.serverless/
123+
124+
# FuseBox cache
125+
.fusebox/
126+
127+
# DynamoDB Local files
128+
.dynamodb/
129+
130+
# TernJS port file
131+
.tern-port
132+
133+
# Stores VSCode versions used for testing VSCode extensions
134+
.vscode-test
135+
136+
# yarn v2
137+
.yarn/cache
138+
.yarn/unplugged
139+
.yarn/build-state.yml
140+
.yarn/install-state.gz
141+
.pnp.*
142+
143+
### Node Patch ###
144+
# Serverless Webpack directories
145+
.webpack/
146+
147+
# Optional stylelint cache
148+
149+
# SvelteKit build / generate output
150+
.svelte-kit
151+
152+
### SSH ###
153+
**/.ssh/id_*
154+
**/.ssh/*_id_*
155+
**/.ssh/known_hosts
156+
157+
### Windows ###
158+
# Windows thumbnail cache files
159+
Thumbs.db
160+
Thumbs.db:encryptable
161+
ehthumbs.db
162+
ehthumbs_vista.db
163+
164+
# Dump file
165+
*.stackdump
166+
167+
# Folder config file
168+
[Dd]esktop.ini
169+
170+
# Recycle Bin used on file shares
171+
$RECYCLE.BIN/
172+
173+
# Windows Installer files
174+
*.cab
175+
*.msi
176+
*.msix
177+
*.msm
178+
*.msp
179+
180+
# Windows shortcuts
181+
*.lnk
182+
183+
# End of https://gitignore.io/api/ssh,certificates,node,windows

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
shamefully-hoist = true
2+
engine-strict = true

LICENSE

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) 2025 Eric Chen
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.

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# remark-block-directive
2+
3+
Remark plugin for turning HTML directive into MDX tags.
4+
5+
[![npm][npm-badge]][npm-url]
6+
[![github][github-badge]][github-url]
7+
![node][node-badge]
8+
9+
[npm-url]: https://www.npmjs.com/package/remark-block-directive
10+
[npm-badge]: https://img.shields.io/npm/v/remark-block-directive.svg?style=flat-square&logo=npm
11+
[github-url]: git+https://github.com/show-docs/remark-block-directive
12+
[github-badge]: https://img.shields.io/npm/l/remark-block-directive.svg?style=flat-square&colorB=blue&logo=github
13+
[node-badge]: https://img.shields.io/node/v/remark-block-directive.svg?style=flat-square&colorB=green&logo=node.js
14+
15+
## Example
16+
17+
```md
18+
Turn:
19+
20+
:::div{.foo}
21+
22+
bar
23+
24+
:::
25+
26+
Into:
27+
28+
<div class="foo">
29+
bar
30+
</div>
31+
```
32+
33+
## Tips
34+
35+
Only some HTML tags are supported.
36+
37+
## Installation
38+
39+
```bash
40+
npm install remark-block-directive --save-dev
41+
```
42+
43+
## Usage
44+
45+
```mjs
46+
import readFileSync from 'node:fs';
47+
48+
import { remark } from 'remark';
49+
import { remarkBlockDirective } from 'remark-block-directive';
50+
import remarkDirective from 'remark-directive';
51+
import remarkMdx from 'remark-mdx';
52+
53+
const markdownText = readFileSync('example.md', 'utf8');
54+
55+
remark()
56+
.use(remarkMdx)
57+
.use(remarkDirective)
58+
.use(remarkBlockDirective)
59+
.process(markdownText)
60+
.then((file) => console.info(file))
61+
.catch((error) => console.warn(error));
62+
```
63+
64+
## Related
65+
66+
- [markdown-code-block-meta](https://github.com/show-docs/markdown-code-block-meta)
67+
- [rehype-extended-table](https://github.com/show-docs/rehype-extended-table)
68+
- [remark-code-example](https://github.com/show-docs/remark-code-example)
69+
- [remark-css-execute](https://github.com/show-docs/remark-css-execute)
70+
- [remark-docusaurus](https://github.com/show-docs/remark-docusaurus)
71+
- [remark-kroki](https://github.com/show-docs/remark-kroki)

eslint.config.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import base from '@nice-move/all-in-base';
2+
import ava from 'eslint-plugin-ava';
3+
4+
export default [
5+
...base,
6+
{
7+
files: ['test/**/*.mjs'],
8+
...ava.configs['flat/recommended'],
9+
},
10+
{
11+
ignores: ['test/fixture/**'],
12+
},
13+
];

lib/index.mjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { visit } from 'unist-util-visit';
2+
3+
const tags = [
4+
'article',
5+
'aside',
6+
'details',
7+
'dialog',
8+
'div',
9+
'footer',
10+
'header',
11+
'main',
12+
'section',
13+
'summary',
14+
];
15+
16+
export function remarkBlockDirective() {
17+
return (tree) => {
18+
visit(
19+
tree,
20+
(node) => node.type === 'containerDirective' && tags.includes(node.name),
21+
(node) => {
22+
node.type = 'mdxJsxFlowElement';
23+
node.attributes = [
24+
{
25+
type: 'mdxJsxAttribute',
26+
name: 'className',
27+
value: node.attributes?.class,
28+
},
29+
{
30+
type: 'mdxJsxAttribute',
31+
name: 'id',
32+
value: node.attributes?.id,
33+
},
34+
].filter(({ value }) => value !== undefined);
35+
},
36+
);
37+
};
38+
}

0 commit comments

Comments
 (0)