Action

CSV to Markdown Table

Posted by Aidan Maurin-Jones, Last update about 2 months ago

Converts CSV formated text to a Markdown table

Steps

  • script

    // Full transparency - this script was written using ChatGPT-4
    let action = async () => {
        let clipboardContentString = editor.getSelectedText();
        let lines = clipboardContentString.split('\n');
        let table = '';
    
        for (let i = 0; i < lines.length; i++) {
            let row = lines[i].split(',');
            row = row.map(cell => cell.trim()); // Trim whitespace from each cell
    
            if (i === 1) {
                // Add the Markdown table header
                table += '| ' + ' --- |'.repeat(row.length) + '\n';
            }
    
            if (row.length > 1) { // Ignore empty lines
                table += '| ' + row.join(' | ') + ' |\n';
            }
        }
    
        editor.setSelectedText(table);
    }
    
    action();

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.