-
-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to use a different markdown library based on layout? #1626
Comments
Pretty sure that isn't possible (and not sure how eleventy would know which renderer to use for markdown). Possible workaround is to just created a paired shortcode which wraps markdown-it and then just toggle between the default layout and a custom typographer layout. Repo: https://github.com/pdehaan/11ty-md-layout-1626 // .eleventy.js config file
const markdownIt = require( "markdown-it" );
const mdLib = markdownIt( {
typographer: true,
quotes: '“”‘’',
html: true,
} );
module.exports = eleventyConfig => {
// eleventyConfig.setLibrary( "md", mdLib);
eleventyConfig.addPairedShortcode("typographer", (content) => mdLib.renderInline(content));
return {
dir: {
input: "src",
output: "www"
}
};
}; Base layout is in ./src/_includes/layouts/base.liquid: <!DoCtYpE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>{{ title }}</title>
</head>
<body>
<main>
{{ content }}
</main>
</body>
</html> Custom typographer layout extends our base layout and uses the custom ---
layout: layouts/base.liquid
---
<div class="typographer">
{% typographer %}{{ content }}{% endtypographer %}
</div> src/pages/two.md can specify the custom "layouts/typographer.liquid" layout from the ./src/_includes/ directory: ---
title: two (custom)
layout: layouts/typographer.liquid
---
<div>
Hello, my name is "Peter".
They're a "nice" thing.
</div> And finally, the output is: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>two (custom)</title>
</head>
<body>
<main>
<div class="typographer">
<div>
<p>Hello, my name is “Peter”.</p>
<p>They’re a “nice” thing.</p>
</div>
</div>
</main>
</body>
</html> |
As for how it would work, I had thought of calling The paired shortcode is a good idea though; I'll give it a try tomorrow, thanks.
|
I think internally the Markdown template engine uses markdown-it's
But I think the feature you might be requesting is #117. Typography can potentially lead to some interesting problems though. One thing I guess I never tested for, was if you had quotes around an HTML tag's attributes. You'd want those to be straight quotes and not smart quotes. But in other places within the document where the single/double quotes appear within text blocks, you'd want to use smart quotes instead. |
Apologies for not replying a lot sooner, but just to let you know, your paired shortcode did the trick, thanks @pdehaan !
If you add html in the markdown file along the lines of Thanks again |
In the docs, you can supply your own markdown library instance like so:
Is it possible to do something like this, but only for specific layouts? For example, I have a
default
layout, which keeps straight quotes etc, and afancy
layout which converts to typographic quotes and all that jazz.As far as I can tell it's for all markdown files or nothing
Thanks
The text was updated successfully, but these errors were encountered: