Last active
August 29, 2015 14:07
-
-
Save agiletortoise/48c322266ca4fd0ec8bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Drafts 4 script step to create custom tags | |
// using the a line or a default value if that line is empty or missing | |
// split draft into an array of lines | |
var lines = draft.content.split('\n'); | |
// reusable function to define tag based on line or default string | |
function createLineTag(lineNumber,default) { | |
var tagName = "line"+(lineNumber+1).toString(); | |
if(lines[lineNumber] && lines[lineNumber].length > 0) { | |
draft.defineTag(tagName, lines[lineNumber]); | |
} | |
else { | |
draft.defineTag(tagName, default); | |
} | |
} | |
// call for each line you want a tag for... | |
createLineTag(0, "first line default string"); | |
createLineTag(1, "second line default string"); | |
// templates in steps after this script step in an action | |
// can use [[line1]], [[line2]] tags to get line or default values. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment