src/Leevel/View/Compiler.php
public function attributeNodeCompiler(array &$theme): void
    {
        $source = trim($theme['content']);
        $source = $this->escapeRegexCharacter($source);

        if (true === $theme['is_js']) {
            $tag = $this->jsTag;
        } else {
            $tag = $this->nodeTag;
        }

        $allowedAttr = $tag[$theme['parent_name']]['attr'];

        // 正则匹配
        $regexp = [];

        if (!$theme['is_js']) {
            // xxx="yyy" 或 "yyy" 格式
            $regexp[] = '/(([^=\\s]+)=)?"([^"]+)"/';

            // xxx='yyy' 或 'yyy' 格式
            $regexp[] = "/(([^=\\s]+)=)?'([^\\']+)'/";
        }

        // xxx=yyy 或 yyy 格式
        $regexp[] = '/(([^=\\s]+)=)?([^\\s]+)/';

        $nameIdx = 2;
        $valueIdx = 3;
        $defaultIdx = 0;

        foreach ($regexp as $item) {
            if (preg_match_all($item, $source, $res)) {
                foreach ($res[0] as $idx => $attribute) {
                    $source = str_replace($attribute, '', $source);
                    $name = $res[$nameIdx][$idx];

                    if (empty($name)) {
                        $defaultIdx++;
                        $name = 'condition'.$defaultIdx;
                    }

                    $value = $res[$valueIdx][$idx];
                    $value = $this->escapeRegexCharacter($value, false);
                    $theme['attribute_list'][strtolower($name)] = $value;
                }
            }
        }

        // 补全节点其余参数
        foreach ($allowedAttr as $item) {
            if (!isset($theme['attribute_list'][$item])) {
                $theme['attribute_list'][$item] = null;
            }
        }

        $theme['content'] = $source;
    }
public function attributeNodeCompiler(array &$theme): void
    {
        $source = trim($theme['content']);
        $source = $this->escapeRegexCharacter($source);

        if (true === $theme['is_js']) {
            $tag = $this->jsTag;
        } else {
            $tag = $this->nodeTag;
        }

        $allowedAttr = $tag[$theme['parent_name']]['attr'];

        // 正则匹配
        $regexp = [];

        if (!$theme['is_js']) {
            // xxx="yyy" 或 "yyy" 格式
            $regexp[] = '/(([^=\\s]+)=)?"([^"]+)"/';

            // xxx='yyy' 或 'yyy' 格式
            $regexp[] = "/(([^=\\s]+)=)?'([^\\']+)'/";
        }

        // xxx=yyy 或 yyy 格式
        $regexp[] = '/(([^=\\s]+)=)?([^\\s]+)/';

        $nameIdx = 2;
        $valueIdx = 3;
        $defaultIdx = 0;

        foreach ($regexp as $item) {
            if (preg_match_all($item, $source, $res)) {
                foreach ($res[0] as $idx => $attribute) {
                    $source = str_replace($attribute, '', $source);
                    $name = $res[$nameIdx][$idx];

                    if (empty($name)) {
                        $defaultIdx++;
                        $name = 'condition'.$defaultIdx;
                    }

                    $value = $res[$valueIdx][$idx];
                    $value = $this->escapeRegexCharacter($value, false);
                    $theme['attribute_list'][strtolower($name)] = $value;
                }
            }
        }

        // 补全节点其余参数
        foreach ($allowedAttr as $item) {
            if (!isset($theme['attribute_list'][$item])) {
                $theme['attribute_list'][$item] = null;
            }
        }

        $theme['content'] = $source;
    }
属性编译.

@param array $theme