threepointone/markdown-in-js

Parameterize `markdown`

Closed this issue · 4 comments

It would be really cool if you could call this:

markdown`foo ${bar}`
markdown({ p: ParagraphComponent })`foo ${bar}`

this way:

markdown(['foo '], bar)
markdown({ p: ParagraphComponent })(['foo '], bar)

Then you could could pass the actual markdown content as parameters if you wanted to reuse the same customized component object. Does that make sense? I'm not sure if this is even possible with tagged template literals.

I mean, it wouldn't be a tagged literal at that point, and it makes analysis/transforming a lot tougher. But I'd recommend you just use a shared object

let params = { p: ParagraphComponent }

markdown(params)` some content `
// ...
markdown(params)` some other content `

feel free to carry on the conversation, and reopen if I've misunderstood

I was coming at it from another direction:

export const content = `
# Some markdown
`

export const content2 = `
# Some other markdown
`
// another file
import { content } from 'file'

markdown({ p: ParagraphComponent })`${content}`

So the MD string that gets passed into markdown could be a variable, but that doesn't seem to work.

yeah this lib is a static transform and doesn't do runtime parsing, you'd have more luck with a lib like https://www.npmjs.com/package/marksy

Ah, ok. I think I'll just have to be limited to that, as I'm using next.js. Thanks for the response!