stuartcusackie / cdom
在Laravel项目中为标记添加类。
1.0.16
2022-07-06 12:18 UTC
Requires
- php: ^7.4 || ^8.0
- simplehtmldom/simplehtmldom: ^2.0@RC
README
一个辅助函数,用于向HTML字符串中的元素添加类。对Tailwind项目非常有用。专为Laravel设计。
安装
composer require stuartcusackie/cdom
发布
php artisan vendor:publish
Tailwind Purge
Tailwind需要了解此cdom配置文件,以便在purge中保持类的维护。
content: [
...
'./config/cdom.php'
],
配置
您可以为您的应用程序设置多个样式。
示例样式配置
'style1' => [
'a' => 'underline text-blue-500 hover:text-blue-900 visited:text-blue-900',
'h1' => 'text-5xl 2xl:text-6xl font-display font-bold mb-12 text-highlight-primary',
'h2' => 'text-4xl 2xl:text-5xl font-display font-semibold mb-8 mt-12 first:mt-0',
'h3' => 'text-3xl 2xl:text-4xl font-display font-semibold mb-6 mt-12 first:mt-0',
'h4' => 'text-2xl 2xl:text-3xl mb-6',
'h5' => 'text-xl 2xl:text-2xl font-semibold mb-4',
'ul' => 'pl-5 list-disc',
'ol' => 'pl-5 list-decimal',
'li' => 'mb-2 last:mb-0',
'p, ul, ol, table' => 'mb-4 last:mb-0',
'blockquote' => 'border-l-8 p-3 mb-5 text-xl border-gray-200',
'table' => 'w-full border-r text-left border-gray-200',
'table tbody' => 'border-t border-gray-200',
'table tr' => 'border-b border-gray-200 odd:bg-gray-100',
'table td, table th' => 'border-l px-3 py-1 border-gray-200',
'table th' => 'odd:bg-gray-200'
]
用法
要转换标记,请使用cdom
辅助函数。您可以传递配置中的样式名称,或者让它回退到默认值。您还可以传递一个覆盖数组。
{!! cdom($content) !!}
{!! cdom($content, 'yourconfigstylename') !!}
要从样式配置中获取单个HTML元素的类,请使用cdomel
辅助函数。您可以传递配置中的样式名称,或者让它回退到默认值。
<h1 class="{{ cdomel('h1') }}">Heading</h1>
<a href="/" class="{{ cdomel('a', 'style1') }}">Link</a>