how to create a block to display c++/java code in HTML/CSS?

Asked

Viewed 821 times

0

I have a JAVA code, I would like to post it on a website. How do I do that? I’m using css spreadsheets but they "spoil the spaces" between the keys and don’t show high light JAVA code, how do I fix this problem of "eating the spaces" and the problem of adding Hylight syntax in JAVA code blocks? this on display on a website.

  • Are you using some lib to make this Highlight? Or playing java code between html tags and formatting with native css?

  • See about the Code Prettify, may be of use to you.

  • I’m playing java code between html tags and formatting with native css, I’m beginner...

1 answer

1


I recommend using the Highlight.js. It works in over 174 languages and 77 styles.

You can download it and use only add in the page HEAD

<link rel="stylesheet" href="/path/to/styles/default.css">
<script src="/path/to/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

Then just put code to give Highlight inside the tags like this:

<pre><code class="html">...</code></pre>

It detects automatic also without needing to mark the language.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.