Action

Markdown Email (default client)

Posted by jmhammond, Last update 8 months ago

UPDATES

8 months ago

Corrected the non-url-bearing body tag.

show all updates...

8 months ago

Corrected the non-url-bearing body tag.

8 months ago

Updated to allow customizing the font family and size using the ideas of agiletortoise’s Copy as Rich Text (adjustable font size)2BY

Send Draft as Email (default client)
- If the draft doesn’t contain URLs, just send it as-is
- If the draft contains urls, we markdownify it:
Copy to the formatted draft to the clipboard
Create a new email with the subject as the title of the draft, the body is a message telling you to paste the formatted text from the clipboard.

This solve my problem of having to manually correct markdown-style URLs when I send emails.

Steps

  • defineTemplateTag

    name
    font-family
    template
    Aptos, Helvetica, sans-serif
  • defineTemplateTag

    name
    font-size
    template
    12
  • defineTemplateTag

    name
    emailBody
    template
  • script

    if(draft.urls.length > 0) {
    	// Process Markdown to HTML
    	var mmd = MultiMarkdown.create();
    	var html = mmd.render(draft.content);
    	var fontFamily = draft.processTemplate("[[font-family]]");
    	var fontSize = draft.processTemplate("[[font-size]]");
    	
    	// Wrap raw MMD output with HTML template with styles to set base fonts.
    	
    	var template = `<html>
    	
    	<body style="font-size: ${fontSize}pt; font-family: ${fontFamily};">
    		[[body]]
    	</body>
    	
    	</html>
    	`;
    	
    	var html = template.replace("[[body]]", html);
    	// Place in clipboard as rich-text
    	if (!app.htmlToClipboard(html)) {
    	context.fail("Error rendering rich text from HTML.");
    	}
    	
    	// Tell myself to paste it from the clipboard.
    	draft.setTemplateTag("emailBody", "The Draft Included URLs! Please paste from the clipboard. -- You")
    
    }
    else{
    	draft.setTemplateTag("emailBody", draft.processTemplate("[[body]]") )
    }
  • url

    template
    mailto:?subject=[[title]]&body=[[emailBody]]
    useSafari
    false
    encodeTags
    true

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.