Editorial Workflows

Line width to 80 characters

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: If you like your text only 80 characters wide per line, run this workflow!

It uses python to grab the text you’ve written (no need to select it or copy to clipboard) and the wrap function to limit the line width to 80 characters.

There’s an extra step built in to preserve blank lines.

The function finishes by selecting all text and replacing it with the newly limited text.

Shared by: ohthreefive

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
# import functions from modules
from textwrap import wrap
from editor import get_text, set_selection, insert_text

# set variable to text in editor using get_text() function
inputText = get_text()

# convert this string to a list, using new lines to split string
inputList = inputText.splitlines()

# declare empty list which the following loop will fill
outputList = []

# loop through list (which contains get_text)
for i in inputList:
# if line was blank, add NEWLINE to outputList
# (if i dont do this, these empty lines will be lost by the wrap() function)
	if i == '':
		outputList.append('NEWLINE')
# otherwise use wrap() function to limit line width to 80 characters
# (wrap() outputs to a list which ive called 'shortened')
	else:
		shortened = wrap(i, width = 80)
# iterate through the shortened list, adding each entry of that list to
# outputList
# if i just added 'shortened' to 'outputList', i would have lists within a list
# i want one list
		for j in shortened:
			outputList.append(j)

# take the outputList and make it back in to a string, adding a new line
# between each line item
outputText = "\n".join(outputList)
# replace the NEWLINE placeholder with nothing, restoring the empty lines
outputText = outputText.replace("NEWLINE","")

# find out how long the outputText is
characters = len(outputText)

# select all text in editor
set_selection(0,characters)

# replace selected text with newly edited text
insert_text(outputText)