BBEdit Smartquotes Breaking TextFilters

Todd's Avatar


11 Feb, 2017 05:52 PM

I had "Educate Quotes" turned on in BBEdit. Whenever I ran the Accept CMark or Reject CMark TextFilter on a sequence that included curly quotes, I got an error: invalid byte sequence in US-ASCII (Argument Error)

I solved this by adding the UTF-8 text to the top of the ruby script. Not sure if this might cause more problems in the long run, but I suppose there might be a few of us out there using non-ASCII, UTF-8 characters.


#!/usr/bin/env ruby
# CriticMarkup reject change script for BBEdit
  Encoding.default_external = Encoding::UTF_8
  Encoding.default_internal = Encoding::UTF_8

myMark =

# CriticMarks
# -----------
# Addition {++ ++}
# Deletion {-- --}
# Substitution {~~ ~> ~~}
# Comment {>> <<}
# Highlight {== ==}{>> <<}

addition_mark = /^\{\+\+(.+?)\+\+\}$/
deletion_mark = /^\{\-\-(.+?)\-\-\}$/
sub_mark = /^\{\~\~(.+?)\~\>(.+?)\~\~\}$/
comment_mark = /^\{\>\>(.+?)\<\<\}$/
highlight_mark = /^\{\=\=(.+?)\=\=\}$/

if addition_mark =~ myMark
  print ""
elsif  deletion_mark =~ myMark
  print myMark.gsub(deletion_mark, "\\1")
elsif sub_mark =~ myMark
  print myMark.gsub(sub_mark, "\\1")
elsif highlight_mark =~ myMark
  print myMark.gsub(highlight_mark, "\\1")
elsif comment_mark =~ myMark
  print ""

P.S. -- Before you copy that script wholesale, note that I did add reject parameters for comments and highlights that you may or may not want to add.

Let me know if you see any issues while using--maybe someone'll come up with a better solution (such as reading whatever encoding you have selected, somehow).

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

11 Feb, 2017 05:52 PM
29 Dec, 2016 04:25 PM
25 Feb, 2016 08:57 AM
15 Feb, 2016 10:52 PM
08 Apr, 2015 11:07 AM