Skip to content

Commit

Permalink
Merge branch 'main' of github.com:mattjennings/mdsvexamples into feat…
Browse files Browse the repository at this point in the history
…/wrapper-named-export
  • Loading branch information
mattjennings committed Aug 4, 2023
2 parents 5605e93 + 79c6883 commit 2b6757c
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 13 deletions.
1 change: 0 additions & 1 deletion .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
},
"npm": {
"publish": true,
"publishPath": "./package",
"tag": "latest"
},
"plugins": {
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@


## [0.4.0-beta.1](https://github.com/mattjennings/mdsvexamples/compare/0.3.4...0.4.0-beta.1) (2023-08-04)

### [0.3.4](https://github.com/mattjennings/mdsvexamples/compare/0.3.3...0.3.4) (2023-08-04)

### Bug Fixes
Expand Down Expand Up @@ -57,4 +61,4 @@

### [0.0.8](https://github.com/mattjennings/mdsvex-code-preview/compare/0.0.9...0.1.0-beta.0) (2022-03-27)

### [0.0.7](https://github.com/mattjennings/mdsvex-code-preview/compare/0.0.9...0.1.0-beta.0) (2022-03-25)
### [0.0.7](https://github.com/mattjennings/mdsvex-code-preview/compare/0.0.9...0.1.0-beta.0) (2022-03-25)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mdsvexamples",
"version": "0.3.4",
"version": "0.4.0-beta.1",
"files": [
"dist"
],
Expand Down
9 changes: 8 additions & 1 deletion src/lib/remark.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ export default function (options = {}) {
console.warn(`ExampleComponent is deprecated, use defaults.Wrapper instead`)
}

return function transformer(tree) {
return function transformer(tree, file) {
let examples = []

const filename = toPOSIX(file.filename).split(toPOSIX(file.cwd)).pop()

visit(tree, 'code', (node) => {
const languages = ['svelte', 'html']
/**
* @type {Record<string, any>}
*/
const meta = {
Wrapper: path.resolve(_dirname, 'Example.svelte'),
filename,
...defaults,
...parseMeta(node.meta || '')
}
Expand Down Expand Up @@ -166,3 +169,7 @@ function createExampleComponent(value, meta, index) {
<slot slot="code">{@html ${JSON.stringify(highlighted)}}</slot>
</Example>`
}

function toPOSIX(path) {
return path.replace(/\\/g, '/')
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
export let meta
</script>

<pre id="meta">
{JSON.stringify(meta)}
</pre>
2 changes: 1 addition & 1 deletion src/routes/tests/meta/array/+page.svx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```svelte example space=["hello", "world"] nospace=["hello","world"] Wrapper="../Wrapper.svelte"
```svelte example space=["hello", "world"] nospace=["hello","world"] Wrapper="../MetaWrapper.svelte"

```
3 changes: 3 additions & 0 deletions src/routes/tests/meta/filename/+page.svx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```svelte example Wrapper="../MetaWrapper.svelte"
<div>hello</div>
```
26 changes: 20 additions & 6 deletions src/routes/tests/meta/meta.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,28 @@ test('hideStyle', async ({ page }) => {

test('wrapper and custom meta', async ({ page }) => {
await page.goto('/tests/meta/wrapper')
await expect(page.locator(`text={"Wrapper":"../Wrapper.svelte","example":true}`)).toBeVisible()
const meta = await getMeta(page)

expect(meta.Wrapper).toBe('../MetaWrapper.svelte')
expect(meta.example).toBe(true)
})

test('array meta', async ({ page }) => {
await page.goto('/tests/meta/array')
await expect(
page.locator(
'text={"Wrapper":"../Wrapper.svelte","example":true,"space":["hello","world"],"nospace":["hello","world"]}'
)
).toBeVisible()

const meta = await getMeta(page)

expect(meta.space).toEqual(['hello', 'world'])
expect(meta.nospace).toEqual(['hello', 'world'])
})

test('filename meta', async ({ page }) => {
await page.goto('/tests/meta/filename')
const meta = await getMeta(page)

expect(meta.filename).toBe('/src/routes/tests/meta/filename/+page.svx')
})

async function getMeta(page) {
return JSON.parse(await page.locator('#meta').textContent())
}
2 changes: 1 addition & 1 deletion src/routes/tests/meta/wrapper/+page.svx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```svelte example Wrapper="../Wrapper.svelte"
```svelte example Wrapper="../MetaWrapper.svelte"

```
2 changes: 1 addition & 1 deletion src/routes/tests/meta/wrappers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import MetaWrapper from './Wrapper.svelte'
import MetaWrapper from './MetaWrapper.svelte'

export { MetaWrapper }

0 comments on commit 2b6757c

Please sign in to comment.