Skip to content

Commit 4cd09ec

Browse files
committed
feat: init commit
0 parents  commit 4cd09ec

File tree

12 files changed

+9979
-0
lines changed

12 files changed

+9979
-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
4+
npm test

.github/workflows/bring-it.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
- 18.0.0
18+
- 16.13.0
19+
exclude:
20+
- os: ubuntu-latest
21+
node: 16.13.0
22+
23+
runs-on: ${{ matrix.os }}
24+
steps:
25+
- name: Run
26+
uses: airkro/bring-it@actions
27+
with:
28+
node-version: ${{ matrix.node }}
29+
30+
publish:
31+
needs: [test]
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Run
35+
uses: airkro/bring-it@actions
36+
with:
37+
npm-token: ${{ secrets.NPM_TOKEN }}

.gitignore

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

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) 2022 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: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# markdown-code-block-meta
2+
3+
A library to parse/stringify metadata of markdown code block.
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/markdown-code-block-meta
10+
[npm-badge]: https://img.shields.io/npm/v/markdown-code-block-meta.svg?style=flat-square&logo=npm
11+
[github-url]: https://github.com/nice-move/markdown-code-block-meta
12+
[github-badge]: https://img.shields.io/npm/l/markdown-code-block-meta.svg?style=flat-square&colorB=blue&logo=github
13+
[node-badge]: https://img.shields.io/node/v/markdown-code-block-meta.svg?style=flat-square&colorB=green&logo=node.js
14+
15+
## Installation
16+
17+
```bash
18+
npm install markdown-code-block-meta --save
19+
```
20+
21+
## Usage
22+
23+
Parsing markdown with [remark](https://remark.js.org).
24+
25+
````markdown
26+
```js title="Here is an example"
27+
28+
```
29+
````
30+
31+
A Code block will turn into:
32+
33+
```json
34+
{
35+
"lang": "js",
36+
"meta": "title=\"Here is an example\""
37+
}
38+
```
39+
40+
Parsing metadata like this:
41+
42+
```js
43+
import { getValue, parse, stringify } from 'markdown-code-block-meta';
44+
45+
const input =
46+
'-8=。是 ==0 ===f=5 =9 dd k=dsds op="s 7" d-p="" sss=`7 u-` rj= lp=\' ds ds\' t="`"';
47+
48+
const result = parse(input);
49+
/* result = Map {
50+
'-8' => '。是',
51+
'==0' => undefined,
52+
'===f=5' => undefined,
53+
'=9' => undefined,
54+
'dd' => undefined,
55+
'k' => 'dsds',
56+
'op' => '"s 7"',
57+
'd-p' => '""',
58+
'sss' => '`7 u-`',
59+
'rj=' => undefined,
60+
'lp' => '\' ds ds\'',
61+
't' => '"`"'
62+
} */
63+
64+
stringify(result); // same as input
65+
66+
getValue('"abc"'); // abc
67+
getValue('`abc`'); // abc
68+
getValue("'abc'"); // abc
69+
```
70+
71+
## Related
72+
73+
- [remark-kroki](https://github.com/nice-move/remark-kroki)
74+
- [remark-code-example](https://github.com/nice-move/remark-code-example)

index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const regexp =
2+
/((?<k1>(?!=)\S+)=((?<v1>(["'`])(.*?)\5)|(?<v2>\S+)))|(?<k2>\S+)/g;
3+
4+
export function parse(string) {
5+
const io = (string ?? '').matchAll(regexp);
6+
7+
return new Map(
8+
[...io]
9+
.map((item) => item?.groups)
10+
.map(({ k1, k2, v1, v2 }) => [k1 ?? k2, v1 ?? v2]),
11+
);
12+
}
13+
14+
export function stringify(object) {
15+
return (
16+
object instanceof Map ? [...object.entries()] : Object.entries(object)
17+
)
18+
.map(([k, v]) => [k, v].filter((i) => i !== undefined).join('='))
19+
.join(' ');
20+
}
21+
22+
export function getValue(string) {
23+
return string.match(/(["'`])(?<value>.*?)\1/)?.groups?.value;
24+
}

0 commit comments

Comments
 (0)