carpentries / styles

Styles for The Carpentries lessons. No README to avoid merge conflicts with lessons. Demo 👇
https://carpentries.github.io/lesson-example
Other
84 stars 96 forks source link

"title" attribute for code blocks #632

Closed tkphd closed 2 years ago

tkphd commented 2 years ago

Code blocks currently show the language as the block title. In many places, the code block represents the contents of a file, and having that filename printed in the title-block would be great.

Kramdown provides the title attribute, e.g.,

~~~
import numpy as np
~~~
{: .language-python title="script.py"}

which ought to render the block with "script.py" as the title, and with Python syntax highlighting. However, my efforts to invoke this functionality have been unsuccessful. Am I just doing it wrong, or is this something The Carpentries' remote Jekyll theme can address using CSS?

zkamvar commented 2 years ago

The reason why this approach is not working is two-fold:

  1. The language displayed on the code blocks is the result of the ::before CSS pseudo-element, meaning that they are entirely visual decoration since pseudo-elements are computed after the HTML document is loaded.
  2. The title element is the text that displays when you hover over an element on a webpage (An example is a persistent feature of XKCD cartoons that adds an additional punchline to the comics https://xkcd.com/927/). The kramdown implementation is specific for their block quotes, but they do not appear to have specifications for code blocks.
tkphd commented 2 years ago

haaaaaaa... OK then.