From bda98d1c33377802b3e58a9cbe865fbdd3523761 Mon Sep 17 00:00:00 2001 From: Peter Droogmans Date: Sun, 7 Dec 2014 16:46:09 +0100 Subject: [PATCH 1/4] Add support for any attribute --- Michelf/Markdown.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index c5245fd..f31361c 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -1678,9 +1678,9 @@ abstract class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { ### Extra Attribute Parser ### # Expression to use to catch attributes (includes the braces) - protected $id_class_attr_catch_re = '\{((?:[ ]*[#.][-_:a-zA-Z0-9]+){1,})[ ]*\}'; + protected $id_class_attr_catch_re = '\{((?:[ ]*[#.:][-_:a-zA-Z0-9=]+){1,})[ ]*\}'; # Expression to use when parsing in a context when no capture is desired - protected $id_class_attr_nocatch_re = '\{(?:[ ]*[#.][-_:a-zA-Z0-9]+){1,}[ ]*\}'; + protected $id_class_attr_nocatch_re = '\{(?:[ ]*[#.:][-_:a-zA-Z0-9=]+){1,}[ ]*\}'; protected function doExtraAttributes($tag_name, $attr) { # @@ -1692,17 +1692,21 @@ abstract class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { if (empty($attr)) return ""; # Split on components - preg_match_all('/[#.][-_:a-zA-Z0-9]+/', $attr, $matches); + preg_match_all('/[#.:][-_:a-zA-Z0-9=]+/', $attr, $matches); $elements = $matches[0]; # handle classes and ids (only first id taken into account) $classes = array(); + $attributes = array(); $id = false; foreach ($elements as $element) { if ($element{0} == '.') { $classes[] = substr($element, 1); } else if ($element{0} == '#') { if ($id === false) $id = substr($element, 1); + } else if ($element{0} == ':') { + $parts = explode('=', substr($element, 1)); + $attributes[] = $parts[0] . '="' . $parts[1] . '"'; } } @@ -1714,6 +1718,9 @@ abstract class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { if (!empty($classes)) { $attr_str .= ' class="'.implode(" ", $classes).'"'; } + if (!empty($attributes)) { + $attr_str .= ' '.implode(" ", $attributes); + } return $attr_str; } From 08b16661f37c2da62f06f68c81d34e20434db6a5 Mon Sep 17 00:00:00 2001 From: Peter Droogmans Date: Sun, 7 Dec 2014 17:16:32 +0100 Subject: [PATCH 2/4] check for no_markup flag --- Michelf/Markdown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index f31361c..0763f80 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -1718,7 +1718,7 @@ abstract class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { if (!empty($classes)) { $attr_str .= ' class="'.implode(" ", $classes).'"'; } - if (!empty($attributes)) { + if (!$this->no_markup && !empty($attributes)) { $attr_str .= ' '.implode(" ", $attributes); } return $attr_str; From 7ff3e598451a75feba9be4850008658b3f804b45 Mon Sep 17 00:00:00 2001 From: Peter Droogmans Date: Sun, 7 Dec 2014 17:55:15 +0100 Subject: [PATCH 3/4] do nut use : as a prefix --- Michelf/Markdown.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 0763f80..4d1dd4d 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -1678,9 +1678,9 @@ abstract class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { ### Extra Attribute Parser ### # Expression to use to catch attributes (includes the braces) - protected $id_class_attr_catch_re = '\{((?:[ ]*[#.:][-_:a-zA-Z0-9=]+){1,})[ ]*\}'; + protected $id_class_attr_catch_re = '\{((?:[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,})[ ]*\}'; # Expression to use when parsing in a context when no capture is desired - protected $id_class_attr_nocatch_re = '\{(?:[ ]*[#.:][-_:a-zA-Z0-9=]+){1,}[ ]*\}'; + protected $id_class_attr_nocatch_re = '\{(?:[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,}[ ]*\}'; protected function doExtraAttributes($tag_name, $attr) { # @@ -1692,7 +1692,7 @@ abstract class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { if (empty($attr)) return ""; # Split on components - preg_match_all('/[#.:][-_:a-zA-Z0-9=]+/', $attr, $matches); + preg_match_all('/[#.a-z][-_:a-zA-Z0-9=]+/', $attr, $matches); $elements = $matches[0]; # handle classes and ids (only first id taken into account) @@ -1704,8 +1704,8 @@ abstract class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { $classes[] = substr($element, 1); } else if ($element{0} == '#') { if ($id === false) $id = substr($element, 1); - } else if ($element{0} == ':') { - $parts = explode('=', substr($element, 1)); + } else if (strpos($element, '=') > 0) { + $parts = explode('=', $element); $attributes[] = $parts[0] . '="' . $parts[1] . '"'; } } From abb587aa86711f0c8f76c0d236129de5ffa640e3 Mon Sep 17 00:00:00 2001 From: Peter Droogmans Date: Sun, 7 Dec 2014 19:29:38 +0100 Subject: [PATCH 4/4] only explode in 2 parts --- Michelf/Markdown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 4d1dd4d..c8ced89 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -1705,7 +1705,7 @@ abstract class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } else if ($element{0} == '#') { if ($id === false) $id = substr($element, 1); } else if (strpos($element, '=') > 0) { - $parts = explode('=', $element); + $parts = explode('=', $element, 2); $attributes[] = $parts[0] . '="' . $parts[1] . '"'; } }