question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support for <kbd> and <samp>

See original GitHub issue

Hey, I really like Prism—you’ve done a good job and making it simple and “just work” (for the most part, which is must more than I can say about most software out there nowadays).

I had a thought, and I’m not 100% of my opinion on this, but… currently you only support <code>, which is completely correct for source code blocks. I was already using <pre><code> in fact.

But to be pedantic, HTML5 says we should use <kbd> for user input (such as the command-line stuff) and <samp> for program output. So for for programming language source code, we’re good, but for the command-line or sample output… HTML5 wants us to use other tags. See:

I know that <kbd> and <samp> aren’t widespread, and that everybody tries to cram everything like this into <code> (as I used to do), but what are your thoughts on supporting <kbd> and <samp> when it’s semantically appropriate?

Cheers,

Garret

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
LeaVeroucommented, Mar 4, 2018

Gawd I can’t wait for :matches(). Once :matches() is supported, that would just be:

Prism.hooks.add('before-highlightall', function (env) {
	env.selector += ", :matches([class*='lang-'], [class*='language-']) :matches(kbd, samp)";
});
0reactions
Golmotecommented, Mar 4, 2018

So the official way to do this is something along the lines of:

Prism.hooks.add('before-highlightall', function (env) {
	env.selector += ", [class*='lang-'] kbd, [class*='language-'] kbd" +
		", kbd[class*='lang-'], kbd[class*='language-']" +
		", [class*='lang-'] samp, [class*='language-'] samp" +
		", samp[class*='lang-'], samp[class*='language-']";
});

Alternatively, env.elements can be set directly to the set of elements that are to be highlighted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What are the differences between kbd, samp and code in HTML
I'm currently reading the HTML tutorial on w3schools (no CSS or JavaScript yet) and I wonder why are there so many different tags...
Read more >
Using HTML's kbd, samp and pre elements - Ian Devlin
As mentioned above, samp can be used with a kbd element to either represent input based on system output or input as echoed...
Read more >
Code and Keys in HTML: Using the code, var, samp and kbd ...
kbd. Used for keyboard commands and shortcuts: <p>To paste copied text content stripped of formatting ...
Read more >
Why do we need var,code,kbd,samp tags we can ... - Sololearn
Why do we need var,code,kbd,samp tags we can display the contents in other tag also??? · What is the missing · Hi I...
Read more >
What Are The Differences Between Kbd, Samp And Code In ...
HTML <em> <strong> <dfn> <code> <samp> <kbd> <var> <cite> tags Example Definition and Usage Browser Support Differences Between HTML and XHTML.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found