import { kebabCase } from 'scule'
const SELF_CLOSING_TAG_REGEX = /<([^\s>]+)([^>]+)\/>/g
const OPEN_TAG_REGEX = /<([^\s>]+)/g
const CLOSE_TAG_REGEX = /<\/([^\s>]+)/g
export function transformExampleMarkup(raw: string) {
let output = raw
let content: RegExpMatchArray | null = null
if ((content = raw.match(/([\s\S]*?)/))) {
const kebabContent = content[1]
.replaceAll(SELF_CLOSING_TAG_REGEX, (substring, tag) => {
return substring.replace('/>', `>${tag.trim()}>`)
})
.replaceAll(OPEN_TAG_REGEX, (substring) => {
return `<${kebabCase(substring.substring(1).trim())}`
})
.replaceAll(CLOSE_TAG_REGEX, (substring) => {
return `${kebabCase(substring.substring(2).trim())}`
})
.replaceAll(''', '\'')
output = output.replace(content[1], kebabContent)
}
return output
}
export function transformSlots(source: string, condition: string = '') {
if (source.includes('') && source.includes('')) {
return `${source}`
.replace(
``,
`\n`,
)
.replace(``, `
\n`)
.replace(
``,
`\n`,
)
.replace(``, `\n`)
}
if (source.includes('')) {
return `${source}`
.replace(
``,
`\n`,
)
.replace(
``,
`
\n\n`,
)
}
if (source.includes('')) {
return `${source}`
.replace(
``,
`\n`,
)
.replace(
``,
`\n\n`,
)
}
return (
`${source}`
+ ``
+ ``
)
}