Editorial Workflows

Regex Highlight

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: This workflow highlights any text matching regular expressions with custom colors. To use it, enter comma-separated regex and hex colors in the first variable of the workflow. Enter only one regex/color pairing per line of the variable. The variable is prefilled with three example regex/color pairings. When activated, the current document opens in the preview panel with matches highlighted with their corresponding colors.

Shared by: http://pronetobits.net/

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Enter one comma-separated regex pattern and color per line ?
Variable Name
fox, #B28647 [Dd]og, #FF0000 \{(.*?)\}, #FFF888
Document Text ?
Folded Text
  • Include
  • Replace with:
Set Variable ?
Variable Name
Run Python Script ?
Source Code
#coding: utf-8
import workflow
import markdown
import re

action_in = workflow.get_input()

hl = action_in

patterns = workflow.get_variable('patterns_colors')
patternsLines = patterns.splitlines()

# This loops through the document text and replaces patterns with highlights
for i in patternsLines:
	pattern = i.split(', ')[0]
	color = i.split(', ')[1]
	regexReplace = '<mark style=\"background-color:' + color + ';\">\\1</mark>'
	hl = re.sub(r'(%s)' % pattern, regexReplace, hl)

# This builds the html for preview
# Put your custom css in the style section
h = markdown.markdown(hl, ['extra'])

header = '''
<!DOCTYPE html>

<meta charset="utf-8"/>
body {font-family:Source Sans Pro; font-size:medium}


footer = '''


#TODO: Generate the output...
action_out = header + h + footer

Show HTML ?
Base URL