tiny refactor to nbconvert ansi filter

was looking at this code for another project, and was irked by what I
saw here, so just cleaned it up.
Merge pull request #5912 from ivanov/ansi-filter-ref

tiny refactor to nbconvert ansi filter