Having trouble implementing Code Prettify in Jekyll—want to use `` instead of <pre></pre>

Larry

I've been trying to implement Code Prettify in my Jekyll blog. I followed some guides and was able to implement it, but it's not ideal. This is what I did:

1- I went to _includes and added the necessary files in head.html:

The sunburst theme:

<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>

The CSS file of the theme (it is in my css folder on GitHub):

<link rel="stylesheet" href="/css/prettify.css" rel= 'stylesheet' type='text/css'>

2- For example, I used the tag <pre class= "prettyprint"></pre> to test it. As you can see in this post (the code block is at the bottom of the page), it does work. If you notice, you see that <iostream> is missing because I used <pre></pre> and therefore it sees the <> characters, takes them as HTML and doesn't show <iostream>. This is how it looks:

enter image description here

I could use HTML entities to fix it, but this is not ideal. I've searched for 2 hours and couldn't find a reliable source to fix this.


So my question is:

Is it possible to make Code Prettify work in markdown, using `` instead of <pre></pre>? If not, is there another way to implement it in Jekyll? Or make it easier to use? If none of these are possible, is there a better alternative to Jekyll which supports Code Prettify?

If you need to see other files please do check my repository.

David Jacquel

With Jekyll, you can use two highligting methods :

backtick-style fenced-code

In _config.yml, set :

kramdown:
  input: GFM

Highlight your code like this :

``` c
include <iostream>
using namespace std;

int main () {
cout << "and then there were none" << endl;
return 0;
}
```

With highlight liquid tag

{% highlight c %}
include <iostream>
using namespace std;

int main () {
cout << "and then there were none" << endl;
return 0;
}
{% endhighlight %}

Styling

Styles are from _scss/_syntax-highlighting.scss.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Embed code in pre/code tags in HAML

From Dev

Having a cycled (interval) pictures on pre-loaded page through a directory

From Dev

Having trouble with implementing multiple pipes in C

From Dev

Having trouble with compiling this code

From Dev

Having trouble with php code to redirect

From Dev

Having trouble implementing google play leaderboard

From Dev

Is having multiple pre-selected values in <select multiple> possible?

From Dev

Having trouble implementing photon mapping

From Dev

Having trouble implementing a readlink() function

From Dev

Rationale for pre-C99 C not having initial declarations in for loops?

From Dev

Different behavior on <pre><code>

From Dev

Having trouble with implementing a system that detects if an input is a integer or not

From Dev

having trouble with <pre> <code> on mobile

From Dev

Implementing pre-made rotating banner into website

From Dev

Implementing a pre commit dialog using tsvn:userdirproperties

From Dev

Trouble installing powerline pre-patched fonts on mavericks 10.9.2

From Dev

Using Twilio to send pre-filled message from iOS handset instead of asking user to enter code?

From Dev

Having trouble with php code to redirect

From Dev

Interpreting C pre pre processor code

From Dev

Want to use <pre> without and css which have defined in css file

From Dev

What is the use of -pre in Chocolatey?

From Dev

Having trouble understanding a portion of code

From Dev

JS use pre-arranged numbers/letters from a list instead of generating letters/numbers?

From Dev

AngularJS - use <pre> or encode HTML for code examples

From Dev

Having trouble with code and program flow

From Dev

Having trouble implementing JsonObjectRequest

From Dev

Having trouble displaying code

From Dev

Unable to use pre - launch task more than once in VS Code

From Dev

Having trouble understanding .this keyword use in this code

Related Related

  1. 1

    Embed code in pre/code tags in HAML

  2. 2

    Having a cycled (interval) pictures on pre-loaded page through a directory

  3. 3

    Having trouble with implementing multiple pipes in C

  4. 4

    Having trouble with compiling this code

  5. 5

    Having trouble with php code to redirect

  6. 6

    Having trouble implementing google play leaderboard

  7. 7

    Is having multiple pre-selected values in <select multiple> possible?

  8. 8

    Having trouble implementing photon mapping

  9. 9

    Having trouble implementing a readlink() function

  10. 10

    Rationale for pre-C99 C not having initial declarations in for loops?

  11. 11

    Different behavior on <pre><code>

  12. 12

    Having trouble with implementing a system that detects if an input is a integer or not

  13. 13

    having trouble with <pre> <code> on mobile

  14. 14

    Implementing pre-made rotating banner into website

  15. 15

    Implementing a pre commit dialog using tsvn:userdirproperties

  16. 16

    Trouble installing powerline pre-patched fonts on mavericks 10.9.2

  17. 17

    Using Twilio to send pre-filled message from iOS handset instead of asking user to enter code?

  18. 18

    Having trouble with php code to redirect

  19. 19

    Interpreting C pre pre processor code

  20. 20

    Want to use <pre> without and css which have defined in css file

  21. 21

    What is the use of -pre in Chocolatey?

  22. 22

    Having trouble understanding a portion of code

  23. 23

    JS use pre-arranged numbers/letters from a list instead of generating letters/numbers?

  24. 24

    AngularJS - use <pre> or encode HTML for code examples

  25. 25

    Having trouble with code and program flow

  26. 26

    Having trouble implementing JsonObjectRequest

  27. 27

    Having trouble displaying code

  28. 28

    Unable to use pre - launch task more than once in VS Code

  29. 29

    Having trouble understanding .this keyword use in this code

HotTag

Archive