Preserve paragraphs

i made an extension which prepends the selected text to a markdown file (together with a date stamp) and it works great except it doesn’t respect paragraph breaks. is there a simple coding trick to fix this?

this is my code

file=/path/to/file.md
echo "$(date '+%Y%m%d-%H%M')" >> $file   
# Add the current date and time at the end of the file
echo -e "$POPCLIP_TEXT\n$(date '+%Y%m%d-%H%M')\n" | cat - "$file" > temp && mv temp "$file"   
# Prepend the text followed by the date

thanks as always!

ps i did look at the ‘copy as markdown’ extension with a view to perhaps hacking the two together somehow but i am already way beyond the limits of my tiny coding brain. so i’d be very happy just with paragraph breaks.

Easiest to use PopClip’s built in Markdown support. Instead of POPCLIP_TEXT use POPCLIP_MARKDOWN instead. Then the content will be pre-baked as markdown with blank lines for paragraph breaks, which sounds like is exactly what you want.

You’ll need to add “capture html” = “true” in your Config file (how that appears depends on what format you chose for Config file … let me know if you need help!)

thanks nick! i am using YAML but # capture html: true doesn’t work…

this is what i tried

#!/bin/zsh
# #popclip
# name: clipping
# icon: →
# stdin: text
# capture html: true

file=/path/to/file.md
echo "$(date '+%Y%m%d-%H%M')" >> $file   
# Add the current date and time at the end of the file
echo -e "$POPCLIP_MARKDOWN\n$(date '+%Y%m%d-%H%M')\n" | cat - "$file" > temp && mv temp "$file"   
# Prepend the text followed by the date

Please don’t just say “doesn’t work” when describing a problem. Tell me exactly what happens – steps leading up to the failure and and what the exact error or failure condition is.

When I install this snippet, it installs fine but when I invoke it on text PopClip shows the X.

I opened the Console app (with PopClip debug output enabled and saw an error in the script that “/path/to/file.md” does not exist.

I changed the path to “~/clips.txt” and it appears to work OK for me.

very curious.
doesn’t work = it didn’t capture any text. i only got the date stamp in my .md file (in my real script i had the real path! i just replaced it with the generic path/to/file.md for the sake of publishing the snippet online.)

so i set popclip debug output in the console app to true to see what was going on and restarted popclip. and now it works! so unless there was something peculiar about the texts i tried to capture before, could it be that restarting popclip fixed it? anyhoo thanks for your help! i’ll come back and reply to this post if i encounter any further errors.

1 Like

Hard to say … but it’s working now :raising_hands:

2 Likes