开发者

How can I get tidy to allow my custom attributes?

开发者 https://www.devze.com 2023-01-06 17:17 出处:网络
function myTidy($content) { $tidyConfig = array( \'indent\'=> false, //don\'t indent \'doctype\'=> \'omit\', //don\'t include doctype
function myTidy($content) {
    $tidyConfig = array(
        'indent'                        => false, //don't indent
        'doctype'                       => 'omit', //don't include doctype
        'wrap'                          => 0, // don't line wrap
        'show-body-only'                => true, //don't include <html><head><title><body>
        'drop-proprietary-attributes'   => false, //this doesn't seem to be helping with our youtube stuff...
    );
    $tidy = tidy_parse_string($content, $tidyConfig, 'UTF8');
    $tidy->cleanRepair();
    return (string)$t开发者_如何学Pythonidy;
}


echo myTidy('<span _my_custom_attr="asdfsdf">asdf</span>'), "\n";

Desired output

<span _my_custom_attr="asdfsdf">asdf</span>

Actual output:

<span>asdf</span>

What does it take to get tidy to allow my custom attribute?


I think a leading underscore make the attibute invalid, so tidy will remove it, even if your tell him not to remove unknown attributes.


Turns out removing the leading underscore in the attribute name resolves the issue -- my_custom_attr works fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消