script src cdnjs cloudflare com ajax libs highlight js 10 1 1 highlight min js script link rel stylesheet href cdnjs cloudflare com ajax libs highlight js 10 1 1 styles default min css pre code for let i 0 i 10 i let test i a coo code pre script type text javascript document body style height 100px hljs initHighlightingOnLoad script script src cdnjs cloudflare com ajax libs highlight js 10 1 1 highlight min js script link rel stylesheet href cdnjs cloudflare com ajax libs highlight js 10 1 1 styles default min css pre code for let i 0 i 10 i let test i a coo code pre script document body style height 100px let codes document getElementsByTagName code for let i 0 i codes length i hljs highlightBlock codes i script Hack workaround for editable content so that the highlighting is updated on the fly dynamically after the code block is changed This version try typing some code then when you leave focus click on something else the code block is updated script src cdnjs cloudflare com ajax libs highlight js 10 1 1 highlight min js script link rel stylesheet href cdnjs cloudflare com ajax libs highlight js 10 1 1 styles default min css pre code contentEditable for let i 0 i 10 i let test i a coo code pre script document body style height 200px let codes document getElementsByTagName code for let i 0 i codes length i hljs highlightBlock codes i this is the update line codes i addEventListener focusout function e hljs highlightBlock e srcElement end for i script
round for editable content so that the highlighting is updated on the fly dynamically after the code block is changed This version try typing some code then when you leave focus click on something else the code block is updated script src cdnjs cloudflare com ajax libs highlight js 10 1 1 highlight min js script link rel stylesheet href cdnjs cloudflare com ajax libs highlight js 10 1 1 styles default min css pre code contentEditable for let i 0 i 10 i let test i a coo code pre script document body style height 200px let codes document getElementsByTagName code for let i 0 i codes length i hljs highlightBlock codes i this is the update line codes i addEventListener focusout function e hljs highlightBlock e srcElement end for i script