svelte-readme 3.6.3 → 4.0.0
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/README.md +51 -83
- package/dist/button.css +28 -0
- package/dist/highlight/bash.d.ts +2 -0
- package/dist/highlight/json.d.ts +2 -0
- package/dist/highlight/shared.d.ts +11 -0
- package/dist/highlight/svelte.d.ts +2 -0
- package/dist/highlight/typescript.d.ts +5 -0
- package/dist/highlight/yaml.d.ts +2 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +73 -14
- package/dist/layout.css +18 -0
- package/dist/preprocessReadme.d.ts +8 -7
- package/dist/shared.css +24 -0
- package/dist/style.css +1 -0
- package/dist/styles/index.d.ts +3 -0
- package/dist/svelte.css +15 -0
- package/dist/svelteReadme.d.ts +42 -0
- package/dist/typescript.css +12 -0
- package/dist/utils/preprocessReadme.utils.d.ts +25 -0
- package/dist/utils/purgeCss.d.ts +1 -0
- package/dist/utils/utils.d.ts +10 -0
- package/dist/yaml.css +3 -0
- package/package.json +9 -41
- package/CHANGELOG.md +0 -197
- package/dist/createConfig.d.ts +0 -50
- package/dist/createConfig.js +0 -141
- package/dist/preprocessReadme.js +0 -182
- package/dist/style.d.ts +0 -1
- package/dist/style.js +0 -4
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# svelte-readme
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> A Vite plugin and Svelte preprocessor for developing and demoing your Svelte components in your README.md.
|
|
4
4
|
|
|
5
5
|
## Readme Driven Development
|
|
6
6
|
|
|
7
|
-
This project embraces the concept of [Readme Driven Development](https://tom.preston-werner.com/2010/08/23/readme-driven-development.html) (RDD)
|
|
7
|
+
This project embraces the concept of [Readme Driven Development](https://tom.preston-werner.com/2010/08/23/readme-driven-development.html) (RDD), or more generally, documentation driven development.
|
|
8
8
|
|
|
9
9
|
This module enables the `README.md` to be used for:
|
|
10
10
|
|
|
@@ -24,24 +24,23 @@ At its core, this library is a simple Svelte preprocessor.
|
|
|
24
24
|
1. Use the `svelte` entry defined in your project `package.json`
|
|
25
25
|
2. Use `README.md` as the Svelte source code
|
|
26
26
|
3. Parse Markdown using [Markdown It](https://github.com/markdown-it/markdown-it)
|
|
27
|
-
4.
|
|
27
|
+
4. Highlight code with a built-in highlighter (`svelte`, `typescript`/`javascript`, `json`, `yaml`, `bash`) and run `svelte` code fence blocks so that demos are juxtaposed with code
|
|
28
|
+
5. Style the result with [GitHub Markdown CSS](https://github.com/sindresorhus/github-markdown-css) to maintain a consistent look with [github.com](https://github.com/)
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
## Installation
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
- [PrismJS](https://github.com/PrismJS/prism)
|
|
35
|
-
- [GitHub Markdown CSS](https://github.com/sindresorhus/github-markdown-css)
|
|
32
|
+
```sh
|
|
33
|
+
npm install svelte-readme
|
|
34
|
+
```
|
|
36
35
|
|
|
37
36
|
## Usage
|
|
38
37
|
|
|
39
38
|
This library exports two methods:
|
|
40
39
|
|
|
41
|
-
- `
|
|
40
|
+
- `svelteReadme`: creates a Vite plugin for you
|
|
42
41
|
- `preprocessReadme`: standalone Svelte markup preprocessor
|
|
43
42
|
|
|
44
|
-
`
|
|
43
|
+
`svelteReadme` requires Svelte 5+ as a peer dependency. `preprocessReadme` has no such constraint. At a minimum, `package.json#svelte` and `package.json#name` are required.
|
|
45
44
|
|
|
46
45
|
**package.json**
|
|
47
46
|
|
|
@@ -49,119 +48,88 @@ This library exports two methods:
|
|
|
49
48
|
{
|
|
50
49
|
"name": "my-svelte-component",
|
|
51
50
|
"svelte": "./src/index.js",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
51
|
+
"type": "module",
|
|
52
|
+
"exports": {
|
|
53
|
+
".": "./src/index.js"
|
|
54
|
+
},
|
|
54
55
|
"scripts": {
|
|
55
|
-
"dev": "
|
|
56
|
-
"build": "
|
|
57
|
-
"
|
|
56
|
+
"dev": "vite",
|
|
57
|
+
"build": "vite build",
|
|
58
|
+
"preview": "vite preview"
|
|
58
59
|
},
|
|
59
60
|
"homepage": "https://github.com/metonym/svelte-readme"
|
|
60
61
|
}
|
|
61
62
|
```
|
|
62
63
|
|
|
63
|
-
**
|
|
64
|
-
|
|
65
|
-
The default export from "svelte-readme" will create a Rollup configuration used to develop and generate the demo.
|
|
66
|
-
|
|
67
|
-
```js
|
|
68
|
-
import resolve from "@rollup/plugin-node-resolve";
|
|
69
|
-
import svelte from "rollup-plugin-svelte";
|
|
70
|
-
import svelteReadme from "svelte-readme";
|
|
71
|
-
import pkg from "./package.json";
|
|
72
|
-
|
|
73
|
-
export default () => {
|
|
74
|
-
if (process.env.BUNDLE !== "true") {
|
|
75
|
-
return svelteReadme();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return ["es", "umd"].map((format) => {
|
|
79
|
-
const UMD = format === "umd";
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
input: pkg.svelte,
|
|
83
|
-
output: {
|
|
84
|
-
format,
|
|
85
|
-
file: UMD ? pkg.main : pkg.module,
|
|
86
|
-
name: UMD ? pkg.name : undefined,
|
|
87
|
-
},
|
|
88
|
-
plugins: [svelte(), resolve()],
|
|
89
|
-
};
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
```
|
|
64
|
+
**vite.config.ts**
|
|
93
65
|
|
|
94
|
-
|
|
66
|
+
`svelteReadme` is a standard Vite plugin factory: it returns `Plugin[]`, so it composes with the rest of your Vite config instead of replacing it.
|
|
95
67
|
|
|
96
68
|
```ts
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* set to `true` to minify the HTML/JS
|
|
100
|
-
* @default false
|
|
101
|
-
*/
|
|
102
|
-
minify: boolean;
|
|
69
|
+
import { svelteReadme } from "svelte-readme";
|
|
70
|
+
import { defineConfig } from "vite";
|
|
103
71
|
|
|
72
|
+
export default defineConfig({
|
|
73
|
+
plugins: [svelteReadme()],
|
|
74
|
+
server: { port: 3000 }, // passes through untouched
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## API
|
|
79
|
+
|
|
80
|
+
All properties are optional.
|
|
81
|
+
|
|
82
|
+
> [!NOTE]
|
|
83
|
+
> `svelteReadme` owns `build.outDir` (set via the `outDir` option below, not `build.outDir`) and `build.rollupOptions.input`/`appType`. If you set your own `build.rollupOptions` in `vite.config.ts`, the outcome depends on Vite's plugin `config` hook merge order — this is composable for fields `svelteReadme` doesn't touch, but not fully composable for the fields it does.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
interface SvelteReadmeOptions {
|
|
104
87
|
/**
|
|
105
88
|
* set the folder to emit the files
|
|
106
89
|
* @default "dist"
|
|
107
90
|
*/
|
|
108
|
-
outDir
|
|
91
|
+
outDir?: string;
|
|
109
92
|
|
|
110
93
|
/**
|
|
111
94
|
* custom CSS appended to the <style> block
|
|
112
95
|
* @default ""
|
|
113
96
|
*/
|
|
114
|
-
style
|
|
97
|
+
style?: string;
|
|
115
98
|
|
|
116
99
|
/**
|
|
117
100
|
* set to `true` to omit the default GitHub styles
|
|
118
101
|
* @default false
|
|
119
102
|
*/
|
|
120
|
-
disableDefaultCSS
|
|
103
|
+
disableDefaultCSS?: boolean;
|
|
121
104
|
|
|
122
105
|
/**
|
|
123
106
|
* value to prepend to relative URLs (i.e. GitHub repo URL)
|
|
124
107
|
* @default undefined
|
|
125
108
|
*/
|
|
126
|
-
prefixUrl
|
|
109
|
+
prefixUrl?: string;
|
|
127
110
|
|
|
128
111
|
/**
|
|
129
|
-
* `
|
|
130
|
-
*
|
|
112
|
+
* Called with the source of each `svelte` code fence before it's highlighted for display,
|
|
113
|
+
* so it can be pretty-printed with your own formatter (e.g. Prettier). The code fence is
|
|
114
|
+
* displayed unformatted if this is omitted or its result rejects/throws.
|
|
115
|
+
* @default undefined
|
|
131
116
|
*/
|
|
132
|
-
|
|
117
|
+
format?: (source: string) => string | Promise<string>;
|
|
133
118
|
|
|
134
119
|
/**
|
|
135
|
-
*
|
|
136
|
-
* @default {
|
|
120
|
+
* `@sveltejs/vite-plugin-svelte` options
|
|
121
|
+
* @default {}
|
|
137
122
|
*/
|
|
138
|
-
|
|
123
|
+
svelte?: VitePluginSvelteOptions;
|
|
139
124
|
|
|
140
125
|
/**
|
|
141
|
-
*
|
|
142
|
-
* @default
|
|
126
|
+
* Append content to the `head` element in `index.html`
|
|
127
|
+
* @default undefined
|
|
143
128
|
*/
|
|
144
|
-
|
|
129
|
+
head?: string;
|
|
145
130
|
}
|
|
146
131
|
```
|
|
147
132
|
|
|
148
|
-
## Limitations
|
|
149
|
-
|
|
150
|
-
### Comments in script blocks
|
|
151
|
-
|
|
152
|
-
Single line comments in Svelte script blocks are not supported.
|
|
153
|
-
|
|
154
|
-
Use multi-line comments instead.
|
|
155
|
-
|
|
156
|
-
```diff
|
|
157
|
-
- let toggled; // comment
|
|
158
|
-
+ let toggled; /** comment */
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
## Prior art
|
|
162
|
-
|
|
163
|
-
This project is inspired by [MDsveX](https://github.com/pngwn/mdsvex).
|
|
164
|
-
|
|
165
133
|
## Changelog
|
|
166
134
|
|
|
167
135
|
[CHANGELOG.md](CHANGELOG.md)
|
package/dist/button.css
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub Primer button CSS
|
|
3
|
+
* https://primer.style/css/components/buttons
|
|
4
|
+
**/
|
|
5
|
+
.code-fence button {
|
|
6
|
+
font-family: inherit;
|
|
7
|
+
text-transform: none;
|
|
8
|
+
position: relative;
|
|
9
|
+
display: inline-block;
|
|
10
|
+
padding: 5px 16px;
|
|
11
|
+
font-size: 14px;
|
|
12
|
+
font-weight: 500;
|
|
13
|
+
line-height: 20px;
|
|
14
|
+
white-space: nowrap;
|
|
15
|
+
vertical-align: middle;
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
user-select: none;
|
|
18
|
+
border: 1px solid;
|
|
19
|
+
border-radius: 6px;
|
|
20
|
+
appearance: none;
|
|
21
|
+
color: #24292e;
|
|
22
|
+
background-color: #fafbfc;
|
|
23
|
+
border-color: rgba(27, 31, 35, 0.15);
|
|
24
|
+
box-shadow:
|
|
25
|
+
0 1px 0 rgba(27, 31, 35, 0.04),
|
|
26
|
+
inset 0 1px 0 rgba(255, 255, 255, 0.25);
|
|
27
|
+
transition: background-color 0.2s cubic-bezier(0.3, 0, 0.5, 1);
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Claim = {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
className: string;
|
|
5
|
+
};
|
|
6
|
+
export type GapFill = (text: string) => string;
|
|
7
|
+
export declare function escapeHtml(text: string): string;
|
|
8
|
+
export declare function token(className: string, text: string): string;
|
|
9
|
+
export declare const baseTokenStyles: string;
|
|
10
|
+
export declare function renderClaims(source: string, claims: Claim[], gapFill: GapFill): string;
|
|
11
|
+
export declare function gapFill(text: string): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Claim } from "./shared.js";
|
|
2
|
+
export declare const styles: string;
|
|
3
|
+
export declare function codeGapFill(text: string): string;
|
|
4
|
+
export declare function collectLeafClaims(root: any, offset: number): Claim[];
|
|
5
|
+
export declare function highlightTypeScript(source: string): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { preprocessReadme } from "./preprocessReadme";
|
|
2
|
-
export {
|
|
1
|
+
export { preprocessReadme } from "./preprocessReadme.js";
|
|
2
|
+
export { svelteReadme } from "./svelteReadme.js";
|