Action

Copy as Rich Text (adjustable font size)

Posted by agiletortoise, Last update about 1 year ago

UPDATES

about 1 year ago

Add tag to set font-family.

Convert Markdown draft to rich text and place in clipboard.

This version assigned an explicit base font size to the output. This value can be adjusted by changing the value in the first “Define Template Tag” action step to be an integer font-size value.

Steps

  • defineTemplateTag

    name
    font-family
    template
    Avenir Next
  • defineTemplateTag

    name
    font-size
    template
    14
  • script

    // 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}px; font-family: ${fontFamily};">
      [[content]]
    </body>
    </html>
    `;
    
    var html = template.replace("[[content]]", html);
    
    // Place in clipboard as rich-text
    if (!app.htmlToClipboard(html)) {
    	context.fail("Error rendering rich text from HTML.");
    }

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.