Editorial Workflows

Convert Lazy References

unlisted 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: Convert lazy reference links in the format of [link][*] to numbered references.

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Set a placeholder for the status message ?
Variable Name
resultText
Value
Send entire document to script ?
Folded Text
  • Include
  • Replace with:
Convert references ?
Source Code
#coding: utf-8
import workflow
import re

text = workflow.get_input()
link_id = 0

def replace(match):
	return match.group(1) + str(link_id) + match.group(2) +str(link_id) + ']:'

def perform_replacement():
	global link_id
	global text
	find = re.compile('(\[[^\]]+\]\s*\[)\*(\].*?\[)\*\]\:', re.DOTALL)
	match = find.search(text)
	while match:
		link_id += 1
		text = find.sub(replace, text, 1)
		match = find.search(text)

perform_replacement()
workflow.set_output(text)

ref_text = ' reference' if link_id == 1 else ' references'
workflow.set_variable('resultText', str(link_id) + ref_text + ' updated')
Set Variable ?
Variable Name
parsedText
Value
Input
Select all and... ?
Direction
  • Backward
  • Forward
  • Both
Unit
  • Start/End of Document
  • Start/End of Line
  • Number of Characters...
1
...replace with text from script ?
Replacement Text
parsedText
Put the cursor at the start of the document ?
Direction
  • Backward
  • Forward
  • Start/End of Document
  • Start/End of Line
  • Number of Characters:
1
Display a helpful status message ?
HUD Text
resultText
Duration
  • 1 Second
  • 2 Seconds
  • 3 Seconds
Icon
  • "Success"
  • "Error"