Add syntax highlighting to gh-pages - github

Is there an easy way to add syntax highlighting to my various plugin's gh-pages using github's Pygments?
I know that every page runs through the Jekyll engine and provides syntax highlighting (ref). But I don't want to install a blog. I just want syntax highlighting applied to the code blocks in my gh-pages.
I guess I could always just include a different plugin with my gh-pages...

Pages already does pygments, there's nothing to install. Just use it!
---
layout: default
title: Something with codes
---
Happy fun highlighting.
[More details](https://github.com/mojombo/jekyll/wiki/liquid-extensions)
{% highlight ruby %}
def foo
puts 'foo'
end
{% endhighlight %}

"GitHub Pages now only supports Rouge, a pure-Ruby syntax highlighter" so you only need to change 'kramdown' syntax highligher to use 'rouge' in your _config.yml file.
markdown: kramdown
kramdown:
input: GFM
syntax_highlighter: rouge

Found this thread as the first hit while trying to figure out syntax highlighting, and I found an even easier way to do it that I thought I'd share. Just put the name of the language you want highlighted after the fenced code blocks (reference). No need to generate any css or use yaml.
This is regular text
```ruby
# This is highlighted code
def foo
puts 'foo'
end
```
```python
# Here is some in python
def foo():
print 'foo'
```

As pointed out by #David Douglas, "GitHub Pages now only supports Rouge, a pure-Ruby syntax highlighter"
You have to put this in you _config.yml. This is from the _config.yml of Barry Clark's Jekyll Now
# Jekyll 3 now only supports Kramdown for Markdown
kramdown:
# Use GitHub flavored markdown, including triple backtick fenced code blocks
input: GFM
# Jekyll 3 and GitHub Pages now only support rouge for syntax highlighting
syntax_highlighter: rouge
syntax_highlighter_opts:
# Use existing pygments syntax highlighting css
css_class: 'highlight'
Then for the code highlighting part...
The list of langauge aliases for Rouge are listed here: https://github.com/jneen/rouge/wiki/List-of-supported-languages-and-lexers
It uses all-lowercase latters.
For example, for JavaScript:
``` javascript
function test() {
console.log("test");
}
```

The default syntax highlighter is rouge (equivalent to highlighter: rouge in your _config.yml file). With rouge, if you write a code block like this in markdown:
~~~js
let z = 26;
~~~
You can expect to get an HTML block like this:
<div class="language-js highlighter-rouge">
<div class="highlight">
<pre class="highlight"><code>
<span class="kd">let</span> <span class="nx">z</span> <span class="o">=</span> <span class="mi">26</span><span class="p">;</span>
</code></pre>
</div>
</div>
Then all you need is a CSS file (if you're using a GitHub Pages Theme, you will get the CSS automatically). I'm not sure where the CSS is officially supposed to come from, but
here is a CSS file for a light background
here is a CSS file for code in a dark rounded rect (the rest of the site may use a light or dark background).
Feel free to customize the css to your liking.

Related

.ejs formatting in VSCode

This is my problem - its unreadable
In order to get .ejs working in general, I've so far added the following. I also have format on save and prettier. I'm looking for proposals to get better formatting of this so that I can read it.
"files.associations": {
"*.ejs": "html",
"*.css": "postcss"
},
"emmet.includeLanguages": {
"postcss": "css",
"ejs": "html"
},
"emmet.syntaxProfiles": {
"postcss": "css",
"ejs": "html"
}
I know that's an old question, but working with .ejs in VSCode is still a problem. But I found the solution (for ? delimeter)
Install EJS language support plugin
Now you have ejs support, highlighting, and snippets, but some tags like
<? for( let item of array ) { ?>
(some data)
<? } ?>
are formatted incorrectly (at least with default html formatter).
To fix this, you can try set custom delimeter to '?' ejs.delimeter = '?'. Now you have correct indentation with <? ... ?> tags.
To use the snippets with our custom delimeter, you need to edit extension snippets (or add your own): install Snippets Ranger plugin, then find needed extension and edit its file. The Snippets Ranger is very handy tool.
I hope I helped somebody to setup VSCode for .ejs files
I would suggest using
EJS language support
which is according to them
Syntax highlighting for EJS, Javascript, and HTML tags. Includes
javascript autocompletion.
and if you are interested in a Linter you should check out
EJS-Lint
which according to them
EJS-Lint parses scriptlet tags (<%, %>, <%_, _%>, and -%>). It ignores
all other tags (i.e. <%=).
Note: This linter does not attempt to check for unclosed EJS tags, so
if you get an error Unexpected token with a line number that doesn't
contain any scriptlets, you most likely forgot to close a tag earlier.
It also is set up to handle old-style includes (<% include filename
%>) by ignoring them. It does not lint included files regardless of
the method of inclusion.
It can work with custom delimiters, just pass it in the options (if
using the API) or pass the --delimiter (-d) flag on the CLI.

Add syntax highlighting to auto generated gh-pages

How to make code snippets highlighted, while taking advantage of Jekyll autogeneration on github pages side?
Is it possible to make it work with backticks notation?
Or do I have / should I , move to over notation of code blocks?
I have this very simple site (at given commit) gh-pages branch with _config.yml:
kramdown:
input: GFM
which I added to make newline to be newlines in my code snippets. (apart from this I can get rid of it).
I wanted to make code higlighted, but keep using backticks notation, can it? (Github preview highlights it properly, however generated page is just black)
P.S. Somehow "Add syntax highlighting to gh-pages" Q&A does not help as you see under links (or I do sth wrong).
Use jekyll highlight tag with this jekyll original pygment highlight css file.
{% highlight ruby %}
def foo
puts 'foo'
end
{% endhighlight %}
You can also find a lot more css for pygment code highlighting.

Text/Code highlight with jsDoc

jsDoc seems to support most of the MD syntax, but when it comes to highlighting a single reserved word or text, I cannot find a usable tag for that.
In the MD syntax I can use `word`, which would set a grey background and a different font, so you can see it clearly, same as on StackOverflow - word.
In jsDoc, whether I use `word` or <code>word</code>, the effect is just setting italic style to the word, which cannot be clearly seen as a reserved word.
Is there any syntax in jsDoc to clearly highlight a word or a text string, like `some text` in MD, to look like some text?
Alternatively, is there a way to customize it - provide my own CSS for a standard MD tag?
JSDoc documentation seems to be using <code> tag, and it highlights the text using a grey background like you want by setting it on the code tag properties defined on the usejavadoc.css file:
From http://usejsdoc.org/tags-name.html:
There is a guide on how to edit or create your own JSDoc template, with a section on how to override the default template layout file:
http://usejsdoc.org/about-configuring-default-template.html#overriding-the-default-template-s-layout-file
But for something as simple as this, you don't even have to go that far. Just edit the css fragment, before or after generation, and set the background-color you want for the code tag. You may do it before generation by editing this line and setting the background color you want:
https://github.com/jsdoc3/jsdoc/blob/5a58bdf5a551844f12b46be6436aefd3c41e0393/templates/default/static/styles/jsdoc-default.css#L257
Or, if that doesn't work, overriding the property by adding
code {
background-color: #DEDEDE !important;
}
to the file.
As an alternative you can use a framework like qooxdoo to generate your documentation using JSDoc-like comments. According to their API reference you may use <pre class="javascript"> for inline javascript syntax code highlighting, and it looks pretty nice: http://manual.qooxdoo.org/3.0/pages/development/api_jsdoc_ref.html#html

how to paste <pre> into tinymce and preserve the formatting?

This seems very hard to do.
I'm pasting html code with <pre> into tinymce editor.
All the whitespaces are gone inside the <pre>
e.g. I'm trying to copy StackOverflow's <pre><code>block as in
def foo():
help me
It seems, tinymce trims whitespaces in <pre><code><span> and newlines are removed
How can I preserve it?
I'm using 3.5.3 btw
First of all you should set the entity encoding setting to raw
tinymce.init({
...
entity_encoding: "raw",
...ยด
But TinyMCE adds <br /> elements on line breaks if you edit your text. Here is a setup for syntay highlighting and preformatted text in NopCommerce, it is almost the same in WordPress or whatever.
TinyMCE Preformatted Text and Syntax Highlighting

Is there any ways to tune JSDoc with markdown plugin gfm to highlight github markdown syntax right?

Is there any ways to tune JSDoc with markdown plugin gfm to highlight github makrdown syntax?
Example
For example here is original highlighting:
https://github.com/darlingjs/darlingjs
and gfm (without highlighting) result:
http://darlingjs.github.io/docs/index.html
and by the way jsdoc has prettyprint.
I was able to add syntax highlight to my markdown tutorials using prettyprint. It's not GFM, but it's better than nothing :)
I just changed the code sections from:
``` javascript
// ...
// js code
// ...
```
to:
<pre class="prettyprint">
// ...
// js code
// ...
</pre>