michelf/php-smartypants
PHP port of John Gruber’s SmartyPants: converts plain ASCII punctuation into typographically correct “smart” quotes, dashes, and ellipses. Useful for cleaning up HTML output from Markdown or other text sources, with configurable transformation options.
composer require michelf/php-smartypants.echo \Michelf\SmartyPants::defaultTransform('He said -- "Hello world."'); → outputs proper en-dash and curly quotes.\Michelf\SmartyPants class; default static method defaultTransform() covers most common typographic conversions (quotes, dashes, ellipses).league/commonmark), as SmartyPants enhances rendered HTML—not raw Markdown.Blade::directive('typo', fn ($expression) => "<?php echo \\Michelf\\SmartyPants::defaultTransform({$expression}); ?>");
Usage: @typo('She said -- "Let\'s go!"').SmartyPants::defaultTransform() in a global response middleware for site-wide typographic polish.SmartyPants::process($text, $attr) to enable options like 2 (smart quotes only), 3 (no quotes), or custom settings like ['smart_quotes' => false].<a href="x">--y</a> → <a href="x">—y</a>), so strip tags first if needed: SmartyPants::defaultTransform(strip_tags($text)).# Title -- My Note will mangle -- inside headings).\Michelf\SmartyPants to override applyRules() for custom rules (e.g., adding Spanish guillemets).-- become en-dashes always, --- em-dashes—no context-awareness. For technical docs, disable dashes via options if fidelity to code snippets is needed.How can I help you explore Laravel packages today?