How to use the highlightElement function from highlight.js

Find comprehensive JavaScript highlight.js.highlightElement code examples handpicked from public code repositorys.

366
367
368
369
370
371
372
373
374
375
376
      <button class="fa fa-trash-o delete-button"></button>
    </div>
    ${converter.makeHtml(content)}
  `;
  // highlight the html code elements
  newArticleElement.querySelectorAll("code").forEach(code => hljs.highlightElement(code));
  document.querySelector("#articles").appendChild(newArticleElement);
}


function createArticleElements(articles) {
fork icon0
star icon0
watch icon1

+ 13 other calls in file

815
816
817
818
819
820
821
822
823
824
825
826
827
function getURL(title) { return title.toLowerCase().replace(/[^a-z0-9\-]+/g, '-').replace(/-{2,}/g, '-'); }


function highlight($body) {
    const $codes = $body.querySelectorAll('code[class^="language-"]');


    if ($codes !== null) { Array.from($codes).forEach($code => hljs.highlightElement($code)); }


    return $body;
}

fork icon0
star icon0
watch icon1

+ 2 other calls in file

73
74
75
76
77
78
79
80
81
82
        console.log("Logging post data")
        setJsonData(data)
    })
    document.querySelectorAll('div.code').forEach(el => {
        // then highlight each
        hljs.highlightElement(el);
    })
}

doStuff()
fork icon0
star icon0
watch icon0