Skip to content

Instantly share code, notes, and snippets.

@agiletortoise
Last active August 29, 2015 14:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agiletortoise/48c322266ca4fd0ec8bf to your computer and use it in GitHub Desktop.
Save agiletortoise/48c322266ca4fd0ec8bf to your computer and use it in GitHub Desktop.
// 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