This reapplies commit b643526d9a after being reverted in commit f65c453555. Unlike the original commit, this does a single pass and does not take into account unfinished code blocks.
b643526d9a
f65c453555