Mailspring/internal_packages/composer-markdown/lib/markdown-composer-extension.coffee
Ben Gotow 18d294c42f feat(transforms): Replace regexp body transforms with DOM approach
Summary:
We originally didn't do this because creating a DOM tree was loading images.
Using range.createContextualFragment seems to do it without the tree ever
being attached.

Accompanying changes to src/pro are here:
https://phab.nylas.com/D3300
https://github.com/nylas/edgehill/compare/bengotow/draft-dom-transformations?expand=1

Also rename applyTransformsToDraft => applyTransformsForSending. Needed
a new name because the function signature has changed. AFAIK there are no
open source plugins using the old functions.

Test Plan: All specs updated

Reviewers: evan, juan

Reviewed By: evan, juan

Differential Revision: https://phab.nylas.com/D3299
2016-09-23 16:36:08 -07:00

17 lines
570 B
CoffeeScript

marked = require 'marked'
Utils = require './utils'
{ComposerExtension} = require 'nylas-exports'
rawBodies = {}
class MarkdownComposerExtension extends ComposerExtension
@applyTransformsForSending: ({draftBodyRootNode, draft}) ->
rawBodies[draft.clientId] = draftBodyRootNode.innerHTML
draftBodyRootNode.innerHTML = marked(draftBodyRootNode.innerText)
@unapplyTransformsForSending: ({draftBodyRootNode, draft}) ->
if rawBodies[draft.clientId]
draftBodyRootNode.innerHTML = rawBodies[draft.clientId]
module.exports = MarkdownComposerExtension