I would like to display blocks of code as a site like StackOverflow does:
def func(A):
result = 0
n = len(A)
while n > 1:
n = n/2
result = result + min(A[1,...,n])
return result
It properly colors, formats and spaces all the code once it has been designated as a code block. I would like this to happen in my site as well. All code blocks will be python, by the way.
The font, background and spacing seem easy enough to implement (just designate a class in which the background is grey, the font is that font and the spacing is monospace).
However, I am wondering how to color the text appropriately? I am assuming I would need to use JavaScript, and loop through all the words in the code block, checking if they match a list of words that I have preset to become certain colors.
Let me know if I made any incorrect assumptions anywhere here, or things that may complicate my approach.