From 7bc924b6d62a8a2b7d50a39bbdbb0d57f07b93f1 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 21 Jan 2015 21:58:51 -0700 Subject: [PATCH] Added ability to configure markdown options in configuration and in page --- system/config/system.yaml | 9 ++++++++- system/src/Grav/Common/Page/Page.php | 20 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/system/config/system.yaml b/system/config/system.yaml index d3cf126c7..ead9bf100 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -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 diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 458de5777..0c5bc4a89 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -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); }