Added ability to configure markdown options in configuration and in page

This commit is contained in:
Andy Miller
2015-01-21 21:58:51 -07:00
parent c881624801
commit 7bc924b6d6
2 changed files with 26 additions and 3 deletions

View File

@@ -5,7 +5,6 @@ home:
pages:
theme: antimatter # Default theme (defaults to "antimatter" theme)
markdown_extra: false # Enable support for Markdown Extra support (GFM by default)
order:
by: defaults # Order pages by "default", "alpha" or "date"
dir: asc # Default ordering direction, "asc" or "desc"
@@ -21,6 +20,14 @@ pages:
events:
page: true # Enable page level events
twig: true # Enable twig level events
markdown:
extra: false # Enable support for Markdown Extra support (GFM by default)
auto_line_breaks: true # Enable automatic line breaks
auto_url_links: false # Enable automatic HTML links
escape_markup: false # Escape markup tags into entities
special_chars: # List of special characters to automatically convert to entities
'>': 'gt'
'<': 'lt'
cache:
enabled: true # Set to true to enable caching

View File

@@ -412,12 +412,28 @@ class Page
/** @var Config $config */
$config = self::$grav['config'];
// get the appropriate setting for markdown extra
if (isset($this->markdown_extra) ? $this->markdown_extra : $config->get('system.pages.markdown_extra')) {
$defaults = (array) $config->get('system.pages.markdown');
if (isset($this->header()->markdown)) {
$defaults = array_merge($defaults, $this->header()->markdown);
}
// pages.markdown_extra is deprecated, but still check it...
if (isset($this->markdown_extra) || $config->get('system.pages.markdown_extra') !== null) {
$defaults['extra'] = $this->markdown_extra;
}
// Initialize the preferred variant of Parsedown
if ($defaults['extra']) {
$parsedown = new ParsedownExtra($this);
} else {
$parsedown = new Parsedown($this);
}
$parsedown->setBreaksEnabled($defaults['auto_line_breaks']);
$parsedown->setSpecialChars($defaults['special_chars']);
$parsedown->setUrlsLinked($defaults['auto_url_links']);
$parsedown->setMarkupEscaped($defaults['escape_markup']);
$this->content = $parsedown->text($this->content);
}