Skip to content

Commit

Permalink
✨ Smartypants support
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmcdade committed Jun 25, 2019
1 parent 40a74a3 commit 4812657
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 30 deletions.
33 changes: 31 additions & 2 deletions app/Fieldtypes/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,40 @@ class Markdown extends Fieldtype
protected $configFields = [
'container' => ['type' => 'asset_container', 'max_items' => 1],
'folder' => ['type' => 'asset_folder', 'max_items' => 1],
'restrict' => ['type' => 'toggle']
'restrict' => ['type' => 'toggle'],
'smartypants' => [
'type' => 'toggle',
'default' => false
],
'automatic_line_breaks' => [
'type' => 'toggle',
'default' => true
],
'escape_markup' => [
'type' => 'toggle',
'default' => true
],
'automatic_links' => [
'type' => 'toggle',
'default' => false
],

];

public function augment($value)
{
return markdown($value);
$markdown = new \ParsedownExtra();

$html = $markdown
->setBreaksEnabled($this->config('automatic_line_breaks'))
->setMarkupEscaped($this->config('escape_markup'))
->setUrlsLinked($this->config('automatic_links'))
->text($value);

if ($this->config('smartypants')) {
$html = smartypants($html);
}

return $html;
}
}
12 changes: 12 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Statamic\API\Path;
use Statamic\API\Site;
use Statamic\API\Config;
use Michelf\SmartyPants;
use Statamic\Extend\Addon;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
Expand Down Expand Up @@ -178,6 +179,17 @@ function markdown($content)
return $markdown->text($content);
}

/**
* Run through Smartypants
*
* @param $content
* @return mixed
*/
function smartypants($content)
{
return SmartyPants::defaultTransform($content);
}

/**
* @return \Statamic\DataStore
*/
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"laravelcollective/html": "5.6.*|5.7.*|5.8.*",
"league/csv": "^9.0",
"league/glide": "^1.1",
"michelf/php-smartypants": "^1.8",
"netcarver/textile": "3.6.*@dev",
"scrumpy/html-to-prosemirror": "^0.4.0",
"scrumpy/prosemirror-to-html": "^0.4.0",
Expand Down
54 changes: 52 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 0 additions & 26 deletions config/theming.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,6 @@

return [

/*
|--------------------------------------------------------------------------
| Smartypants
|--------------------------------------------------------------------------
|
| With this enabled, the "content" field will automatically be run through
| the smartypants modifier which translates typographical elements into
| their "smart" versions, eg. straight quotes (") into curly ones (”)
|
*/

'smartypants' => false,

/*
|--------------------------------------------------------------------------
| Markdown Hard Wrapping
|--------------------------------------------------------------------------
|
| Normally, line breaks are created in Markdown by ending lines
| with two spaces. You can enable this option to get a more
| traditional experience seen on websites like Github.
|
*/

'markdown_hard_wrap' => false,

/*
|--------------------------------------------------------------------------
| Default view names
Expand Down

0 comments on commit 4812657

Please sign in to comment.