Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add processing of inline code in Markdown #38

Open
sashaqred opened this issue Oct 30, 2020 · 6 comments
Open

Add processing of inline code in Markdown #38

sashaqred opened this issue Oct 30, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@sashaqred
Copy link

Hi,

Recently I've tried writing some code with 11ty in markdown and faced with something unexpectable. With block code, everything works fine. But inline code is not.

This code
image

will be transformed into this:

image

Seems like inline code isn't processed at all. On block code result there are bunch of extra classes but on inline none of them.

As temporal fix I'm using HTML in markdown (<code class="language-">Some inline code with custom wrap</code>).

Is this a bug or my misconfiguration?

@lautarodragan
Copy link

I'm interested in this too. Haven't found a way to process inline code blocks yet.

@sashaqred
Copy link
Author

@lautarodragan, I think it is possible to automate only with a custom instance of markdownIt.

I use that function:
https://github.com/sashaqred/sashaqred/blob/d165371710e059e01c6103405d8e998e4c5c938e/src/_markdown-it/index.js#L9-L12

@lautarodragan
Copy link

Thanks @sashaqred !! That worked 😄

@zachleat zachleat added open-question Further information is requested from the original poster. enhancement New feature or request and removed open-question Further information is requested from the original poster. labels Jun 28, 2022
@markmichon
Copy link

markmichon commented Feb 9, 2023

To build on @sashaqred's example in case anyone else runs into it, markdownit's default inline rule escapes the HTML, so if you don't also do so you may run into issues when using things like < in your inline-code blocks. Here's a modification using markdown-it's escapeHtml library.

// setup

const markdownIt = require("markdown-it");
const mdSetup = markdownIt({ html: true})

// The important part below. Replace mdSetup with your instance of markdownit,
// and replace attributes and classes as needed.

mdSetup.renderer.rules.code_inline = (tokens, idx, { langPrefix = "" }) => {
  const token = tokens[idx];
  return `<code class="${langPrefix}">${mdSetup.utils.escapeHtml(token.content)}</code>`;
};

@sashaqred
Copy link
Author

@markmichon, good catch!

Recently I've faced such an issue. Your comment saved some time for me 😅

@Dinhero21
Copy link

I used markdown-it with markdown-it-highlightjs with this style. It looks a bit weird because it will guess the language when inline but you can just turn off auto.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants