4 * Parser that converts `pygmetize` output or similar HTML blocks from "class"
5 * attributes to "style" attributes.
7 final class PhutilPygmentizeParser
extends Phobject
{
9 private $map = array();
11 public function setMap(array $map) {
16 public function getMap() {
20 public function parse($block) {
21 $class_look = 'class="';
22 $class_len = strlen($class_look);
28 $len = strlen($block);
31 for ($ii = 0; $ii < $len; $ii++
) {
35 // We're in general text between tags, and just passing characers
36 // through unmodified.
43 // We're inside a tag, and looking for `class="` so we can rewrite
49 if (!substr_compare($block, $class_look, $ii, $class_len)) {
56 if ($mode != 'class') {
61 // We're inside a `class="..."` tag, and looking for the ending quote
62 // so we can replace it.
64 $class = substr($block, $class_start, $ii - $class_start);
66 // If this class is present in the map, rewrite it into an inline
68 if (isset($map[$class])) {
69 $out .= 'style="'.phutil_escape_html($map[$class]).'"';
71 $out .= 'class="'.$class.'"';