Skip to content

Different Markdown options based on content language? #2891

Answered by rothsandro
saadatm asked this question in Q&A
Discussion options

You must be logged in to vote

Maybe you could create a wrapper around markdown-it and provide your wrapper to Eleventy?

const markdownIt = require("markdown-it");

module.exports = function (eleventyConfig) {
  const libEnglish = markdownIt({ html: true });
  const libUrdu = markdownIt({ html: false });

  eleventyConfig.setLibrary("md", {
    ...libEnglish,
    render: (content, ctx) => {
      const lib = ctx.lang === "urdu" ? libUrdu : libEnglish;
      return lib.render(content, ctx);
    },
  });
};

The ctx variable gives you access to front matter data and other props like inputPath that you can use to determine the language. Beside the render property there are one or two other props that Eleventy uses (as far …

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
6 replies
@saadatm
Comment options

@darthmall
Comment options

@pdehaan
Comment options

@darthmall
Comment options

@saadatm
Comment options

Comment options

You must be logged in to vote
2 replies
@pdehaan
Comment options

@saadatm
Comment options

Answer selected by saadatm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants