Editorial Workflows

Share

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: Calls console.quicklook to preview the current document. Tap the preview's share button to 'Open in ...' another app or to print. If the document is Markdown, you can convert it to HTML and you can share the HTML as a .txt file, so you can see the HTML tags in the preview.

Shared by: Peter Hopcroft

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
How to use this workflow ?
Source Code
"""
Editorial workflow: Share
Peter Hopcroft, 25 November 2013

Calls console.quicklook to preview the current document. Tap the preview's share button to 'Open in ...' another app or to print. If the document is Markdown, you can convert it to HTML and you can share the HTML as a .txt file, so you see the HTML tags in the preview.


Two issues with console.quicklook:
	
1.	 It expects your file to be in latin-1 encoding. Editorial uses utf-8 files and the app you are sharing the file to probably expects utf-8. Therefore, if your file has a utf-8 character that is more than one byte long you will see several junk latin characters in the preview.

2.	The preview never finishes loading a file with .md extension. You can still share it.


This assumes a file name containing '.m' is Markdown. For these, you choose an option:
	
*Don't convert to HTML*
Leave as is.

*Convert to HTML, a .html file*
See rendered HTML in the preview; you don't see the HTML tags

*Convert to HTML, a .txt file*
See the HTML tags in the preview.

"""
Get Current File Name ?
Include Folder
OFF
Include Extension
ON
If it doesn't seem to be a markdown file ?
Run the block if
Input
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
.m
Preview/share the file ?
Source Code
#coding: utf-8
import console
import editor

console.quicklook(editor.get_path())
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
It seems to be a Markdown file, choose an option ?
Title
That seems to be a Markdown file
Message
Choose an option
Button 1
Don't convert to HTML
Output Value
leave
Button 2
Convert to HTML, an .html file
Output Value
convert-html
Button 3
Convert to HTML, a .txt file
Output Value
convert-txt
Show Cancel Button
ON
Set Variable ?
Variable Name
Option
Value
Input
Maybe convert to markdown, then preview/share ?
Source Code
#coding: utf-8
import codecs
import console
import editor
import markdown
import os
import workflow

# the file currently open has a markdown extension

# Option can be 'leave', 'convert-html', 'convert-txt'
Option = workflow.get_variable('Option')
text = editor.get_text()
if 'convert' in Option:
    text = markdown.markdown(text, extensions=['tables', 'attr_list'])

# write text to temporary file for quicklook
f_n_e = editor.get_path()
f, n_e = os.path.split (f_n_e)
n,e = os.path.splitext(n_e)
if 'txt' in Option:	# the order of the if tests matters
    e = '.txt'
elif 'html' in Option:
    e = '.html'
else:								# file has a markdown extension
    e = e
    console.alert('The preview may never finish loading a markdown file', 
                  'But you can still share it', 'OK')

temp_file = n + e
f = codecs.open(temp_file, 'w', encoding='utf-8', errors='replace')
f.write(text)
f.close()

console.quicklook(os.path.abspath(temp_file))
os.remove(temp_file)