<commit_before>const {MenuBarEditorView} = require("prosemirror-menu")
const {EditorState} = require("prosemirror-state")
const {schema, defaultMarkdownParser, defaultMarkdownSerializer} = require("prosemirror-markdown")
const {exampleSetup} = require("prosemirror-example-setup")

let place = document.querySelector("#editor")

let getContent
function toTextArea(content, focus) {
  window.view = undefined
  let te = place.appendChild(document.createElement("textarea"))
  te.style.cssText = "font-family: inherit; font-size: inherit"
  te.value = content
  if (focus !== false) te.focus()
  getContent = () => te.value
}
function toProseMirror(content) {
  let view = new MenuBarEditorView(place, {
    state: EditorState.create({
      doc: defaultMarkdownParser.parse(content),
      plugins: exampleSetup({schema})
    })
  })
  window.view = view.editor
  view.editor.focus()
  getContent = () => defaultMarkdownSerializer.serialize(view.editor.state.doc)
}
toTextArea(document.querySelector("#markdown_content").textContent, false)

function change() {
  let content = getContent()
  place.textContent = ""
  if (document.querySelector("#inputformat").checked) toTextArea(content)
  else toProseMirror(content)
}
let radios = document.querySelectorAll("[name=inputformat]")
for (let i = 0; i < radios.length; i++) radios[i].addEventListener("change", change)
<commit_msg>[markdown demo] Call destroy when dropping an EditorView instance<commit_after>const {MenuBarEditorView} = require("prosemirror-menu")
const {EditorState} = require("prosemirror-state")
const {schema, defaultMarkdownParser, defaultMarkdownSerializer} = require("prosemirror-markdown")
const {exampleSetup} = require("prosemirror-example-setup")

let place = document.querySelector("#editor")

let getContent
function toTextArea(content, focus) {
  window.view = undefined
  let te = place.appendChild(document.createElement("textarea"))
  te.style.cssText = "font-family: inherit; font-size: inherit"
  te.value = content
  if (focus !== false) te.focus()
  getContent = () => te.value
}
function toProseMirror(content) {
  let view = new MenuBarEditorView(place, {
    state: EditorState.create({
      doc: defaultMarkdownParser.parse(content),
      plugins: exampleSetup({schema})
    })
  })
  window.view = view.editor
  view.editor.focus()
  getContent = () => {
    let content = defaultMarkdownSerializer.serialize(view.editor.state.doc)
    view.destroy()
    return content
  }
}
toTextArea(document.querySelector("#markdown_content").textContent, false)

function change() {
  let content = getContent()
  place.textContent = ""
  if (document.querySelector("#inputformat").checked) toTextArea(content)
  else toProseMirror(content)
}
let radios = document.querySelectorAll("[name=inputformat]")
for (let i = 0; i < radios.length; i++) radios[i].addEventListener("change", change)

{'fraction_non_alphanumeric': 0.13579387186629527, 'fraction_numerical': 0.0006963788300835655, 'mean_word_length': 5.589449541284404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7279847', 'n_tokens_mistral': 852, 'n_tokens_neox': 841, 'n_words': 177}