SmartBlocks icon indicating copy to clipboard operation
SmartBlocks copied to clipboard

Roam Bounty:: Codeblock Parser

Open bathrobe opened this issue 4 years ago • 0 comments

✂️ Copy of your #42SmartBlock from Roam

  • Code (copy this block ref)
const CB = roam42.smartBlocks.activeWorkflow.vars["clipBoard"];
const ticks = "`" + "`" + "`"
const regString = "(" + ticks +")(.*?)("+ ticks + ")";
let re = new RegExp(regString, "gs");
const codeBlocks = [...CB.matchAll(re)].map(block=> "\n//"+block[2]+'\n').join('')
roam42.smartBlocks.activeWorkflow.vars["codeBlocks"] =  codeBlocks;
  • #42SmartBlock Codeblock Parser - Roam Bounties
    • <%SET:clipBoard,<%CLIPBOARDPASTETEXT%>%><%NOBLOCKOUTPUT%>
    • <%JA:<%RESOLVEBLOCKREF:YOUR_BLOCK_REF_HERE%>%><%NOBLOCKOUTPUT%>
    • <%CLIPBOARDCOPY:<%GET:codeBlocks%>%><%NOBLOCKOUTPUT%>
    • <%NOTIFICATION:20,Codeblocks copied to clipboard!%><%NOBLOCKOUTPUT%>

📋 Describe the SmartBlock

Copy a multi-block set of codeblocks and plain text and this SmartBlock will return ONLY your codeblocks, minus the backticks and separated by linebreaks. Loom here! https://www.loom.com/share/b331778d90af46bca25453b1d4468802

✅ Describe any prerequisites or dependencies that are required for this SmartBlock

Make sure your browser's new enough to use the matchAll method for regular expressions (it probably is, I'd bet). Loom below!

📷 Screenshot of your #42SmartBlock workflow/template from Roam

image

bathrobe avatar Dec 31 '20 00:12 bathrobe