Action

Headings to List

Posted by sylumer, Last update over 2 years ago - Unlisted

Steps

  • script

    // Param 1 = the text to be transformed.
    // Param 2 = the number of heading levels to transform.
    function headingsToList(p_strContent, p_intLevels)
    {
    	const SPACER = "	";
    	const LIST_ITEM = "-";
    	let strResult = p_strContent;
    	for (let intCount = p_intLevels; intCount > 0; intCount--)
    	{
    		let reSub = new RegExp("^" + "#".repeat(intCount), "gm");
    		strResult = strResult.replace(reSub, SPACER.repeat(intCount - 1) + LIST_ITEM)
    	}
    	return strResult;
    }
    
    draft.content = headingsToList(draft.content, 6);
    draft.update();

Options

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