Skip to content
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

Adds data-lang attribute for CommonMark code block renderer #90

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

alexgarrettsmith
Copy link
Contributor

This PR adds a data-lang attribute to CommonMark code blocks, allowing an unobtrusive method of accessing the currently highlighted language for display purposes.

For example (in this case with Tailwind typography), the prose-pre:after:content-[attr(data-lang)] class could be used to style a pseudo element with the following result (top right):

Screenshot 2024-04-02 at 16 46 40

I've avoided adding this to pre output and InlineTheme output for simplicity, but happy to add this in if needed.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 8525924001

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 94.608%

Totals Coverage Status
Change from base Build 8522176271: 0.0%
Covered Lines: 1316
Relevant Lines: 1391

💛 - Coveralls

@aidan-casey
Copy link
Member

Thanks for the PR, @alexgarrettsmith!

@brendt, we should keep #81 in mind for this. If the alias is used, would the expected behavior be that the alias is set or the primary language key?

@brendt brendt mentioned this pull request Apr 3, 2024
5 tasks
@brendt
Copy link
Member

brendt commented Apr 3, 2024

If the alias is used, would the expected behavior be that the alias is set or the primary language key?

@aidan-casey for now I think this is fine. Languages currently don't define their own code(s), and we cannot change that without a breaking change. So using the language code directly is ok. I plan on changing this in the future.

I've avoided adding this to pre output and InlineTheme output for simplicity, but happy to add this in if needed.

@alexgarrettsmith This is actually a pretty big oversight on my part, because the theme itself has no idea about the current language. I can add an ugly string replace as a temporary fix within the common mark renderer, but I think I have a better idea (described in #91) This would require a breaking change though.

What I think I'll do is merge this in, and only have support for it on themes without WithPre. I don't scare away from tagging a new major quickly, so I'll probably have this fixed in v2 somewhere this week of next.

@brendt brendt merged commit a72b484 into tempestphp:main Apr 3, 2024
4 checks passed
@brendt
Copy link
Member

brendt commented Apr 3, 2024

@alexgarrettsmith
Copy link
Contributor Author

No worries @brendt, I noticed that the language wasn't available there which is why I didn't touch it — appreciate that you're heavily developing right now and didn't want to get in the way.

Appreciate the merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants