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

how to highlight code syntax? #263

Closed
fedelibre opened this issue Dec 2, 2014 · 15 comments
Closed

how to highlight code syntax? #263

fedelibre opened this issue Dec 2, 2014 · 15 comments

Comments

@fedelibre
Copy link
Contributor

Reading issue #183 , I understand that mkdocs supports syntax highlighting. And I see also the prettify.js files in all the themes.except readthedocs.

I wonder where can I find the instructions about the use of prettify. Is it supposed to recognize the language automatically or should I specify the lang in the fenced block?
I've tried py, js, css but none works.

```py
import this
print("Please document syntax highlighting in mkdocs")
```

It would be worth adding some information in the documentation.
Thanks

@bosbyj
Copy link

bosbyj commented Dec 3, 2014

I changed the source a bit and switched the engine to markdown2, which supports 'gfm'.
write a plugin of pygments, and it is good to go.

only that the TOC part is not working correctly, because markdown and markdown2 do not share the same api in Meta part.

@fedelibre
Copy link
Contributor Author

Ok, I've made some search.
So MkDocs use markdown python library, which supports Github fence code style, as you can read in python markdown documentation

IIUC markdown assigns as <pre> class whatever text is following the three backticks. But there's no syntax CSS file in any theme, right?
Not implemented yet?

@d0ugal
Copy link
Member

d0ugal commented Dec 3, 2014

There is highlighting in the ReadTheDocs theme. You can see it here: http://mkdocs.readthedocs.org/en/latest/#installation

@d0ugal
Copy link
Member

d0ugal commented Dec 3, 2014

... It uses highlight.js

@d0ugal
Copy link
Member

d0ugal commented Dec 3, 2014

To use that extension, you need to add 'fenced_code' to your config.

http://www.mkdocs.org/user-guide/configuration/#formatting-options

@d0ugal d0ugal closed this as completed Dec 3, 2014
@bosbyj
Copy link

bosbyj commented Dec 3, 2014

OK. I figured it out.
The prettity.js feature is only available in the DEFAULT theme.
So syntax highlighting is actually working fine.

@fedelibre
Copy link
Contributor Author

I cannot make it work. This is my config file:

$ cat mkdocs.yml 
site_name: MkDocs Test
theme: readthedocs
markdown_extensions: [fenced_code]

I've tried indented blocks, fenced blocks and fenced block with languages specified.
Nothing works.
highlight.js and highlight.css are loaded.

What I'm missing?

@fedelibre
Copy link
Contributor Author

BTW, MkDocs doc seems to suggest that fenced_code is already enabled:

Python Markdown supports a variety of extensions that customize how pages are formatted. This setting lets you enable a list of extensions beyond the ones that MkDocs uses by default (meta, toc, tables, and fenced_code).

@bosbyj
Copy link

bosbyj commented Dec 3, 2014

comment this line out:

# theme: readthedocs

it falls back automatically to the mkdocs theme, which works well with highlighting.

you can just copy the css from any theme you like, as a quick fix to this problem.

eg.:

css files
from:
\site-packages\mkdocs\themes\readthedocs\css
to:
\site-packages\mkdocs\themes\mkdocs\css

@fedelibre
Copy link
Contributor Author

@d0ugal how is generated the documentation on readthedocs.org? I'd like to see the source of the page you linked.

@fedelibre
Copy link
Contributor Author

now I see why it didn't work
@d0ugal I was using your search branch of #222 pull: it must have some kind of conflict...

In my experience, on current master, code highlighting works out of the box when I use the default theme. It doesn't work at all when I use readthedocs theme.

@d0ugal
Copy link
Member

d0ugal commented Dec 3, 2014

The documentation I linked is the MkDocs documentation with the RTD theme.

@fedelibre
Copy link
Contributor Author

Yes, I know, of course. But it doesn't use the same mkdocs.yml, right? So some processing must be done. I wonder how it's changed, that's why I'd like to see the exact sources used to generate the documentation on readthedocs.org, which is not the same source used to generate the documentation on mkdocs.org

I did try to add theme: readthedocs but it is not enough, no highlighting.

I hope I've provided enough information to understand my question now.

@d0ugal
Copy link
Member

d0ugal commented Dec 4, 2014

It is exactly the same but the theme is replaced with readthedocs. Read The Docs doesn't support other MkDocs themes at this point.

@master317
Copy link

@{
Layout = null;
}

<title>Index</title>
Hello World (from the view)

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

No branches or pull requests

4 participants