Skip to content

Commit d325cf9

Browse files
committed
Add readme
1 parent 9cee8cc commit d325cf9

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# svelte-shortcodes
2+
3+
Embed Svelte components inside rich content from any CMS using shortcodes. A
4+
concept we have shamelessly stolen [from WordPress](https://codex.wordpress.org/Shortcode_API).
5+
6+
You can also use this module to replace matching html elements with a custom
7+
Svelte component of your choice.
8+
9+
## Installation
10+
11+
```sh
12+
yarn add --dev svelte-shortcodes # or npm i --save-dev svelte-shortcodes
13+
```
14+
15+
## Usage
16+
17+
The Shortcodes component will replace every occurrence of the component `name`
18+
with a Svelte component of your choice. Both WordPress-style shortcodes and the
19+
html tag names will be replaced.
20+
21+
```
22+
<script>
23+
import { Shortcodes } from "svelte-shortcodes";
24+
import Heading from "./Heading.svelte";
25+
import ResponsiveImage from "./ResponsiveImage.svelte";
26+
27+
let markup = `
28+
[heading]Heading[/heading]
29+
<img src="logo.png" alt="Svelte logo">
30+
<p>Text...</p>
31+
`;
32+
33+
// { [name: string]: Component }
34+
let components = {
35+
heading: Heading,
36+
img: ResponsiveImage
37+
};
38+
</script>
39+
40+
<Shortcodes {components} {markup} />
41+
```
42+
43+
Checkout the code inside `/dev` for a full example.
44+
45+
## Development
46+
47+
There is a dev app available inside the `/dev` folder that can be used for
48+
testing and experimenting with the components. To start it simply run:
49+
50+
```sh
51+
yarn dev # or npm run dev
52+
```
53+
54+
## Todo
55+
56+
- [ ] Add tests
57+
- [ ] Consider separating html tag names from shortcodes
58+
- [ ] Find a better way to handle html fallback ([relevant svelte issue](https://github.com/sveltejs/svelte/issues/2324))

0 commit comments

Comments
 (0)