|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of Laravel Markdown. |
| 7 | + * |
| 8 | + * (c) Graham Campbell <hello@gjcampbell.co.uk> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view the LICENSE |
| 11 | + * file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +use League\CommonMark\Extension\CommonMark\Node\Block\BlockQuote; |
| 15 | +use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode; |
| 16 | +use League\CommonMark\Extension\CommonMark\Node\Block\Heading; |
| 17 | +use League\CommonMark\Extension\CommonMark\Node\Block\ListBlock; |
| 18 | +use League\CommonMark\Extension\CommonMark\Node\Block\ListItem; |
| 19 | +use League\CommonMark\Extension\CommonMark\Node\Block\ThematicBreak; |
| 20 | +use League\CommonMark\Extension\CommonMark\Node\Inline\Code; |
| 21 | +use League\CommonMark\Extension\CommonMark\Node\Inline\Emphasis; |
| 22 | +use League\CommonMark\Extension\CommonMark\Node\Inline\Image; |
| 23 | +use League\CommonMark\Extension\CommonMark\Node\Inline\Link; |
| 24 | +use League\CommonMark\Extension\CommonMark\Node\Inline\Strong; |
| 25 | +use League\CommonMark\Extension\Table\Table; |
| 26 | +use League\CommonMark\Extension\Table\TableCell; |
| 27 | +use League\CommonMark\Extension\Table\TableRow; |
| 28 | +use League\CommonMark\Node\Block\Paragraph; |
| 29 | + |
| 30 | +return [ |
| 31 | + |
| 32 | + /* |
| 33 | + |-------------------------------------------------------------------------- |
| 34 | + | Enable View Integration |
| 35 | + |-------------------------------------------------------------------------- |
| 36 | + | |
| 37 | + | This option specifies if the view integration is enabled so you can write |
| 38 | + | markdown views and have them rendered as html. The following extensions |
| 39 | + | are currently supported: ".md", ".md.php", and ".md.blade.php". You may |
| 40 | + | disable this integration if it is conflicting with another package. |
| 41 | + | |
| 42 | + | Default: true |
| 43 | + | |
| 44 | + */ |
| 45 | + |
| 46 | + 'views' => true, |
| 47 | + |
| 48 | + /* |
| 49 | + |-------------------------------------------------------------------------- |
| 50 | + | CommonMark Extensions |
| 51 | + |-------------------------------------------------------------------------- |
| 52 | + | |
| 53 | + | This option specifies what extensions will be automatically enabled. |
| 54 | + | Simply provide your extension class names here. |
| 55 | + | |
| 56 | + | Default: [ |
| 57 | + | League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension::class, |
| 58 | + | League\CommonMark\Extension\Table\TableExtension::class, |
| 59 | + | ] |
| 60 | + | |
| 61 | + */ |
| 62 | + |
| 63 | + 'extensions' => [ |
| 64 | + League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension::class, |
| 65 | + League\CommonMark\Extension\DefaultAttributes\DefaultAttributesExtension::class, |
| 66 | + League\CommonMark\Extension\Table\TableExtension::class, |
| 67 | + ], |
| 68 | + |
| 69 | + /* |
| 70 | + |-------------------------------------------------------------------------- |
| 71 | + | Renderer Configuration |
| 72 | + |-------------------------------------------------------------------------- |
| 73 | + | |
| 74 | + | This option specifies an array of options for rendering HTML. |
| 75 | + | |
| 76 | + | Default: [ |
| 77 | + | 'block_separator' => "\n", |
| 78 | + | 'inner_separator' => "\n", |
| 79 | + | 'soft_break' => "\n", |
| 80 | + | ] |
| 81 | + | |
| 82 | + */ |
| 83 | + |
| 84 | + 'renderer' => [ |
| 85 | + 'block_separator' => "\n", |
| 86 | + 'inner_separator' => "\n", |
| 87 | + 'soft_break' => "\n", |
| 88 | + ], |
| 89 | + |
| 90 | + /* |
| 91 | + |-------------------------------------------------------------------------- |
| 92 | + | Commonmark Configuration |
| 93 | + |-------------------------------------------------------------------------- |
| 94 | + | |
| 95 | + | This option specifies an array of options for commonmark. |
| 96 | + | |
| 97 | + | Default: [ |
| 98 | + | 'enable_em' => true, |
| 99 | + | 'enable_strong' => true, |
| 100 | + | 'use_asterisk' => true, |
| 101 | + | 'use_underscore' => true, |
| 102 | + | 'unordered_list_markers' => ['-', '+', '*'], |
| 103 | + | ] |
| 104 | + | |
| 105 | + */ |
| 106 | + |
| 107 | + 'commonmark' => [ |
| 108 | + 'enable_em' => true, |
| 109 | + 'enable_strong' => true, |
| 110 | + 'use_asterisk' => true, |
| 111 | + 'use_underscore' => true, |
| 112 | + 'unordered_list_markers' => ['-', '+', '*'], |
| 113 | + ], |
| 114 | + |
| 115 | + /* |
| 116 | + |-------------------------------------------------------------------------- |
| 117 | + | HTML Input |
| 118 | + |-------------------------------------------------------------------------- |
| 119 | + | |
| 120 | + | This option specifies how to handle untrusted HTML input. |
| 121 | + | |
| 122 | + | Default: 'strip' |
| 123 | + | |
| 124 | + */ |
| 125 | + |
| 126 | + 'html_input' => 'strip', |
| 127 | + |
| 128 | + /* |
| 129 | + |-------------------------------------------------------------------------- |
| 130 | + | Allow Unsafe Links |
| 131 | + |-------------------------------------------------------------------------- |
| 132 | + | |
| 133 | + | This option specifies whether to allow risky image URLs and links. |
| 134 | + | |
| 135 | + | Default: true |
| 136 | + | |
| 137 | + */ |
| 138 | + |
| 139 | + 'allow_unsafe_links' => true, |
| 140 | + |
| 141 | + /* |
| 142 | + |-------------------------------------------------------------------------- |
| 143 | + | Maximum Nesting Level |
| 144 | + |-------------------------------------------------------------------------- |
| 145 | + | |
| 146 | + | This option specifies the maximum permitted block nesting level. |
| 147 | + | |
| 148 | + | Default: PHP_INT_MAX |
| 149 | + | |
| 150 | + */ |
| 151 | + |
| 152 | + 'max_nesting_level' => PHP_INT_MAX, |
| 153 | + |
| 154 | + /* |
| 155 | + |-------------------------------------------------------------------------- |
| 156 | + | Slug Normalizer |
| 157 | + |-------------------------------------------------------------------------- |
| 158 | + | |
| 159 | + | This option specifies an array of options for slug normalization. |
| 160 | + | |
| 161 | + | Default: [ |
| 162 | + | 'max_length' => 255, |
| 163 | + | 'unique' => 'document', |
| 164 | + | ] |
| 165 | + | |
| 166 | + */ |
| 167 | + |
| 168 | + 'slug_normalizer' => [ |
| 169 | + 'max_length' => 255, |
| 170 | + 'unique' => 'document', |
| 171 | + ], |
| 172 | + |
| 173 | + 'default_attributes' => [ |
| 174 | + Heading::class => [ |
| 175 | + 'class' => static function (Heading $node) { |
| 176 | + return match ($node->getLevel()) { |
| 177 | + 1 => 'text-xl font-semibold text-gray-900 dark:text-white mb-6 mt-8 first:mt-0', |
| 178 | + 2 => 'text-lg font-semibold text-gray-900 dark:text-white mb-4 mt-6', |
| 179 | + 3 => 'text-lg font-medium text-gray-900 dark:text-white mb-3 mt-5', |
| 180 | + 4 => 'text-base font-medium text-gray-900 dark:text-white mb-2 mt-4', |
| 181 | + 5 => 'text-base font-medium text-gray-900 dark:text-white mb-2 mt-3', |
| 182 | + 6 => 'text-base font-medium text-gray-700 dark:text-gray-300 mb-2 mt-3', |
| 183 | + default => 'font-medium text-gray-900 dark:text-white mb-2 mt-3', |
| 184 | + }; |
| 185 | + }, |
| 186 | + ], |
| 187 | + // Paragraphs with proper spacing |
| 188 | + Paragraph::class => [ |
| 189 | + 'class' => 'text-gray-700 dark:text-gray-300 leading-relaxed mb-4', |
| 190 | + ], |
| 191 | + |
| 192 | + // Links styled like Flux buttons/links |
| 193 | + Link::class => [ |
| 194 | + 'class' => 'text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-300 underline decoration-1 underline-offset-2 transition-colors', |
| 195 | + ], |
| 196 | + |
| 197 | + // Tables with Flux-like styling |
| 198 | + Table::class => [ |
| 199 | + 'class' => 'min-w-full divide-y divide-gray-200 dark:divide-gray-700 border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden mb-6', |
| 200 | + ], |
| 201 | + |
| 202 | + TableRow::class => [ |
| 203 | + 'class' => 'hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors', |
| 204 | + ], |
| 205 | + |
| 206 | + TableCell::class => [ |
| 207 | + 'class' => 'px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100', |
| 208 | + ], |
| 209 | + |
| 210 | + // Code blocks with syntax highlighting ready |
| 211 | + FencedCode::class => [ |
| 212 | + 'class' => 'bg-gray-100 dark:bg-gray-800 rounded-lg overflow-x-auto border border-gray-200 dark:border-gray-700', |
| 213 | + ], |
| 214 | + |
| 215 | + Code::class => [ |
| 216 | + 'class' => 'bg-gray-100 dark:bg-gray-800 text-gray-800 dark:text-gray-200 px-2 py-1 rounded text-sm font-mono border border-gray-200 dark:border-gray-700', |
| 217 | + ], |
| 218 | + |
| 219 | + // Lists with proper spacing |
| 220 | + ListBlock::class => [ |
| 221 | + 'class' => static function (ListBlock $node) { |
| 222 | + $classes = 'mb-4 space-y-2'; |
| 223 | + if ($node->getListData()->type === ListBlock::TYPE_ORDERED) { |
| 224 | + return $classes.' list-decimal list-inside'; |
| 225 | + } |
| 226 | + |
| 227 | + return $classes.' list-disc list-inside'; |
| 228 | + }, |
| 229 | + ], |
| 230 | + |
| 231 | + ListItem::class => [ |
| 232 | + 'class' => 'text-gray-700 dark:text-gray-300 leading-relaxed', |
| 233 | + ], |
| 234 | + |
| 235 | + // Blockquotes |
| 236 | + BlockQuote::class => [ |
| 237 | + 'class' => 'border-l-4 border-blue-500 pl-4 py-2 mb-4 bg-blue-50 dark:bg-blue-900/20 text-gray-700 dark:text-gray-300 italic', |
| 238 | + ], |
| 239 | + |
| 240 | + // Horizontal rules |
| 241 | + ThematicBreak::class => [ |
| 242 | + 'class' => 'my-8 border-gray-300 dark:border-gray-600', |
| 243 | + ], |
| 244 | + |
| 245 | + // Images |
| 246 | + Image::class => [ |
| 247 | + 'class' => 'max-w-full h-auto rounded-lg shadow-sm mb-4', |
| 248 | + ], |
| 249 | + |
| 250 | + // Strong and emphasis |
| 251 | + Strong::class => [ |
| 252 | + 'class' => 'font-medium text-gray-900 dark:text-white', |
| 253 | + ], |
| 254 | + |
| 255 | + Emphasis::class => [ |
| 256 | + 'class' => 'italic text-gray-800 dark:text-gray-200', |
| 257 | + ], |
| 258 | + ], |
| 259 | +]; |
0 commit comments