Action

Transclude > New Draft

Posted by agiletortoise, Last update over 3 years ago

Replace any [[Wiki-Style Links]] to other drafts with the content of the draft they are linked to and output the full content to a new draft.

Steps

  • script

    let findLinkedDraft = (title) => {
    	let found = Draft.queryByTitle(title);
    	if (found.length == 0) {
    		return null;
    	}
    	return found[0];
    }
    
    let transclude = (d) => {
    	let re = /\[\[(.+?)\]\]/gm;
    	let content = draft.content;
    
    	content = content.replace(re, (match, title) => {
    		let d = findLinkedDraft(title);
    		if (d) {
    			return d.content;
    		}
    		else { // not found, leave as-is
    			return match;
    		}
    	});
    	return content;
    }
    
    // expand links to their content and create new draft...
    let newDraft = new Draft();
    newDraft.content = transclude(draft);
    newDraft.update();
    editor.load(newDraft);

Options

  • After Success Nothing
    Notification None
    Log Level None
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.