Editorial Workflows

Render to PDF

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Convert a Markdown document to HTML and call an app that makes PDF out of that.

Contains a general purpose script to pass data to other apps (that have a URL scheme) using a temporary local web server.

Shared by: @myvanity

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Document Text ?
Folded Text
  • Include
  • Replace with:
Convert Markdown ?
Markdown Extras: Footnotes
ON
…Auto-Links
ON
…Strikethrough (~~x~~)
ON
…Superscript (^x)
ON
…Tables
ON
…Smart Quotes etc.
ON
…Strip Metadata Headers
OFF
Serve HTML ?
Source Code
from BaseHTTPServer import BaseHTTPRequestHandler
from SocketServer import TCPServer
import threading
import webbrowser

from workflow import get_input

SCHEME = 'rhttp'    # Readdle Documents
CHARSET = 'utf-8'

class HTTPRequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', self.server.content_type)
        self.end_headers()
        self.wfile.write(self.server.content)

    def log_request(self, *args):
        pass    # Prevent console from appearing

class HTTPServer(TCPServer):
    def __init__(self, content, content_type):
        self.content = content
        self.content_type = content_type
        TCPServer.__init__(self, ('', 0), HTTPRequestHandler)

httpd = HTTPServer(get_input().encode(CHARSET),
    'text/html; charset=' + CHARSET)

thread = threading.Thread(target=httpd.handle_request)
thread.daemon = True
thread.start()

webbrowser.open('rhttp://%s:%i' % httpd.server_address)
# Raises when scheme not registered, except in Editorial

thread.join(30)
if thread.isAlive():
    raise KeyboardInterrupt('Offer timed out')