Skip to main content
Version: 1.3.x

Smartypants

Description

Smartypants in ParsedownExtended automatically transforms basic ASCII punctuation marks into their typographically correct HTML entities. This feature enhances the readability and aesthetic appeal of your text by converting straight quotes to curly quotes, dashes to en-dashes and em-dashes, and ellipses to their HTML equivalents. It's particularly useful for ensuring that your Markdown content maintains high typographical standards without manual adjustments.

ASCII to HTML Entity Conversion

ASCII symbolReplacementsHTML EntitiesSubstitution Keys
''‘ ’‘ ’"left_single_quote", "right_single_quote"
""“ ”“ ”"left_double_quote", "right_double_quote"
<< >>« »&laquo; &raquo;"left_angle_quote", "right_angle_quote"
...&hellip;"ellipsis"
--&ndash;"ndash"
---&mdash;"mdash"

Configuration Syntax

Configure Smartypants using the config()->set() method:

$ParsedownExtended->config()->set('smartypants', (bool|array) $value);

Parameters

Customize Smartypants with these options:

  • smart_dashes (boolean): Convert dashes to en-dashes and em-dashes.
  • smart_quotes (boolean): Convert straight quotes to curly quotes.
  • smart_angled_quotes (boolean): Convert angled quotes.
  • smart_ellipses (boolean): Convert triple periods to ellipses.
  • substitutions (array): Overwrite default substitutions with custom mappings.

Examples

Custom Substitutions

To customize the substitutions for a specific language or style:

$ParsedownExtended->config()->set('smartypants', [
'substitutions' => [
'left_single_quote' => '&sbquo;', // Single bottom quote
'right_single_quote' => '&lsquo;', // Single top quote
'left_double_quote' => '&bdquo;', // Double bottom quote
'right_double_quote' => '&ldquo;' // Double top quote
]
]);

Enable Smartypants

To enable Smartypants and automatically apply typographical enhancements:

$ParsedownExtended->config()->set('smartypants', true);

This documentation ensures clarity and provides the full context for configuring Smartypants within ParsedownExtended, making it easy for users to apply these settings correctly in their projects.