Fermain / -mollify

9 stars 9 forks source link

Feature codeblock copy #168

Closed StianSto closed 9 months ago

StianSto commented 10 months ago

so this is at least a viable product, but we might want to discuss if it is good enough or not. i have tried several plugins, mdsvex custom components, but no luck there. this however does work, but requires an import in the markdown file.

how it works: i have made a custom and basic remark plugin that retrieves codeblocks from the AST and returns the CodeBlock from SkeletonUI. this is the reason we need that import in the markdown file.

the final result will look something like this: Screenshot 2023-09-13 205729

let me know if you have an idea on how to improve this! 😄

Fermain commented 10 months ago

I've got an issue here testing with a real lesson. Multi-line code blocks break the Component attribute

Fermain commented 10 months ago
file: /Users/oliver/Repos/Noroff/Content/-mollify/packages/lms/src/routes/content/feu1/javascript-1/module-3/more-about-apis/+page.md:89:13
 87 |  <CodeBlock language="js" code={`const key = '12345abcdef';
 88 |  
 89 |  const url = `https://api.spoonacular.com/recipes/716429/information?apiKey=${key}&includeNutrition=true`;
                    ^
 90 |  
 91 |  async function getData(url) {
error during build:
ParseError: Expected }
Fermain commented 9 months ago

I missed the import, can we do this in Layout?

Edit: No, I'm not sure how to solve this

StianSto commented 9 months ago

i have now added an automatic import for components being used in a markdown file. i had to make a merge script plugin, because svelte does not like multiple script tags :/ im wondering if it would be better to just make a barrel import that import all components, regardless if they are being used or not?

StianSto commented 9 months ago

do not merge yet! i believe i have finally figured out a much much better way to solve this, using mdsvex own custom components :) finally began to understand their docs. to be fair, their examples are lacking...

StianSto commented 9 months ago

and there we go, no script shenanigans needed 😄 With this it is also possible to easily create other custom components like tooltips, modals, quizblocks. the sky is the limit.

Fermain commented 9 months ago

and there we go, no script shenanigans needed 😄 With this it is also possible to easily create other custom components like tooltips, modals, quizblocks. the sky is the limit.