   o.innerHTML
 
 convertCodeBlocksToAtomEditors = (domFragment, defaultLanguage='text') ->
+  codeBlocks.clear()
+  grammarSubscription?.dispose()
+  grammarSubscription = atom.grammars.onDidAddGrammar ->
+    codeBlocks.forEach (fenceName, editor) ->
+      if grammar = atom.grammars.grammarForScopeName(scopeForFenceName(fenceName))
+        editor.setGrammar(grammar)
+
   if fontFamily = atom.config.get('editor.fontFamily')
-
     for codeElement in domFragment.querySelectorAll('code')
       codeElement.style.fontFamily = fontFamily
 

    fenceName = codeBlock.getAttribute('class')?.replace(/^lang-/, '') ? defaultLanguage

    editorElement = document.createElement('atom-text-editor')
    editorElement.setAttributeNode(document.createAttribute('gutter-hidden'))
    editorElement.removeAttribute('tabindex') # make read-only

    preElement.parentNode.insertBefore(editorElement, preElement)
    preElement.remove()

    editor = editorElement.getModel()
    editor.setText(codeBlock.textContent)
    if grammar = atom.grammars.grammarForScopeName(scopeForFenceName(fenceName))
      editor.setGrammar(grammar)

    # Remove line decorations from code blocks.
    if editor.cursorLineDecorations?
      for cursorLineDecoration in editor.cursorLineDecorations
        cursorLineDecoration.destroy()
    else
      editor.getDecorations(class: 'cursor-line', type: 'line')[0].destroy()

  domFragment


path = require 'path'
cheerio = require 'cheerio'
createDOMPurify = require 'dompurify'
fs = require 'fs-plus'
