astro-live-code
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "astro-live-code", | ||
"type": "module", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -21,5 +21,16 @@ import { visitParents as unistVisit } from 'unist-util-visit-parents' | ||
if (node.meta && node.meta.split(' ').includes('live')) { | ||
const isDiff = node.lang === 'diff' | ||
const lang = getLang(node) | ||
const meta = node.meta | ||
const src = node.value | ||
const src = isDiff | ||
? node.value | ||
?.split('\n') | ||
// filter out lines with leading - | ||
.filter((line) => !line.match(/^[-]/)) | ||
// remove leading + from lines | ||
.map((line) => line.replace(/^[+]/, '')) | ||
.join('\n') | ||
: node.value | ||
const i = examples.length | ||
@@ -39,3 +50,3 @@ | ||
'', | ||
)}-${exampleComponentName}.${node.lang}`, | ||
)}-${exampleComponentName}.${lang}`, | ||
) | ||
@@ -48,3 +59,3 @@ | ||
const wrapperFilename = wrapper | ||
? filename.replace(`.${node.lang}`, `.w.${node.lang}`) | ||
? filename.replace(`.${lang}`, `.w.${lang}`) | ||
: null | ||
@@ -62,3 +73,3 @@ | ||
src: createWrapperSrc({ | ||
lang: node.lang, | ||
lang, | ||
inner: filename, | ||
@@ -100,3 +111,3 @@ outer: wrapper, | ||
name: 'lang', | ||
value: node.lang, | ||
value: lang, | ||
}, | ||
@@ -358,2 +369,13 @@ // filename of the markdown file | ||
function getLang(node) { | ||
if (node.lang === 'diff') { | ||
const lang = node.meta.split(' ').find((part) => part.startsWith('lang=')) | ||
if (lang) { | ||
return lang.split('=')[1].slice(1, -1) | ||
} | ||
} | ||
return node.lang | ||
} | ||
function parsePropsFromString(string) { | ||
@@ -360,0 +382,0 @@ const regex = /props={{(.*?)}}/g |
17514
516