Skip to content

Commit

Permalink
Fix single underscores in email templates
Browse files Browse the repository at this point in the history
provides a better fix for #1800
  • Loading branch information
brandonkelly committed Feb 26, 2018
1 parent 80894d3 commit c876276
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@

### Fixed
- Fixed a bug where entry version data was not including newly-created Matrix block IDs, so they would be re-created from scratch when loading the version. ([#2498](https://github.com/craftcms/cms/issues/2498))
- Fixed an error that could occur if an email template included any Twig filters with a single underscore.

## 2.6.3010 - 2018-02-21

Expand Down
14 changes: 10 additions & 4 deletions src/services/EmailService.php
Expand Up @@ -438,11 +438,17 @@ private function _sendEmail(UserModel $user, EmailModel $emailModel, $variables
}
else
{
// TODO: This won't be necessary in 3.0 thanks to Parsedown
$emailModel->body = preg_replace('/(?<=[a-zA-Z])_(?=[a-zA-Z])/', '\_', $emailModel->body);

// They didn't provide an htmlBody, so markdown the body.
$renderedHtmlBody = craft()->templates->renderString(StringHelper::parseMarkdown($emailModel->body), $variables);

// Don't parse _text_ as italics because https://github.com/craftcms/cms/issues/1800
if (!class_exists('\Markdown_Parser', false))
{
require_once craft()->path->getFrameworkPath().'vendors/markdown/markdown.php';
}
$md = new \Markdown_Parser();
unset($md->em_relist['_']);

$renderedHtmlBody = craft()->templates->renderString($md->transform($emailModel->body), $variables);
$email->msgHTML($renderedHtmlBody);
}

Expand Down

0 comments on commit c876276

Please sign in to comment.