paste-html.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. import { EditorView } from '@codemirror/view'
  2. import { Prec } from '@codemirror/state'
  3. import {
  4. insertPastedContent,
  5. pastedContent,
  6. storePastedContent,
  7. } from './pasted-content'
  8. export const pasteHtml = [
  9. Prec.highest(
  10. EditorView.domEventHandlers({
  11. paste(event, view) {
  12. const { clipboardData } = event
  13. if (!clipboardData) {
  14. return false
  15. }
  16. // allow pasting an image to create a figure
  17. if (clipboardData.files.length > 0) {
  18. return false
  19. }
  20. // only handle pasted HTML
  21. if (!clipboardData.types.includes('text/html')) {
  22. return false
  23. }
  24. // ignore text/html from VS Code
  25. if (
  26. clipboardData.types.includes('application/vnd.code.copymetadata') ||
  27. clipboardData.types.includes('vscode-editor-data')
  28. ) {
  29. return false
  30. }
  31. const html = clipboardData.getData('text/html').trim()
  32. const text = clipboardData.getData('text/plain').trim()
  33. if (html.length === 0) {
  34. return false
  35. }
  36. // convert the HTML to LaTeX
  37. try {
  38. const parser = new DOMParser()
  39. const { documentElement } = parser.parseFromString(html, 'text/html')
  40. // if the only content is in a code block, use the plain text version
  41. if (onlyCode(documentElement)) {
  42. return false
  43. }
  44. const latex = htmlToLaTeX(documentElement)
  45. // if there's no formatting, use the plain text version
  46. if (latex === text) {
  47. return false
  48. }
  49. view.dispatch(insertPastedContent(view, { latex, text }))
  50. view.dispatch(storePastedContent({ latex, text }, true))
  51. return true
  52. } catch (error) {
  53. console.error(error)
  54. // fall back to the default paste handler
  55. return false
  56. }
  57. },
  58. })
  59. ),
  60. pastedContent,
  61. ]
  62. const removeUnwantedElements = (
  63. documentElement: HTMLElement,
  64. selector: string
  65. ) => {
  66. for (const element of documentElement.querySelectorAll(selector)) {
  67. element.remove()
  68. }
  69. }
  70. const findCodeContainingElement = (documentElement: HTMLElement) => {
  71. let result: HTMLElement | null
  72. // a code element
  73. result = documentElement.querySelector<HTMLElement>('code')
  74. if (result) {
  75. return result
  76. }
  77. // a pre element with "monospace" somewhere in the font family
  78. result = documentElement.querySelector<HTMLPreElement>('pre')
  79. if (result?.style.fontFamily.includes('monospace')) {
  80. return result
  81. }
  82. return null
  83. }
  84. // return true if the text content of the first <code> element
  85. // is the same as the text content of the whole document element
  86. const onlyCode = (documentElement: HTMLElement) => {
  87. const codeElement = findCodeContainingElement(documentElement)
  88. return (
  89. codeElement?.textContent?.trim() === documentElement.textContent?.trim()
  90. )
  91. }
  92. const htmlToLaTeX = (documentElement: HTMLElement) => {
  93. // remove style elements
  94. removeUnwantedElements(documentElement, 'style')
  95. // replace non-breaking spaces added by Chrome on copy
  96. processWhitespace(documentElement)
  97. // pre-process table elements
  98. processTables(documentElement)
  99. // pre-process lists
  100. processLists(documentElement)
  101. // protect special characters in non-LaTeX text nodes
  102. protectSpecialCharacters(documentElement)
  103. processMatchedElements(documentElement)
  104. const text = documentElement.textContent
  105. if (!text) {
  106. return ''
  107. }
  108. // normalise multiple newlines
  109. return text.replaceAll(/\n{2,}/g, '\n\n')
  110. }
  111. const processWhitespace = (documentElement: HTMLElement) => {
  112. const walker = document.createTreeWalker(
  113. documentElement,
  114. NodeFilter.SHOW_TEXT
  115. )
  116. for (let node = walker.nextNode(); node; node = walker.nextNode()) {
  117. if (node.textContent === ' ') {
  118. node.textContent = ' '
  119. }
  120. }
  121. }
  122. const isElementNode = (node: Node): node is HTMLElement =>
  123. node.nodeType === Node.ELEMENT_NODE
  124. // TODO: negative lookbehind once Safari supports it
  125. const specialCharacterRegExp = /(^|[^\\])([#$%&~_^\\{}])/g
  126. const specialCharacterReplacer = (
  127. _match: string,
  128. prefix: string,
  129. char: string
  130. ) => {
  131. if (char === '\\') {
  132. // convert `\` to `\textbackslash{}`, preserving subsequent whitespace
  133. char = 'textbackslash{}'
  134. }
  135. return `${prefix}\\${char}`
  136. }
  137. const isElementContainingCode = (element: HTMLElement) =>
  138. element.tagName === 'CODE' ||
  139. (element.tagName === 'PRE' && element.style.fontFamily.includes('monospace'))
  140. const protectSpecialCharacters = (documentElement: HTMLElement) => {
  141. const walker = document.createTreeWalker(
  142. documentElement,
  143. NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,
  144. node =>
  145. isElementNode(node) && isElementContainingCode(node)
  146. ? NodeFilter.FILTER_REJECT
  147. : NodeFilter.FILTER_ACCEPT
  148. )
  149. for (let node = walker.nextNode(); node; node = walker.nextNode()) {
  150. if (node.nodeType === Node.TEXT_NODE) {
  151. const text = node.textContent
  152. if (text) {
  153. // replace non-backslash-prefixed characters
  154. node.textContent = text.replaceAll(
  155. specialCharacterRegExp,
  156. specialCharacterReplacer
  157. )
  158. }
  159. }
  160. }
  161. }
  162. const processMatchedElements = (documentElement: HTMLElement) => {
  163. for (const item of selectors) {
  164. for (const element of documentElement.querySelectorAll<any>(
  165. item.selector
  166. )) {
  167. if (!item.match || item.match(element)) {
  168. // start the markup
  169. if (item.start) {
  170. const start = document.createTextNode(item.start(element))
  171. if (item.inside) {
  172. element.prepend(start)
  173. } else {
  174. element.before(start)
  175. }
  176. }
  177. // end the markup
  178. if (item.end) {
  179. const end = document.createTextNode(item.end(element))
  180. if (item.inside) {
  181. element.append(end)
  182. } else {
  183. element.after(end)
  184. }
  185. }
  186. }
  187. }
  188. }
  189. }
  190. const matchingParents = (element: HTMLElement, selector: string) => {
  191. const matches = []
  192. for (
  193. let ancestor = element.parentElement?.closest(selector);
  194. ancestor;
  195. ancestor = ancestor.parentElement?.closest(selector)
  196. ) {
  197. matches.push(ancestor)
  198. }
  199. return matches
  200. }
  201. const urlCharacterReplacements = new Map<string, string>([
  202. ['\\', '\\\\'],
  203. ['#', '\\#'],
  204. ['%', '\\%'],
  205. ['{', '%7B'],
  206. ['}', '%7D'],
  207. ])
  208. const protectUrlCharacters = (url: string) => {
  209. // NOTE: add new characters to both this regex and urlCharacterReplacements
  210. return url.replaceAll(/[\\#%{}]/g, match => {
  211. const replacement = urlCharacterReplacements.get(match)
  212. if (!replacement) {
  213. throw new Error(`No replacement found for ${match}`)
  214. }
  215. return replacement
  216. })
  217. }
  218. const processLists = (element: HTMLElement) => {
  219. for (const list of element.querySelectorAll('ol,ul')) {
  220. // if the list has only one item, replace the list with an element containing the contents of the item
  221. if (list.childElementCount === 1) {
  222. const div = document.createElement('div')
  223. div.append(...list.firstElementChild!.childNodes)
  224. list.before('\n', div, '\n')
  225. list.remove()
  226. }
  227. }
  228. }
  229. const processTables = (element: HTMLElement) => {
  230. for (const table of element.querySelectorAll('table')) {
  231. // create a wrapper element for the table and the caption
  232. const container = document.createElement('div')
  233. container.className = 'ol-table-wrap'
  234. table.after(container)
  235. // move the caption (if it exists) into the container before the table
  236. const caption = table.querySelector('caption')
  237. if (caption) {
  238. container.append(caption)
  239. }
  240. // move the table into the container
  241. container.append(table)
  242. // add empty cells to account for rowspan
  243. for (const cell of table.querySelectorAll<HTMLTableCellElement>(
  244. 'th[rowspan],td[rowspan]'
  245. )) {
  246. const rowspan = Number(cell.getAttribute('rowspan') || '1')
  247. const colspan = Number(cell.getAttribute('colspan') || '1')
  248. let row: HTMLTableRowElement | null = cell.closest('tr')
  249. if (row) {
  250. let position = 0
  251. for (const child of row.cells) {
  252. if (child === cell) {
  253. break
  254. }
  255. position += Number(child.getAttribute('colspan') || '1')
  256. }
  257. for (let i = 1; i < rowspan; i++) {
  258. const nextElement: Element | null = row?.nextElementSibling
  259. if (!isTableRow(nextElement)) {
  260. break
  261. }
  262. row = nextElement
  263. let targetCell: HTMLTableCellElement | undefined
  264. let targetPosition = 0
  265. for (const child of row.cells) {
  266. if (targetPosition === position) {
  267. targetCell = child
  268. break
  269. }
  270. targetPosition += Number(child.getAttribute('colspan') || '1')
  271. }
  272. const fillerCells = Array.from({ length: colspan }, () =>
  273. document.createElement('td')
  274. )
  275. if (targetCell) {
  276. targetCell.before(...fillerCells)
  277. } else {
  278. row.append(...fillerCells)
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. const isTableRow = (element: Element | null): element is HTMLTableRowElement =>
  286. element?.tagName === 'TR'
  287. const cellAlignment = new Map([
  288. ['left', 'l'],
  289. ['center', 'c'],
  290. ['right', 'r'],
  291. ])
  292. const tabular = (element: HTMLTableElement) => {
  293. const definitions: Array<{
  294. alignment: string
  295. borderLeft: boolean
  296. borderRight: boolean
  297. }> = []
  298. const rows = element.querySelectorAll('tr')
  299. for (const row of rows) {
  300. const cells = [...row.childNodes].filter(
  301. element => element.nodeName === 'TD' || element.nodeName === 'TH'
  302. ) as Array<HTMLTableCellElement>
  303. let index = 0
  304. for (const cell of cells) {
  305. // NOTE: reading the alignment and borders from the first cell definition in each column
  306. if (definitions[index] === undefined) {
  307. const { textAlign, borderLeftStyle, borderRightStyle } = cell.style
  308. definitions[index] = {
  309. alignment: textAlign,
  310. borderLeft: visibleBorderStyle(borderLeftStyle),
  311. borderRight: visibleBorderStyle(borderRightStyle),
  312. }
  313. }
  314. index += Number(cell.getAttribute('colspan') ?? 1)
  315. }
  316. }
  317. for (let index = 0; index <= definitions.length; index++) {
  318. // fill in missing definitions
  319. const item = definitions[index] || {
  320. alignment: 'left',
  321. borderLeft: false,
  322. borderRight: false,
  323. }
  324. // remove left border if previous column had a right border
  325. if (item.borderLeft && index > 0 && definitions[index - 1]?.borderRight) {
  326. item.borderLeft = false
  327. }
  328. }
  329. return definitions
  330. .flatMap(definition => [
  331. definition.borderLeft ? '|' : '',
  332. cellAlignment.get(definition.alignment) ?? 'l',
  333. definition.borderRight ? '|' : '',
  334. ])
  335. .filter(Boolean)
  336. .join(' ')
  337. }
  338. const listDepth = (
  339. element: HTMLOListElement | HTMLUListElement | HTMLLIElement
  340. ): number => Math.max(0, matchingParents(element, 'ul,ol').length - 1)
  341. const listIndent = (
  342. element: HTMLOListElement | HTMLUListElement | HTMLLIElement
  343. ): string => '\t'.repeat(listDepth(element))
  344. type ElementSelector<T extends string, E extends HTMLElement = HTMLElement> = {
  345. selector: T
  346. match?: (element: E) => boolean
  347. start?: (element: E) => string
  348. end?: (element: E) => string
  349. inside?: boolean
  350. }
  351. const createSelector = <
  352. T extends string,
  353. E extends HTMLElement = T extends keyof HTMLElementTagNameMap
  354. ? HTMLElementTagNameMap[T]
  355. : HTMLElement
  356. >({
  357. selector,
  358. ...elementSelector
  359. }: ElementSelector<T, E>) => ({
  360. selector,
  361. ...elementSelector,
  362. })
  363. const headings = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6']
  364. const isHeading = (element: HTMLElement | null) => {
  365. return element && headings.includes(element.nodeName)
  366. }
  367. const hasContent = (element: HTMLElement): boolean => {
  368. return Boolean(element.textContent && element.textContent.trim().length > 0)
  369. }
  370. type BorderStyle =
  371. | 'borderTopStyle'
  372. | 'borderRightStyle'
  373. | 'borderBottomStyle'
  374. | 'borderLeftStyle'
  375. const visibleBorderStyle = (style: CSSStyleDeclaration[BorderStyle]): boolean =>
  376. !!style && style !== 'none' && style !== 'hidden'
  377. const rowHasBorderStyle = (
  378. element: HTMLTableRowElement,
  379. style: BorderStyle
  380. ): boolean => {
  381. if (visibleBorderStyle(element.style[style])) {
  382. return true
  383. }
  384. const cells = element.querySelectorAll<HTMLTableCellElement>('th,td')
  385. return [...cells].every(cell => visibleBorderStyle(cell.style[style]))
  386. }
  387. const isTableRowElement = (
  388. element: Element | null
  389. ): element is HTMLTableRowElement => element?.tagName === 'TR'
  390. const nextRowHasBorderStyle = (
  391. element: HTMLTableRowElement,
  392. style: BorderStyle
  393. ) => {
  394. const { nextElementSibling } = element
  395. return (
  396. isTableRowElement(nextElementSibling) &&
  397. rowHasBorderStyle(nextElementSibling, style)
  398. )
  399. }
  400. const startMulticolumn = (element: HTMLTableCellElement): string => {
  401. const colspan = Number(element.getAttribute('colspan') || 1)
  402. const alignment = cellAlignment.get(element.style.textAlign) ?? 'l'
  403. return `\\multicolumn{${colspan}}{${alignment}}{`
  404. }
  405. const startMultirow = (element: HTMLTableCellElement): string => {
  406. const rowspan = Number(element.getAttribute('rowspan') || 1)
  407. // NOTE: it would be useful to read cell width if specified, using `*` as a starting point
  408. return `\\multirow{${rowspan}}{*}{`
  409. }
  410. const selectors = [
  411. createSelector({
  412. selector: 'b',
  413. match: element =>
  414. !element.style.fontWeight &&
  415. !isHeading(element.parentElement) &&
  416. hasContent(element),
  417. start: () => '\\textbf{',
  418. end: () => '}',
  419. }),
  420. createSelector({
  421. selector: '*',
  422. match: element =>
  423. (element.style.fontWeight === 'bold' ||
  424. parseInt(element.style.fontWeight) >= 700) &&
  425. hasContent(element),
  426. start: () => '\\textbf{',
  427. end: () => '}',
  428. inside: true,
  429. }),
  430. createSelector({
  431. selector: 'strong',
  432. match: element => !element.style.fontWeight && hasContent(element),
  433. start: () => '\\textbf{',
  434. end: () => '}',
  435. }),
  436. createSelector({
  437. selector: 'i',
  438. match: element => !element.style.fontStyle && hasContent(element),
  439. start: () => '\\textit{',
  440. end: () => '}',
  441. }),
  442. createSelector({
  443. selector: '*',
  444. match: element =>
  445. element.style.fontStyle === 'italic' && hasContent(element),
  446. start: () => '\\textit{',
  447. end: () => '}',
  448. }),
  449. createSelector({
  450. selector: 'em',
  451. match: element => !element.style.fontStyle && hasContent(element),
  452. start: () => '\\textit{',
  453. end: () => '}',
  454. }),
  455. createSelector({
  456. selector: 'sup',
  457. match: element => !element.style.verticalAlign && hasContent(element),
  458. start: () => '\\textsuperscript{',
  459. end: () => '}',
  460. }),
  461. createSelector({
  462. selector: 'span',
  463. match: element =>
  464. element.style.verticalAlign === 'super' && hasContent(element),
  465. start: () => '\\textsuperscript{',
  466. end: () => '}',
  467. }),
  468. createSelector({
  469. selector: 'sub',
  470. match: element => !element.style.verticalAlign && hasContent(element),
  471. start: () => '\\textsubscript{',
  472. end: () => '}',
  473. }),
  474. createSelector({
  475. selector: 'span',
  476. match: element =>
  477. element.style.verticalAlign === 'sub' && hasContent(element),
  478. start: () => '\\textsubscript{',
  479. end: () => '}',
  480. }),
  481. createSelector({
  482. selector: 'a',
  483. match: element => !!element.href && hasContent(element),
  484. start: (element: HTMLAnchorElement) => {
  485. const url = protectUrlCharacters(element.href)
  486. return `\\href{${url}}{`
  487. },
  488. end: () => `}`,
  489. }),
  490. createSelector({
  491. selector: 'h1',
  492. match: element => !element.closest('table') && hasContent(element),
  493. start: () => `\n\n\\section{`,
  494. end: () => `}\n\n`,
  495. }),
  496. createSelector({
  497. selector: 'h2',
  498. match: element => !element.closest('table') && hasContent(element),
  499. start: () => `\n\n\\subsection{`,
  500. end: () => `}\n\n`,
  501. }),
  502. createSelector({
  503. selector: 'h3',
  504. match: element => !element.closest('table') && hasContent(element),
  505. start: () => `\n\n\\subsubsection{`,
  506. end: () => `}\n\n`,
  507. }),
  508. createSelector({
  509. selector: 'h4',
  510. match: element => !element.closest('table') && hasContent(element),
  511. start: () => `\n\n\\paragraph{`,
  512. end: () => `}\n\n`,
  513. }),
  514. createSelector({
  515. selector: 'h5',
  516. match: element => !element.closest('table') && hasContent(element),
  517. start: () => `\n\n\\subparagraph{`,
  518. end: () => `}\n\n`,
  519. }),
  520. // TODO: h6?
  521. createSelector({
  522. selector: 'br',
  523. match: element => element.parentElement?.nodeName !== 'TD', // TODO: why?
  524. start: () => `\n\n`,
  525. }),
  526. createSelector({
  527. selector: 'code',
  528. match: element =>
  529. element.parentElement?.nodeName !== 'PRE' && hasContent(element),
  530. start: () => `\\verb|`,
  531. end: () => `|`,
  532. }),
  533. createSelector({
  534. selector: 'pre > code',
  535. match: element => hasContent(element),
  536. start: () => `\n\n\\begin{verbatim}\n`,
  537. end: () => `\n\\end{verbatim}\n\n`,
  538. }),
  539. createSelector({
  540. selector: 'pre',
  541. match: element =>
  542. element.style.fontFamily.includes('monospace') &&
  543. element.firstElementChild?.nodeName !== 'CODE' &&
  544. hasContent(element),
  545. start: () => `\n\n\\begin{verbatim}\n`,
  546. end: () => `\n\\end{verbatim}\n\n`,
  547. }),
  548. createSelector({
  549. selector: '.ol-table-wrap',
  550. start: () => `\n\n\\begin{table}\n\\centering\n`,
  551. end: () => `\n\\end{table}\n\n`,
  552. }),
  553. createSelector({
  554. selector: 'table',
  555. start: element => `\n\\begin{tabular}{${tabular(element)}}`,
  556. end: () => `\\end{tabular}\n`,
  557. }),
  558. createSelector({
  559. selector: 'thead',
  560. start: () => `\n`,
  561. end: () => `\n`,
  562. }),
  563. createSelector({
  564. selector: 'tfoot',
  565. start: () => `\n`,
  566. end: () => `\n`,
  567. }),
  568. createSelector({
  569. selector: 'tbody',
  570. start: () => `\n`,
  571. end: () => `\n`,
  572. }),
  573. createSelector({
  574. selector: 'tr',
  575. start: element => {
  576. const borderTop = rowHasBorderStyle(element, 'borderTopStyle')
  577. return borderTop ? '\\hline\n' : ''
  578. },
  579. end: element => {
  580. const borderBottom = rowHasBorderStyle(element, 'borderBottomStyle')
  581. return borderBottom && !nextRowHasBorderStyle(element, 'borderTopStyle')
  582. ? '\n\\hline\n'
  583. : '\n'
  584. },
  585. }),
  586. createSelector({
  587. selector: 'tr > td, tr > th',
  588. start: (element: HTMLTableCellElement) => {
  589. let output = ''
  590. if (element.getAttribute('colspan')) {
  591. output += startMulticolumn(element)
  592. }
  593. // NOTE: multirow is nested inside multicolumn
  594. if (element.getAttribute('rowspan')) {
  595. output += startMultirow(element)
  596. }
  597. return output
  598. },
  599. end: element => {
  600. let output = ''
  601. // NOTE: multirow is nested inside multicolumn
  602. if (element.getAttribute('rowspan')) {
  603. output += '}'
  604. }
  605. if (element.getAttribute('colspan')) {
  606. output += '}'
  607. }
  608. const row = element.parentElement as HTMLTableRowElement
  609. const isLastChild = row.cells.item(row.cells.length - 1) === element
  610. return output + (isLastChild ? ' \\\\' : ' & ')
  611. },
  612. }),
  613. createSelector({
  614. selector: 'caption',
  615. start: () => `\n\n\\caption{`,
  616. end: () => `}\n\n`,
  617. }),
  618. createSelector({
  619. // selector: 'ul:has(> li:nth-child(2))', // only select lists with at least 2 items (once Firefox supports :has())
  620. selector: 'ul',
  621. start: element => `\n\n${listIndent(element)}\\begin{itemize}`,
  622. end: element => `\n${listIndent(element)}\\end{itemize}\n`,
  623. }),
  624. createSelector({
  625. // selector: 'ol:has(> li:nth-child(2))', // only select lists with at least 2 items (once Firefox supports :has())
  626. selector: 'ol',
  627. start: element => `\n\n${listIndent(element)}\\begin{enumerate}`,
  628. end: element => `\n${listIndent(element)}\\end{enumerate}\n`,
  629. }),
  630. createSelector({
  631. selector: 'li',
  632. start: element => `\n${listIndent(element)}\t\\item `,
  633. }),
  634. createSelector({
  635. selector: 'p',
  636. match: element => {
  637. // must have content
  638. if (!hasContent(element)) {
  639. return false
  640. }
  641. // inside lists and tables, must precede another paragraph
  642. if (element.closest('li') || element.closest('table')) {
  643. return element.nextElementSibling?.nodeName === 'P'
  644. }
  645. return true
  646. },
  647. end: () => '\n\n',
  648. }),
  649. createSelector({
  650. selector: 'blockquote',
  651. start: () => `\n\n\\begin{quote}\n`,
  652. end: () => `\n\\end{quote}\n\n`,
  653. }),
  654. ]