gajus / dindent

HTML indentation library for development and testing.
Other
180 stars 31 forks source link

Contents of <pre> should not be parsed #25

Open inoas opened 7 years ago

inoas commented 7 years ago

I am building some Twig based Content Application Framework and when debugging <pre>'s newlines and whitespaces should be left untouched to support plain-text content type.

inoas commented 7 years ago

Moving from:

case 'PLAINTEXT':
    $entity->translated_body = '<pre class="plaintext">'
        . nl2br(htmlentities(
            $entity->translated_body, ENT_XML1 | ENT_NOQUOTES | ENT_SUBSTITUTE), true)
        . '</pre>';
    break;

To:

case 'PLAINTEXT':
    $entity->translated_body = htmlentities(
        $entity->translated_body, ENT_XML1 | ENT_NOQUOTES | ENT_SUBSTITUTE);
    $entity->translated_body = str_replace(' ', '&#160;', $entity->translated_body);
    $entity->translated_body = str_replace("\t", '&#9;', $entity->translated_body);
    $entity->translated_body = nl2br($entity->translated_body, true);
    $entity->translated_body = '<pre class="plaintext">' .  $entity->translated_body . '</pre>';
    break;

Resolved most of the issue but there is still the left padding injected by indent() that shifts the <pre> output to the right.