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

Syntax highlighting does not work with fenced (~~~) code blocks #537

Closed
sol opened this issue Oct 12, 2012 · 14 comments
Closed

Syntax highlighting does not work with fenced (~~~) code blocks #537

sol opened this issue Oct 12, 2012 · 14 comments
Assignees
Labels
Milestone

Comments

@sol
Copy link

sol commented Oct 12, 2012

If I use something like

~~~ {.haskell}
main :: IO ()
main = putStrLn "hello, world!"
~~~

I would like to get syntax highlighting for Haskell code.

My motivation to use this over

```haskell
...
```

is that it is compatible with other software, and it allows me to add several classes to a single code block (e.g. ~~~ {.haskell .literate}).

BTW: GFM and GitHub's README renderer do the right thing here.

@ghost
Copy link

ghost commented Oct 12, 2012

We have a lot of code in ```bash blocks that stopped working as of 2.2.2. Same issue or new issue?

@bootstraponline
Copy link
Member

Same issue. pygments.rb was upgraded which handles syntax highlighting. I will look into why it's not working as expected. The existing code highlighting unit tests all pass so test coverage has to improve.

@ghost ghost assigned bootstraponline Oct 13, 2012
@bootstraponline
Copy link
Member

@riddley The following is syntax highlighted when I save the page. Does it work for you?

```bash
'test'
````

It doesn't appear highlighted in live preview though. I fixed bash highlighting for live preview on master. It'll be in the next release.

@bootstraponline
Copy link
Member

@sol Gollum has never supported the ~~~ syntax. I agree this would be a great feature though.

@bootstraponline
Copy link
Member

@sol Is the ~~~ syntax detailed somewhere? I added support for single languages ~~~ {.ruby} but multiple languages such as ~~~ {.haskell .literate} will fail. The references I've found only show one language per block.

@sol
Copy link
Author

sol commented Oct 13, 2012

@bootstraponline I don't think so. But you can look at e.g. Pandoc's Users Guide.

What about just ignoring all but the first class name? I think that is what GFM does. The thing why I want more classes is that I want to extract code pieces to test/verify them. So I may have things like ~~~ {.haskell .example-1}.

@bootstraponline
Copy link
Member

@sol Thanks for the link. I'll update the code to use just the first class name and ignore everything else.

@bootstraponline
Copy link
Member

Gollum 2.2.4 has been released on RubyGems and includes this feature. Let me know if it works as expected.

@sol
Copy link
Author

sol commented Oct 14, 2012

@bootstraponline It works already pretty well. Thanks for that!

"Fences" of arbitrary length do not work yet. They are useful, if you want to write a code block that itself contains markdown, e.g.:

Gollum supports fenced code blocks.  Here is an example:
~~~~~~ .markdown
~~~ .ruby
puts 'Hello world'
~~~
~~~~~~

The relevant parts of Pandoc's User's Guide (emphasis added):

These begin with a row of three or more tildes (~) or backticks (`) and end with a row of tildes or backticks that must be at least as long as the starting row. Everything between these lines is treated as code.

...

If the code itself contains a row of tildes or backticks, just use a longer row of tildes or backticks at the start and end.

In addition, the live preview does not handle it correctly, yet.

Both issues are not very critical for me. I think arbitrary length delimiters are a good idea. I don't care at all about the live preview.

And thanks again for implementing it in the first place, it already solves my use case :)

@bootstraponline
Copy link
Member

Thanks for pointing out the details for tilde fenced code blocks. I will look into implementing arbitrary length tilde fences for Gollum.

I opened #546 about better support in live preview. I don't think that's worth fixing in live preview unless someone plans on using it because the ``` syntax always works correctly.

@sol This doesn't work for you in live preview? It works for me. There are other examples which break though.

~~~~ {.ruby}
~~
'hi'
~~
~~~~

@sol
Copy link
Author

sol commented Oct 14, 2012

@bootstraponline Yes, this simple example works. I just realized that the actual parser is now more permissive than what is used for live preview. But I don't think it's a big issue.

@bootstraponline
Copy link
Member

The parser is the same, both use sundown. The extraction code is a bit different now that ~~~ is supported. I released 2.2.5. Let me know if it works as expected.

@ghost
Copy link

ghost commented Oct 15, 2012

Perhaps I should have reported it separately, but as of 2.2.9 ```bash blocks still don't work like they did with 2.2.1.

@bootstraponline
Copy link
Member

@riddley I opened #550. Please provide a reproducible example so I can fix the issue.

existme pushed a commit to existme/gollum that referenced this issue Aug 9, 2018
existme pushed a commit to existme/gollum that referenced this issue Aug 9, 2018
existme pushed a commit to existme/gollum that referenced this issue Aug 9, 2018
More than 3 tildes can be used. The code block must end with the same amount of tildes used to open the code block.

Fix gollum#537

http://johnmacfarlane.net/pandoc/README.html#delimited-code-blocks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants