Text filter deletes source file content

30 views
Skip to first unread message

Martin Post

unread,
Feb 4, 2023, 6:27:25 AM2/4/23
to BBEdit Talk
If I apply this Text filter (pandoc.sh):

cd "$(dirname "$BB_DOC_PATH")";
pandoc --from markdown --to html --standalone "${BB_DOC_PATH}" -o "${BB_DOC_PATH%%.*}".html

…to a text file (with nothing selected), the converted HTML file will be stored as expected – but the content of the open text file will be deleted. This is undoable, but why does it happen / how can it be avoided?

(I have used similar scripts as *Preview* filters for years, where this problem didn’t occur.)

Thank you.

Fletcher Sandbeck

unread,
Feb 4, 2023, 11:42:27 AM2/4/23
to bbe...@googlegroups.com
The text filter replaces the content of the BBEdit document with the output of the script which is empty.

You can put the same script in the Scripts folder and run it from there without this happening. You need to add a #!/bin/sh or similar line to the top.

You could also probably just echo the original file back to BBEdit at the end of the script.

cat "$(BB_DOC_PATH)"

Hope this helps,

[fletcher]


--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/54c684f0-c7f3-4d05-85d9-e9e0b78ed732n%40googlegroups.com.

Martin Post

unread,
Feb 4, 2023, 2:22:30 PM2/4/23
to BBEdit Talk
Thank you, Fletcher. Putting the script into the Scripts folder works without side effects. :)

I also found that a reduced, stdin/stdout-ish version of the filter (without cd "$(dirname "$BB_DOC_PATH")" and an -o target file), i.e.

pandoc --from markdown --to html --toc --standalone "${BB_DOC_PATH}"

… returns Pandoc’s output to the current window, allowing for in-place conversion. Nice!
Reply all
Reply to author
Forward
0 new messages