11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.

Home Page:https://www.11ty.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When replacing built-in Markdown engine, permalinks in frontmatter are processed as Markdown

danburzo opened this issue · comments

Operating system

macOS Ventura 13.1

Eleventy

^2.0.0-beta.2 / 1.0.2

Describe the bug

Found while poking around replacing the built-in Markdown engine (see #2777) that when setting a replacement with .addExtension('md', { ... }), as exemplified in the docs, any explicit permalinks present in the frontmatter of .md sources will get processed with the replacement engine, as observed a while back (#1019).

This is a problem because most Markdown processors (including marked and remark) will wrap a plain string such as /path/to/output/ in <p> tags, thus breaking the output. I'm not sure if the default engine skips the Markdown step or whether markdown-it simply doesn't wrap a plain string, but the issue only manifests when changing to a different engine.

Reproduction steps

Eleventy config:

const marked = require('marked');
module.exports = config => {
	config.addExtension("md", {
		compile: inputContent => data => marked.parse(inputContent)
	});
};

Content file:

---
title: Hello world
permalink: hello-world/
---

## Heading

Paragraph.

Running Eleventy outputs the HTML to _site / <p>hello-world / < / p>.

Expected behavior

If permalinks passing through the Markdown engine is inevitable, it would be great to get enough arguments to the compile() function for authors to be able to discern when to skip Markdown processing.

Reproduction URL

No response

Screenshots

No response

The workaround is to use the compileOptions.permalink option, which can be set to "raw" in case all permalinks in the project are static.

For dynamic permalinks, the solution depends on a fix to #2777, as they are not currently pre-processed with Liquid/Nunjucks when the Markdown template engine is swapped.

I think a very good case can be made to make the default raw and encourage permalink callback functions in custom syntaxes by default!