Markdoc support #394
Replies: 11 comments
|
Astro/Markdoc/Expressive Code is something I was working on this weekend. Although not elegant, I figured it out how to make it work(ish) - at least for the language, code, title, and frame options. I wrote a blog post on how to get it working: https://amandaguthrie.dev/post/astro-markdoc-expressive-code-1/ - the site is using what I outlined in the post. There were 2 parts between Markdoc, Astro's Markdoc, and Expressive Code that were the main snags.
I looked at the I'm going to test line highlighting and other options and see if it can all be used by creating custom attributes. Will update if I find anything interesting. If there's any other information I can contribute here, in Astro's repo, or elsewhere, please let me know. Would love to see these three tools working in harmony! ❤️🔥 |
|
I made myself a component here: https://github.com/Princesseuh/erika.florist/blob/main/src%2Fcomponents%2Fcontent%2FCode.astro |
|
thanks a lot @Princesseuh @amandaguthrie !! it works but official support would be awesome |
|
I overrid the +astro-expressive-code did the job |
|
@jasikpark can you also share the Code.astro component ? |
|
lol i forgot it's @Princesseuh's perfect Code component 💖 |
|
@jasikpark so when you add a code block you are passing title like : |
|
oooh nope, never figured that part out. |
|
@jasikpark found a hacky way, is this even acceptable 😆 check the first line of the code block in the Code.astro : ---
import { Code } from 'astro-expressive-code/components'
const { content } = Astro.props
const inputString = Astro.props['data-language'] || 'txt'
const parts = inputString.split('|')
const parsedResult = parts.map((part) => {
if (part.startsWith('[') && part.endsWith(']')) {
return part.slice(1, -1).split(',')
} else if (part.startsWith('{') && part.endsWith('}')) {
const content = part.slice(1, -1)
if (content.includes(',')) {
return content.split(',').map((item) => Number(item))
} else {
return Number(content)
}
} else {
return part
}
})
const [lang, title, mark, ins, del] = parsedResult
---
<Code
code={content}
title={title ?? undefined}
mark={mark ?? undefined}
del={del ?? undefined}
ins={ins ?? undefined}
frame="auto"
lang={lang ?? undefined}
/>markdoc.config.mjs : fence: {
render: component('./src/components/Code.astro'),
attributes: {
...nodes.fence.attributes,
content: { type: String },
},
},test.mdoc : ```cpp|test.cpp|{2,4}|{6}|{7}
void DelayedExecutor::delayedExecute(const QString &udi) {
Solid::Device device(udi);
QString exec = m_service.exec();
MacroExpander mx(device);
mx.expandMacros(exec);
KRun::runCommand(exec, QString(), m_service.icon(), 0);
deleteLater(); }```Demo :
|
|
@amandaguthrie maybe you can improve this even further ? |
|
Hello! We are moving feature requests and support questions to discussions and using issues only for bugs to help better track those going forward. See you in the Discussions tab! |

Uh oh!
There was an error while loading. Please reload this page.
Markdoc isn't terribly popular, nonetheless it would be neat to have Markdoc support for this! Especially in Astro, this is one of the few things that doesn't work.
All reactions