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

type attribute for the code element #38

Closed
vanillajonathan opened this Issue Apr 24, 2017 · 6 comments

Comments

Projects
None yet
2 participants
@vanillajonathan
Copy link

vanillajonathan commented Apr 24, 2017

Provide a lang attribute for the <code> element.

<code lang="python">
class Cat(object):
    def talk():
        """Make some noise."""
        print('Meow')
</code>

This would semantically declare the language of the code.
Which could be used to apply syntax highlighting.

@shaunix

This comment has been minimized.

Copy link
Contributor

shaunix commented May 1, 2017

The current way to do this is with the mime attribute, which takes a MIME type, e.g.:

<code mime="text/x-python">

This has proven itself cumbersome, because nobody can remember the MIME types, and most MIME types for programming languages are just made up and unregistered. In the future (possibly Mallard 1.1), we'll probably change this to the type attribute, just using a simple string like "python". See #21

@vanillajonathan

This comment has been minimized.

Copy link
Author

vanillajonathan commented May 1, 2017

Ah, the documentation mentioning the mime attribute is here:
http://projectmallard.org/1.0/mal_block_code

I did miss it because I didn't see it on the learning page:
http://projectmallard.org/about/learn/code

Wikipedia which is powered by MediaWiki uses the SyntaxHighlight extension which does syntax highlighting using the lang attribute. It is powered by Pygments.
It also have a line attribute to indicate that the lines should be numbered.

Wikipedia, GitHub, and Disqus uses simple strings like "python".

@shaunix shaunix changed the title Lang attribute for the code element type attribute for the code element May 12, 2017

@shaunix shaunix self-assigned this May 12, 2017

@shaunix shaunix added the NeedsMEP label May 12, 2017

@shaunix shaunix added this to the 1.1 milestone May 12, 2017

@shaunix

This comment has been minimized.

Copy link
Contributor

shaunix commented Aug 31, 2017

@vanillajonathan

This comment has been minimized.

Copy link
Author

vanillajonathan commented Aug 31, 2017

I would rather see the attribute be named lang than type.

The SyntaxHighlight extension for MediaWiki uses lang for the attribute name.

@shaunix shaunix added HasSpec and removed NeedsSpec labels Jan 12, 2019

@shaunix

This comment has been minimized.

Copy link
Contributor

shaunix commented Jan 12, 2019

I noted the request for a lang attribute in the Alternatives section of the MEP. I think it's confusing with the same-named attribute used for human languages in various formats (namedspaced or not). I really want to take advantage of Ducktype's shorthand syntax, and I want to do something similar to replace the mime attribute on media elements in 1.2.

@shaunix shaunix closed this Jan 12, 2019

@vanillajonathan

This comment has been minimized.

Copy link
Author

vanillajonathan commented Jan 13, 2019

Good point @shaunix, as you said; the lang attribute is usually used for human language.
The type attribute is actually a good choice, since it is used for MIME type in the script element as well as the link element.

Example:

<script type="text/javascript" src="script.js"></script>
<link rel="stylesheet" type="text/css" href="theme.css">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment