Editorial Workflows

WebArticle2MD

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: Converts the HTML in clipboard (set from Workflow.app) to markdown, and opens the .md file in other apps.

Markdown also get copied to Clipboard.

Can easily be changed to also save to Dropbox (see comments in python action)

To capture only Article HTML in any browser, and pass it on to this workflow,
use: https://workflow.is/workflows/1b455f2b33d54b04ba93d9cb8c234a21

Also just delete the last action if Editorial is your markdown editor of choice.

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
If… ?
Run the block if
Input
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
ON
Message
No title in input
…End If
Set Variable ?
Variable Name
from_workflow
Value
Input
Declare empty variable ?
Variable Name
filename
Value
Get WebPage and Convert to Markdown ?
Source Code
#coding: utf-8
import workflow
import clipboard
import datetime
import html2text
import re
import os

folder = 'WebCapture'
usedropbox = True

# IMPORTANT:
# If saving to Dropbox, instead of locally 
# (switch to Dropbox in both 'Set File Content' and 'Open Document' actions),
# 'folder' above has to be manually created before use (or left blank),
# and also, 'usedropbox' above, should be set to True!

if not usedropbox:
	root = os.path.join(os.path.expanduser("~"), "Documents")
	fullpath = os.path.join(root, folder)
	if not os.path.isdir(fullpath):
		os.mkdir(fullpath)	

filedate = datetime.datetime.today().strftime('%Y-%m-%d_%H%M')
filename = 'Article_' + filedate + '.md'
filepath = os.path.join(folder, filename)

h = html2text.HTML2Text()
h.body_width = 0

#input = workflow.get_input().split('||')
input = workflow.get_variable('from_workflow').split('|||')

title, url, root = '', '', ''
try:
	title = '# ' + input[1] + '\n\n'
	url = input[0]
	root = re.sub(r'^.*?//(.+?)/.*', r'\1', url)
except:
	pass

datestamp = datetime.datetime.today().strftime('%Y-%m-%d at %H:%M')
source = '_Captured: ' + datestamp + ' from [' + root + '](' + url + ')_\n\n'

workflow.set_variable('filename', filepath)

html = clipboard.get()

#print html
html = re.sub(r'(?s)<!--.*?-->', '', html)
html = re.sub(r'(?s)<script.*?</script>', '', html)
html = re.sub(r'(?s)(<figure>.*?</figure>)', r'\1<p/>', html)
html = re.sub(r'(?s)<figcaption>(.*?)</figcaption>', r'<p>&gt; _\1_</p>', html)
#print html

action_out = title + source + h.handle(html)

clipboard.set(action_out)
workflow.set_output(action_out)
Set File Contents ?
File Name
%var:filename
In Dropbox
ON
New Text
Input
If File Does Not Exist
  • Create
  • Stop Workflow
Open Document ?
File Name
%var:filename
In Dropbox
ON