pantsdown 1.3.1 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +136 -0
- package/README.md +107 -2
- package/bun.lockb +0 -0
- package/package.json +5 -4
- package/{styles.css → src/css/styles.css} +709 -242
- package/{styles.css.d.ts → src/css/styles.css.d.ts} +2 -2
- package/src/pantsdown.ts +5 -0
- package/src/parser.ts +9 -3
- package/src/renderer.ts +40 -11
- package/src/types.ts +14 -3
- package/src/utils.ts +34 -12
- package/LICENSE.md +0 -67
package/LICENSE
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
Pantsdown (https://github.com/wallpants/pantsdown)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023+, Wallpants (https://github.com/wallpants/).
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
----------------------------------------------------
|
|
24
|
+
|
|
25
|
+
highlight.js (https://github.com/highlightjs/highlight.js)
|
|
26
|
+
|
|
27
|
+
BSD 3-Clause License
|
|
28
|
+
|
|
29
|
+
Copyright (c) 2006, Ivan Sagalaev.
|
|
30
|
+
All rights reserved.
|
|
31
|
+
|
|
32
|
+
Redistribution and use in source and binary forms, with or without
|
|
33
|
+
modification, are permitted provided that the following conditions are met:
|
|
34
|
+
|
|
35
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
36
|
+
list of conditions and the following disclaimer.
|
|
37
|
+
|
|
38
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
39
|
+
this list of conditions and the following disclaimer in the documentation
|
|
40
|
+
and/or other materials provided with the distribution.
|
|
41
|
+
|
|
42
|
+
* Neither the name of the copyright holder nor the names of its
|
|
43
|
+
contributors may be used to endorse or promote products derived from
|
|
44
|
+
this software without specific prior written permission.
|
|
45
|
+
|
|
46
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
47
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
48
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
49
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
50
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
51
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
52
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
53
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
54
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
55
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
56
|
+
|
|
57
|
+
----------------------------------------------------
|
|
58
|
+
|
|
59
|
+
github-markdown-css (https://github.com/sindresorhus/github-markdown-css)
|
|
60
|
+
|
|
61
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
62
|
+
|
|
63
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
64
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
65
|
+
in the Software without restriction, including without limitation the rights
|
|
66
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
67
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
68
|
+
furnished to do so, subject to the following conditions:
|
|
69
|
+
|
|
70
|
+
The above copyright notice and this permission notice shall be included in
|
|
71
|
+
all copies or substantial portions of the Software.
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
75
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
76
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
77
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
78
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
79
|
+
THE SOFTWARE.
|
|
80
|
+
|
|
81
|
+
----------------------------------------------------
|
|
82
|
+
|
|
83
|
+
Marked
|
|
84
|
+
|
|
85
|
+
Copyright (c) 2018+, MarkedJS (https://github.com/markedjs/)
|
|
86
|
+
|
|
87
|
+
Copyright (c) 2011-2018, Christopher Jeffrey (https://github.com/chjj/)
|
|
88
|
+
|
|
89
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
90
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
91
|
+
in the Software without restriction, including without limitation the rights
|
|
92
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
93
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
94
|
+
furnished to do so, subject to the following conditions:
|
|
95
|
+
|
|
96
|
+
The above copyright notice and this permission notice shall be included in
|
|
97
|
+
all copies or substantial portions of the Software.
|
|
98
|
+
|
|
99
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
100
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
101
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
102
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
103
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
104
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
105
|
+
THE SOFTWARE.
|
|
106
|
+
|
|
107
|
+
----------------------------------------------------
|
|
108
|
+
|
|
109
|
+
Markdown
|
|
110
|
+
|
|
111
|
+
Copyright © 2004, John Gruber
|
|
112
|
+
http://daringfireball.net/
|
|
113
|
+
All rights reserved.
|
|
114
|
+
|
|
115
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
116
|
+
are permitted provided that the following conditions are met:
|
|
117
|
+
|
|
118
|
+
- Redistributions of source code must retain the above copyright notice,
|
|
119
|
+
this list of conditions and the following disclaimer.
|
|
120
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
|
121
|
+
this list of conditions and the following disclaimer in the documentation
|
|
122
|
+
and/or other materials provided with the distribution.
|
|
123
|
+
- Neither the name “Markdown” nor the names of its contributors may be used
|
|
124
|
+
to endorse or promote products derived from this software without specific
|
|
125
|
+
prior written permission.
|
|
126
|
+
|
|
127
|
+
This software is provided by the copyright holders and contributors “as is”
|
|
128
|
+
and any express or implied warranties, including, but not limited to,
|
|
129
|
+
the implied warranties of merchantability and fitness for a particular purpose
|
|
130
|
+
are disclaimed. In no event shall the copyright owner or contributors be liable
|
|
131
|
+
for any direct, indirect, incidental, special, exemplary, or consequential
|
|
132
|
+
damages (including, but not limited to, procurement of substitute goods or
|
|
133
|
+
services; loss of use, data, or profits; or business interruption) however
|
|
134
|
+
caused and on any theory of liability, whether in contract, strict liability,
|
|
135
|
+
or tort (including negligence or otherwise) arising in any way out of the use
|
|
136
|
+
of this software, even if advised of the possibility of such damage.
|
package/README.md
CHANGED
|
@@ -1,5 +1,110 @@
|
|
|
1
|
+
<!-- Up to marked@9.1.2 -->
|
|
2
|
+
|
|
1
3
|
# Pantsdown
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
Pantsdown is a **Markdown** to **"GitHub HTML"** converter based on [Marked](https://github.com/markedjs/marked).
|
|
6
|
+
Basically this is a non customizable version of Marked, optimized to render markdown similar to how GitHub does it plus
|
|
7
|
+
some features developed specifically for [github-preview.nvim](https://github.com/wallpants/github-preview.nvim).
|
|
8
|
+
|
|
9
|
+
Applicable fixes/updates released by Marked will eventually be applied to Pantsdown.
|
|
10
|
+
|
|
11
|
+
If you need a feature that's supported by GitHub and is not already listed in Pantsdown's [Roadmap](#roadmap),
|
|
12
|
+
feel free to open an issue. If you need anything else, use Marked or another library.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
🚨 Pantsdown is distributed only as a TypeScript module. This means you'll need a bundler to handle transpilation.
|
|
17
|
+
See below for usage examples.
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
bun install pantsdown
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### [Vite](https://vitejs.dev/guide/#scaffolding-your-first-vite-project)
|
|
26
|
+
|
|
27
|
+
Create a Vite Project & install dependencies:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
bun create vite my-app --template react-swc-ts
|
|
31
|
+
cd my-app
|
|
32
|
+
bun install pantsdown
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Remove CSS from `my-app/src/main.tsx`:
|
|
36
|
+
|
|
37
|
+
```diff
|
|
38
|
+
import React from 'react'
|
|
39
|
+
import ReactDOM from 'react-dom/client'
|
|
40
|
+
import App from './App.tsx'
|
|
41
|
+
- import './index.css'
|
|
42
|
+
|
|
43
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
44
|
+
<React.StrictMode>
|
|
45
|
+
<App />
|
|
46
|
+
</React.StrictMode>,
|
|
47
|
+
)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Replace content in `my-app/src/App.tsx`:
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { Pantsdown } from "pantsdown";
|
|
54
|
+
import "pantsdown/styles.css";
|
|
55
|
+
import { useEffect } from "react";
|
|
56
|
+
|
|
57
|
+
const pantsdown = new Pantsdown();
|
|
58
|
+
|
|
59
|
+
function App() {
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const markdown = "# Hello world\n- [ ] item 1\n- [ ] item 2";
|
|
62
|
+
const html = pantsdown.parse(markdown);
|
|
63
|
+
const container = document.getElementById("markdown-container");
|
|
64
|
+
if (container) container.innerHTML = html;
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
return <div id="markdown-container" className="pantsdown light" />;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default App;
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Configuration
|
|
74
|
+
|
|
75
|
+
The Pantsdown constructor accepts an optional configuration object:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { PantsdownConfig } from "pantsdown";
|
|
79
|
+
|
|
80
|
+
const config: PantsdownConfig = {
|
|
81
|
+
renderer: {
|
|
82
|
+
/**
|
|
83
|
+
* Prefix to be added to relative image sources.
|
|
84
|
+
* Must start and end with "/"
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* relativeImageUrlPrefix: "/__localimage__/"
|
|
88
|
+
*
|
|
89
|
+
* 
|
|
90
|
+
* relative src is updated and result in:
|
|
91
|
+
* <img src="/__localimage__/wallpants-512.png" />
|
|
92
|
+
*
|
|
93
|
+
* 
|
|
94
|
+
* absolute path remains unchanged:
|
|
95
|
+
* <img src="https://avatars.githubusercontent.com/wallpants" />
|
|
96
|
+
*/
|
|
97
|
+
relativeImageUrlPrefix: "/__localimage__/",
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const pantsdown = new Pantsdown(config);
|
|
102
|
+
pantsdown.parse(markdown);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Roadmap
|
|
4
106
|
|
|
5
|
-
|
|
107
|
+
- [x] Add id & anchors to headings
|
|
108
|
+
- [ ] Add button to copy code in fences
|
|
109
|
+
- [ ] [Mermaid](https://mermaid.js.org/) support
|
|
110
|
+
- [ ] [Footnote](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#footnotes) support [Base](https://github.com/bent10/marked-extensions/tree/main/packages/footnote)
|
package/bun.lockb
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pantsdown",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"author": "wallpants",
|
|
5
5
|
"description": "The markdown parser",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
"./styles.css": {
|
|
14
|
-
"types": "./styles.css.d.ts",
|
|
15
|
-
"bun": "./styles.css",
|
|
16
|
-
"import": "./styles.css"
|
|
14
|
+
"types": "./src/css/styles.css.d.ts",
|
|
15
|
+
"bun": "./src/css/styles.css",
|
|
16
|
+
"import": "./src/css/styles.css"
|
|
17
17
|
},
|
|
18
18
|
".": {
|
|
19
19
|
"types": "./src/index.ts",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
]
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"github-slugger": "^2.0.0",
|
|
40
41
|
"highlight.js": "^11.9.0"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|