How to enter a syntax-highlighted code block in an instructions page without using Markdown?

My class’s primary language is Hebrew, which is written from right to left. I’d like to provide project instructions in Hebrew. Unfortunately, Markdown doesn’t seem to support right-to-left languages. However, there’s a workaround: using raw HTML to wrap all the instruction code inside a <div dir="rtl", align="right", lang="he"> element (cf. this post).

However, this creates a problem when I wish to incorporate syntax-highlighted code blocks in my instructions. If it weren’t for the enclosing div element, I could use a Markdown fenced codeblock element and write, say

println("Hello, world!")

However, this doesn’t work inside a div element. Generally speaking, Markdown doesn’t seem to work inside raw HTML elements.

A possible solution would be to end the div element before the code block, and then enter the code using a Markdown fenced codeblock. However, this disrupts the logical structure of the document, and may also have undesirable practical repercussions. Consider, for instance, a situation in which I wish to provide a code block as one of several items of an ordered list inside an HTML <ol> element. The automatic numbering of list items and their indentation will be off if I end the ordered list mid-way in order to enter a code block using Markdown.

Most of the Markdown language elements have raw HTML equivalents, for instance the # (hashtag) Markdown element that indicates a top-level heading can be substituted by the equivalent raw HTML <h1> element.

Is there a raw HTML equivalent for the fenced codeblock Markdown element for formatting a code block with language-specific syntax highlighting?

I found another post in this forum that may be of help to me. It suggests using highlights.js. However, I can’t figure out how to deploy highlight.js in my repl. Help will be appreciated.


Hey @itaib, welcome to the community!

Simply wrap the code in pre and code tags.

Or if you just want it to look like this, don’t use the pre tag at all.

Hope this helps!

1 Like

H Qwerty. Thanks for your reply. The pre and code tags don’t provide syntax highlighting.

1 Like

Replit actually uses highlight.js, so you can simply specify the language like so:

<pre><code class="language-python">print("Hello, world!")</code></pre>

Thanks! This solves my problem.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.