-
Notifications
You must be signed in to change notification settings - Fork 385
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
Add support for shebang style code blocks. #142
base: master
Are you sure you want to change the base?
Conversation
If the flag is enabled, a block like this: #!ruby puts "hello world" Is stripped of the shebang line, and the language is treated the same as with a fenced code block.
It would be nice if this allowed real hashbangs: #!/usr/bin/env ruby
puts ARGF[1] |
@gampleman I considered that, but then it gets pretty messy, imagine if
Suddenly this is pretty hard to figure out. |
@jnicklas, for the record, that doesn't even work. Shebang lines are limited to a single argument. |
I think that a simple heuristic for figuring this out is this:
Where words are tokens separated by whitespace. |
Also to address more the whole issue rather than this specific point, I would be in favor of this proposal if the hashbang line was rendered as well; that is, it would simply trigger the syntax highlighter but still it would be also passed to the final document. Why? While I'm not a huge fan of code fences myself, I'm even less for yet another fracturing in the way Markdown is rendered and this proposal AFAIK isn't implemented in any other implementation. While adding tweaks like syntax highlighting enhances the output, having hashbangs render in some implementations and not render in others seems like a major pain. |
@gampleman: that would obviously be easy to change, but it would leave the status quo that code fences provide a feature that can't be achieved through indentation. My intention is to find a solution which looks good both as plain text, and as rendered text. If this looks worse than fenced blocks when rendered (due to the added shebang) then it isn't worthwhile. I don't want to fracture Markdown either, but does that mean innovation is impossible, since there is no body which has responsibility for the format? |
Kind of. But then you still have the problem of code fences having the one up, what if you actually want a shebang at the top of the code? (Quite common, imho). An alternative solution is simply to turn on syntax highlighting for all code blocks and use language auto detection (for which shebangs certainly help). |
@gampleman in UNIX, shebangs must be absolute paths, that is, they must start with a slash. In other words, this syntax ignores actual shebangs. So this would only be relevant if someone starts a code block with a shebang for another reason than it being part of a script, which I can't imagine is too common. |
@jnicklas Maybe you can ask here: https://github.com/hoedown/hoedown |
If the MKDEXT_SHEBANG_CODE flag is enabled, a block like this:
Is stripped of the shebang line, and the language is treated the same as with a fenced code block.
This was born out of a discussion on Twitter, where I was whining about the fact that syntax highlighting on @github requires the use of fenced code blocks. I hate fenced code blocks, so I wanted an equivalent syntax for indented code blocks. After a brief discussion with @ryanb, @searls, @tpope and a few others, we all felt that this syntax was the nicest.
Does this project have any tests? I couldn't find any. If so, I'd be happy to add tests for this functionality. I used this file as test input. Attached at the link is also output with the flag enabled and disabled.
I tried to be as conservative as possible in what is allowed as a shebang line. I'm total C newb though, so I have no idea if I've missed anything important.