Skip to content

Commit

Permalink
fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TorstenDittmann committed Aug 15, 2023
1 parent 13d3318 commit ac88b56
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 101 deletions.
14 changes: 10 additions & 4 deletions apps/demo/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<script>
import { dev } from "$app/environment";
</script>

<header>
<nav>
<h1>svelte-markdoc-preprocess</h1>
<a href="/">usage</a> /
<a href="/svelte">svelte</a> /
<a href="/components">components</a> /
<a href="/markdown">markdown</a>
<a href="/">home</a> /
<a href="/docs">docs</a>
{#if dev}
/ <a href="/playground">playground</a>
{/if}
</nav>
</header>

<main>
<slot />
</main>
103 changes: 7 additions & 96 deletions apps/demo/src/routes/+page.markdoc
Original file line number Diff line number Diff line change
@@ -1,100 +1,11 @@
This is a [Svelte](https://svelte.dev) preprocessor that allows you to use Markdoc.
This library brings the power of [Markdoc](https://markdoc.dev/) right into your [Svelte](https://svelte.dev) applications!

## Usage

Install the package:

```bash
npm i -D svelte-markdoc-preprocess
```

Add the preprocessor and new extensions to your `svelte.config.js`:
```js
import { markdoc } from 'svelte-markdoc-preprocess';

const config = {
preprocess: [
vitePreprocess(),
markdoc({
layouts: {
default: join(
dirname(fileURLToPath(import.meta.url)),
'./src/lib/Layout.svelte'
)
}
})
],
extensions: ['.markdoc', '.svelte'],
};
```

And use them like this:

```md
<!-- +page.markdoc -->

# I am a heading

I am a paragraph with **bold** words. But you can also use Svelte Components:
```

## Layouts

You can define layouts in the `markdoc` options.

```js
// svelte.config.js
markdoc({
layouts: {
default: join(
dirname(fileURLToPath(import.meta.url)),
'./src/lib/Layout.svelte'
),
some_other_layout:join(
dirname(fileURLToPath(import.meta.url)),
'./src/lib/SomeOtherLayout.svelte'
)
}
})
```

Layout files are basically Svelte components with a slot.


```html
<!-- ./src/lib/Layout.svelte -->
<nav>
...
</nav>
<slot />
```

And use them in using the `layout` key in frontmatter. If no layout is defined with frontmatter, the default layout will be used.

```md
<!-- +page.markdoc -->
---
layout: some_other_layout
---

# some other content
```

## Components

You can export components from your used layout and use them in your Markdoc files.

```html
<!-- ./src/lib/Layout.svelte -->
<script context="module">
export { default as Addition } from './Addition.svelte';
</script>

<slot />
```

You can use the components from a layout file like this `{% addition a=4 b=6 %}`.
## Features
- **Markdoc**: Use the full power of Markdoc in your Svelte applications.
- **Components**: Access your Svelte components directly as Markdoc tags. No individual imports or configurations required.
- **Layouts**: Add a default and also named layouts.
- **Flexibility**: Configure Markdoc to your needs.

## Experimental

This is totally experimental for now, please don't use it *yet*. Even if you're a brave one.
This is totally experimental for now, please don't use it *yet*. Unless you're a brave one.
94 changes: 94 additions & 0 deletions apps/demo/src/routes/docs/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
## Usage

Install the package:

```bash
npm i -D svelte-markdoc-preprocess
```

Add the preprocessor and new extensions to your `svelte.config.js`:
```js
import { markdoc } from 'svelte-markdoc-preprocess';

const config = {
preprocess: [
vitePreprocess(),
markdoc({
layouts: {
default: join(
dirname(fileURLToPath(import.meta.url)),
'./src/lib/Layout.svelte'
)
}
})
],
extensions: ['.markdoc', '.svelte'],
};
```

And use them like this:

```md
<!-- +page.markdoc -->

# I am a heading

I am a paragraph with **bold** words. But you can also use Svelte Components:
```

## Layouts

You can define layouts in the `markdoc` options.

```js
// svelte.config.js
markdoc({
layouts: {
default: join(
dirname(fileURLToPath(import.meta.url)),
'./src/lib/Layout.svelte'
),
some_other_layout:join(
dirname(fileURLToPath(import.meta.url)),
'./src/lib/SomeOtherLayout.svelte'
)
}
})
```

Layout files are basically Svelte components with a slot.


```html
<!-- ./src/lib/Layout.svelte -->
<nav>
...
</nav>
<slot />
```

And use them in using the `layout` key in frontmatter. If no layout is defined with frontmatter, the default layout will be used.

```md
<!-- +page.markdoc -->
---
layout: some_other_layout
---

# some other content
```

## Components

You can export components from your used layout and use them in your Markdoc files.

```html
<!-- ./src/lib/Layout.svelte -->
<script context="module">
export { default as Addition } from './Addition.svelte';
</script>

<slot />
```

You can use the components from a layout file like this `{% addition a=4 b=6 %}`.
6 changes: 6 additions & 0 deletions apps/demo/src/routes/playground/+layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<nav>
<a href="/playground/components">components</a> /
<a href="/playground/markdown">markdown</a>
</nav>

<slot />
5 changes: 5 additions & 0 deletions apps/demo/src/routes/playground/+page.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { redirect } from '@sveltejs/kit';

export function load() {
throw redirect(307, '/playground/components');
}
File renamed without changes.
1 change: 0 additions & 1 deletion apps/demo/src/routes/svelte/+page.svelte

This file was deleted.

0 comments on commit ac88b56

Please sign in to comment.