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

Add support for shebang style code blocks. #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jnicklas
Copy link

If the MKDEXT_SHEBANG_CODE 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.

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.

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.
@gampleman
Copy link

It would be nice if this allowed real hashbangs:

    #!/usr/bin/env ruby 
    puts ARGF[1]

@jnicklas
Copy link
Author

@gampleman I considered that, but then it gets pretty messy, imagine if ruby had taken an argument:

#!/usr/bin/env ruby -w

Suddenly this is pretty hard to figure out.

@tpope
Copy link

tpope commented Nov 20, 2012

@jnicklas, for the record, that doesn't even work. Shebang lines are limited to a single argument.

@gampleman
Copy link

I think that a simple heuristic for figuring this out is this:

  1. If 1 word, then split on / and take last token.
  2. If 2 words:
    • If second word starts with -, use first word and do 1.
    • Otherwise use second word.
  3. If more words, fail.

Where words are tokens separated by whitespace.

@gampleman
Copy link

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.

@jnicklas
Copy link
Author

@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?

@gampleman
Copy link

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).

@jnicklas
Copy link
Author

@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
Copy link
Author

jnicklas commented Feb 5, 2014

Hello guys, I know there is some grand plan to transition off of sundown at @github, but it is currently still in use right? @vmg, any chance that @github could support this syntax? I write a lot of README files and this would clean them up quite nicely.

@FSX
Copy link
Contributor

FSX commented Feb 5, 2014

@jnicklas Maybe you can ask here: https://github.com/hoedown/hoedown

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