oleeskild / digitalgarden

275 stars 158 forks source link

Build Error with Code Blocks in Markdown Files for Eleventy #204

Closed thewronghand closed 10 months ago

thewronghand commented 11 months ago

Hello,

I'm facing an issue with Eleventy when building markdown files containing code blocks. Below is a detailed breakdown:

Problem:

When there's a code block (wrapped with ```) in an md file, a build error occurs. Here's a snippet of the error message I encountered:

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] 1. Having trouble rendering njk template ./src/site/notes/index.md (via TemplateContentRenderError)
[11ty] 2. (./src/site/notes/index.md) [Line 21, Column 25]
[11ty]   expected variable end (via Template render error)
[11ty] 
[11ty] Original error stack trace: Template render error: (./src/site/notes/index.md) [Line 21, Column 25]
[11ty]   expected variable end

The content in the problematic line 21 is:

import { motion } from 'framer-motion';

function FadeInComponent() {
  return (
    <motion.div
      initial={{ opacity: 0 }}
      animate={{ opacity: 1 }}
      transition={{ duration: 1 }}
    >
      I will fade in!
    </motion.div>
  );
}

It seems that the part initial={{ opacity: 0 }} from line 21 is causing the issue.

I suspect that the content within the code block is being interpreted by Nunjucks, which is leading to the problem. When I wrapped the content with the raw tags, the build was successful.

However, manually adding raw tags for every code block in my Obsidian markdown files would be inefficient. So, I attempted to modify the .eleventy.js configuration to automatically wrap code blocks in markdown files with raw tags. However, being unfamiliar with Eleventy, I'm uncertain if I've written the code incorrectly or if my approach to the issue itself is flawed. I'm still encountering the same error on line 21.

I would appreciate any insights or solutions to resolve this issue. Thank you for your assistance.

dayne commented 10 months ago

Odd. I use code blocks regularly and never run into an issue.

Is this still an issue? Have you updated to the latest version of the template?

Can you share the code block causing this issue?

oleeskild commented 10 months ago

This was fixed in a recent version of the template. The problem was that text inside curly brackets, {{...}}, would be interpreted as a nunjuck variable. (Nunjuck is the templating language we are using). It would then thriw an error if it couldn't find the variable.

This should no longer be the case. Try updating the template and see if that fixes it