Editorial Workflows

Insert MD-Table

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 Editoral-WF inserts a MD-table template.

It prompts the user to either specify a number of columns e.g 4 or a sequence of L, C or R to specify L(eft), C(enterd) or R(ight) alignment, e.g LLCR. The WF prompts the user also for the number of rows. The table will contain placeholders which can easily be selected for editing by double tapping.

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
# Insert MD-table,
# prompts for number of columns and rows,
# instead of number of columns an alignment sequence can be given like LLCLR
# L=left, C=centered, R=right aligned
# V2, Olivier Roth, 22.1.2015

import workflow
import console
import editor

range = editor.get_selection()

text = editor.get_selected_text()
if len(text) > 0:
	console.hud_alert('don\'t select anything for this workflow', 'error', 1.0)
	workflow.stop()

xCols = console.input_alert('Columns: Number or Alignment Sequence "LCR"')
if xCols.isdigit():
	nCols = int(xCols)
else:
	tCols = list(xCols.upper())
	nCols = len(tCols)

try:
	nRows = int(console.input_alert('Number of Rows'))
except:
	console.hud_alert('Invalid Row-Number', 'error', 1.0)
	workflow.stop()

text1 = '\n|'
text2 = '|'

iC = 0
while (iC < nCols):
	text1 = text1 + ' TITLE' + str(iC+1) + ' |'
	if xCols.isdigit():
		t = ' --- |'
	else:
		if   tCols[iC] == "L": t = ":--- |"
		elif tCols[iC] == "C": t = ":---:|"
		elif tCols[iC] == "R": t = " ---:|"
		else:
			console.hud_alert('Invalid Alignment Code', 'error', 1.0)
			workflow.stop()
	text2 = text2 + t
	iC = iC + 1
text1 = text1 + '\n'
text2 = text2 + '\n'

text3 = ''
iR = 1
while (iR <= nRows):
	iC = 1
	text3 = text3 + '|'
	while (iC <= nCols):
		text3 = text3 + ' XXX' + str(iR) + 'x' + str(iC) + ' |'
		iC = iC + 1
	text3 = text3 + '\n'
	iR = iR + 1
text3 = text3 + '\n'

output = text1 + text2 + text3

editor.replace_text(range[0], range[1], output[0:-1])

workflow.stop()