Action

Copy as Rich Text - V2

Posted by deanfx, Last update about 4 hours ago

Updated version of the original Copy as Rich Text, but preserves line breaks and paragraphs from the original document.

Steps

  • script

    // Process Markdown to HTML
    var mmd = MultiMarkdown.create();
    var html = mmd.render(draft.content);
    
    // Convert single line breaks inside paragraphs to <br>
    html = html.replace(/([^\n])\n([^\n])/g, "$1<br>\n$2");
    
    // Wrap raw MMD output with HTML template with styles to set base fonts
    var template = `<html>
    <body style="font-family: -apple-system, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.5; margin: 0;">
      [[content]]
    </body>
    </html>
    `;
    
    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.