Drafts Action Directory

Switch Syntax…

Posted by @mattgemmell, Last update 3 months ago

Shows a popup allowing you to choose a new syntax-highlighting scheme (grammar) for the current draft, i.e. choosing between Markdown, Taskpaper, etc.

Install

Steps

  • script

    var syntaxList = ["Plain Text", "Markdown", "Simple List", "Taskpaper", "JavaScript"];
    var currentGrammar = draft.languageGrammar;
    
    var p = Prompt.create();
    
    p.title = "Switch Syntax";
    p.message = "Currently: " + currentGrammar;
    
    p.addSelect("listSelect", "Syntax", syntaxList, [currentGrammar], false);
    p.addButton("Switch Syntax");
    
    var didSelect = p.show();
    
    var selectedGrammar = p.fieldValues["listSelect"];
    
    if (p.buttonPressed == "Switch Syntax" && currentGrammar != selectedGrammar) {
    	draft.languageGrammar = selectedGrammar;
    	draft.update();
    	app.displaySuccessMessage("Switched to " + selectedGrammar);
    }

Options

  • After Success Default
    Notification Error
    Log Level Info

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.