Editorial Workflows

Literate Source Code

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: Explain and Code.

Let us change our traditional attitude to the construction of programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do. — Donald E. Knuth

Version : 1.0.0+20131028
License : The MIT License (c) 2013 Stefano F. Rausch < stefano@rausch-e.net >
See : https://github.com/StefanoRausch/Literate-Source-Code

Shared by: Stefano F. Rausch — @StefanoRausch

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Set Variable ?
Variable Name
feedbackHUD
Value
true
Set Variable ?
Variable Name
fileExtension
Value
File Extension
Set Variable ?
Variable Name
fileExtensionError
Value
true
Set Variable ?
Variable Name
fileName
Value
File Name
Set Variable ?
Variable Name
fileNameError
Value
true
If File Extension Is Markdown ?
Run the block if
fileExtension
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
(md|mkd|mkdn|mdwn|mdown|markdown)
Set Variable ?
Variable Name
fileExtensionError
Value
false
If File Name Ends With Supported Extension ?
Run the block if
fileName
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
.+\.(coffee|css|js|haml|html|ini|jade|json|less|php|rool|sass|scss|stylus)
Set Variable ?
Variable Name
fileNameError
Value
false
Get Bookmark URL ?
Include Selected Range
OFF
Set Variable ?
Variable Name
bookmarkURL
Value
Input
Remove Editorial Prefix From File Path ?
Find
.+open/
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
Remove File Extension From Path ?
Find
(.+)\.(md|markdown)(\?root=dropbox)?$
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
$1
Set Variable ?
Variable Name
filePath
Value
Input
Get Document Text ?
Folded Text
  • Include
  • Replace with:
Process Literate Source Code ?
Source Code
#coding: utf-8

# Literate Source Code Implementation
#
# version : 1.0.0+20131028
# license : The MIT License (c) 2013 Stefano F. Rausch < stefano@rausch-e.net >
# see     : https://github.com/StefanoRausch/Literate-Source-Code

import re
import workflow

documentText = workflow.get_input()

# Regular Expression Patterns

documentationLines      = re.compile( r"^(\t|\S)+.*?$", re.DOTALL | re.MULTILINE )
multipleEmptyLines      = re.compile( r"\n+([ \t]*\n){2,}", re.DOTALL )
emptyLinesAtStartOfFile = re.compile( r"^(\n*[ \t]*\n)+" )
emptyLinesAtEndOfFile   = re.compile( r"(\n*[ \t]*\n)+$" )
oneLevelIndentation     = re.compile( r"^ {4}", re.DOTALL | re.MULTILINE )

# Source Code Extraction

documentText = documentationLines.sub( "", documentText )
documentText = multipleEmptyLines.sub( "\n\n", documentText )
documentText = emptyLinesAtStartOfFile.sub( "", documentText )
documentText = emptyLinesAtEndOfFile.sub( "\n", documentText )
documentText = oneLevelIndentation.sub( "", documentText )

workflow.set_output( documentText )
Set Variable ?
Variable Name
sourceCode
Value
Input
If File Is Local ?
Run the block if
bookmarkURL
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
?root=dropbox
Save Source File ?
File Name
%var:filePath
In Dropbox
OFF
New Text
sourceCode
If File Does Not Exist
  • Create
  • Stop Workflow
…End If
If File Is in Dropbox ?
Run the block if
bookmarkURL
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
?root=dropbox
Save Source File ?
File Name
%var:filePath
In Dropbox
ON
New Text
sourceCode
If File Does Not Exist
  • Create
  • Stop Workflow
…End If
If Feedback Is Requested ?
Run the block if
feedbackHUD
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
true
Show HUD ?
HUD Text
The source code has been extracted to fileName.
Duration
  • 1 Second
  • 2 Seconds
  • 3 Seconds
Icon
  • "Success"
  • "Error"
…End If
…End If
If File Name Ends Not With Supported Extension ?
Run the block if
fileNameError
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
true
Show Alert ?
Title
Message
ERROR The source code file extension is not supported.
Button 1
OK
Output Value
Button 2
(don't show)
Output Value
Button 3
(don't show)
Output Value
Show Cancel Button
OFF
…End If
…End If
If File Extension is Not Markdown ?
Run the block if
fileExtensionError
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
true
Show Alert ?
Title
Message
ERROR The literate source code file extension is not supported.
Button 1
OK
Output Value
Button 2
(don't show)
Output Value
Button 3
(don't show)
Output Value
Show Cancel Button
OFF
…End If
End of Workflow ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped