Action

Slugify Selection

Posted by @mattgemmell, Last update over 6 years ago

Transforms the selected text into a “slug”, i.e. a URL-safe, lowercase version of itself, with spaces converted to hyphens, and various special characters removed. Useful for filenames and web permalinks.

Steps

  • script

    // Slugify selected text.
    var selectedText = editor.getSelectedText();
    
    var slug = selectedText.toLowerCase()
    				.replace(/["'=:!?@£#$%&\*\(\)\[\]_\+\|;~`<>,\.]+/g, '')
    				.replace(/ +/g,'-');
    
    editor.setSelectedText(slug);

Options

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