Editorial Workflows

cleanup line breaks in all

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: Take a text with line breaks within paragraphs (e.g. OCRed, converted from something, badly copy-pasted) and get rid of them. Also put space between all paragraphs rather than tab at start.

Shared by: Paul Gowder (paul-gowder.com)

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
#coding: utf-8
import editor, re

text = editor.get_text()	

def tab_paras_to_double_lines(s):
	return re.sub("\n\t", "\n\n", s)

def de_leading_trailing(s):
	s1 = re.sub(" \n", "\n", s)
	return re.sub("\n ", "\n", s1)

def fix_unspaced(mobj):
	m = mobj.group(0)
	return m[0] + " " + m[2]

def de_break(s):
	return re.sub("[^\s]\n[^\s]", fix_unspaced, s)

def clean_lines(s):
	return de_break(de_leading_trailing(tab_paras_to_double_lines(s)))

fixed = clean_lines(text)

editor.replace_text(0, len(text), fixed)