Pygments supports [filters]( https://pygments.org/docs/filters/ ), and some of them like [TokenMergeFilter]( https://pygments.org/docs/filters/#TokenMergeFilter ) could [significantly help]( https://github.com/pygments/pygments/issues/2363 ) with reducing the size of the produced html on some pathological cases.