Code Highlighting
June 10, 2018•197 words
Listed now supports code highlighting for fenced code blocks.
```ruby def hello puts "world" end ```
will yield:
def hello
puts "world"
end
Some more examples:
Python
import numpy as np
cimport cython
from libc.math cimport sqrt
@cython.boundscheck(False)
@cython.wraparound(False)
def pairwise_cython(double[:, ::1] X):
cdef int M = X.shape[0]
cdef int N = X.shape[1]
cdef double tmp, d
cdef double[:, ::1] D = np.empty((M, M), dtype=np.float64)
for i in range(M):
for j in range(M):
d = 0.0
for k in range(N):
tmp = X[i, k] - X[j, k]
d += tmp * tmp
D[i, j] = sqrt(d)
return np.asarray(D)
JavaScript
document.addEventListener("DOMContentLoaded", function(event) {
var purchaseForm = document.getElementById("purchase-form");
if(purchaseForm) {
purchaseForm.addEventListener("submit", ($event) => {
var email = document.getElementById("purchase-form-email").value;
var price = purchaseForm.dataset.price * 100;
var title = purchaseForm.dataset.title;
var id = purchaseForm.dataset.postId;
var name = purchaseForm.dataset.blog;
loadStripe(() => {
beginPostPurchase(id, email, title, name, price);
})
});
}
});
CSS
/* Some example CSS */
@import url("something.css");
body {
margin: 0;
padding: 3em 6em;
font-family: tahoma, arial, sans-serif;
color: #000;
}
#navigation a {
font-weight: bold;
text-decoration: none !important;
}
code {
font-family: courier, monospace;
font-size: 80%;
color: #418A8A;
}