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

Highlight Inline Code Blocks #599

Closed
andreas-mausch opened this issue Aug 14, 2022 · 7 comments · Fixed by #616
Closed

Highlight Inline Code Blocks #599

andreas-mausch opened this issue Aug 14, 2022 · 7 comments · Fixed by #616
Labels

Comments

@andreas-mausch
Copy link

andreas-mausch commented Aug 14, 2022

Hi, the default language works well for normal code blocks (triple ```).

However, for

`inline code`

the code is rendered as

<code>...</code>

instead of

<code class="language-default">...</code>
@jGleitz
Copy link
Owner

jGleitz commented Aug 23, 2022

This plugin currently does not target inline code at all.

To clarify: Would you like to have just the defaultLanguage functionality for inline code? Or all the functionality?

@andreas-mausch
Copy link
Author

This plugin currently does not target inline code at all.

Oops, thanks for pointing that out.

Would you like to have just the defaultLanguage functionality for inline code? Or all the functionality?

Best case all functionality. That would be great.
(I currently use a workaround for inline code mentioned in 11ty/eleventy-plugin-syntaxhighlight#38 (comment))

@jGleitz
Copy link
Owner

jGleitz commented Aug 23, 2022

Alright. So let’s teach this plugin to optionally also target inline code ✔️.

@jGleitz jGleitz changed the title Set default language on inline code blocks Highlight Inline Code Blocks Aug 23, 2022
jGleitz added a commit that referenced this issue Aug 29, 2022
@jGleitz
Copy link
Owner

jGleitz commented Aug 29, 2022

@andreas-mausch highlighting inline code is implemented in #616. Can you please give feedback on it?

In particular, what’s your take on the syntax

`class Demo { };`{language=cpp}

to specify the language for inline code? I’d like to make sure the syntax makes sense & is usable before merging, as changing it afterwards would be a breaking change.

jGleitz added a commit that referenced this issue Aug 29, 2022
@andreas-mausch
Copy link
Author

Hi, your change works great!
Only "issue": I didn't have to set the option highlightInlineCode explicitly. Seems like the value is ignored.

The default language was successfully set on the code tag. 👍

what’s your take on the syntax

I think it looks great. Easy to understand.
I'm just curious if that is compatible with https://github.com/arve0/markdown-it-attrs.
If yes, perfect.

For my personal requirements the default language should be good enough though.
Quick test with markdown-it-attrs (defaultLanguage is set to plain):

// Works:
`class Demo { };`{language=cpp}
// = <code class="language-cpp">

// Also works:
`class Demo { };`{data-myattr=value}
// = <code data-myattr="value" class="language-plain">

// This is not rendered as expected:
`class Demo { };`{language=cpp, data-myattr=value}
// Rendered: <code data-myattr="value" class="language-plain">
// Expected: <code data-myattr="value" class="language-cpp">

I wonder if the last case is really needed. I do not need it.
I use attrs to specify a filename on a code block with three backticks:

```js {data-filename=test.js}

but for inline code I don't need it.

Thank you very much for your effort.
If you accept donations, please let me know.

jGleitz added a commit that referenced this issue Aug 30, 2022
jGleitz added a commit that referenced this issue Aug 30, 2022
@jGleitz
Copy link
Owner

jGleitz commented Aug 30, 2022

Thank you very much for your detailed feedback!

I didn't have to set the option highlightInlineCode explicitly.

Yep, that was an oversight. I fixed it & added a test case.

I think [the syntax] looks great. Easy to understand.

Great, so I’ll merge it that way.

I'm just curious if that is compatible with https://github.com/arve0/markdown-it-attrs.

I think it is, see below.

// This is not rendered as expected:

This renders exactly like I intended it to. My intention was to not introduce additional syntax to markdown-it, but rather freeload on the existing markdown-it-attrs syntax. This effectively makes language a special attribute for inline code to define the desired language. Hence, the language attribute works differently than normal with markdown-it-attrs. However, language is not a valid HTML attribute, so I figured nobody would mind.

Alternatively, I could have mandated the syntax

`class Demo { };\`{.language-cpp}

However, I find this awkward. First, it is less intuitive, and second, if the lang-prefix setting in markdownIt was changed, one would have to update all the language specifications.

If you accept donations, please let me know.

I don’t. But if you had the chance to give a little to UNHCR instead, that’d be a great reward for me!

jGleitz added a commit that referenced this issue Aug 30, 2022
github-actions bot pushed a commit that referenced this issue Aug 30, 2022
# [2.3.0](v2.2.5...v2.3.0) (2022-08-30)

### Features

* highlight inline code [#599](#599) ([e7c91ac](e7c91ac))
@github-actions
Copy link

🎉 This issue has been resolved in version 2.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

andreas-mausch added a commit to andreas-mausch/eleventy-sample that referenced this issue Aug 31, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants