From 29e5a138df949fb199a8c86ea2775134f0366c00 Mon Sep 17 00:00:00 2001 From: Jukka Svahn Date: Tue, 2 Jan 2024 18:25:38 +0200 Subject: [PATCH] Support : and ! characters in CSS class names Fixes #224 --- CHANGELOG.textile | 2 ++ LICENSE | 2 +- src/Netcarver/Textile/Parser.php | 4 ++-- test/fixtures/issue-224.yaml | 10 ++++++++++ 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/issue-224.yaml diff --git a/CHANGELOG.textile b/CHANGELOG.textile index b5b7ba96..f7c2ba75 100644 --- a/CHANGELOG.textile +++ b/CHANGELOG.textile @@ -4,6 +4,8 @@ Here's a summary of changes in each release. The list doesn't include some small h2. Version 4.1.0 - upcoming +* Support @:@ and @!@ characters in CSS class names (closes "#224":https://github.com/textile/php-textile/issues/224). + h2. "Version 4.0.0 - 2022/12/03":https://github.com/textile/php-textile/releases/tag/v4.0.0 * HTML void tags render a self-closing slash based on the given document type. If @Parser::setDocumentType()@ is given @Parser::DOCTYPE_XHTML@, self-closing tags are used, otherwise not. diff --git a/LICENSE b/LICENSE index 14171cc6..3a1acaae 100644 --- a/LICENSE +++ b/LICENSE @@ -11,7 +11,7 @@ Additions and fixes Copyright (c) 2010 Stef Dawson https://stefdawson.c Additions and fixes Copyright (c) 2010-17 Netcarver https://github.com/netcarver Additions and fixes Copyright (c) 2011 Jeff Soo http://ipsedixit.net/ Additions and fixes Copyright (c) 2012 Robert Wetzlmayr https://wetzlmayr.com/ -Additions and fixes Copyright (c) 2012-19 Jukka Svahn https://rahforum.biz/ +Additions and fixes Copyright (c) 2012-24 Jukka Svahn https://rahforum.biz/ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/src/Netcarver/Textile/Parser.php b/src/Netcarver/Textile/Parser.php index 43b07cf9..c1ee0353 100644 --- a/src/Netcarver/Textile/Parser.php +++ b/src/Netcarver/Textile/Parser.php @@ -2527,14 +2527,14 @@ protected function parseAttribsToArray($in, $element = '', $include_id = true, $ } if (preg_match("/\(([^()]+)\)/U", $matched, $cls)) { - $class_regex = "/^([-a-zA-Z 0-9_\.\/\[\]]*)$/"; + $class_regex = "/^([-a-zA-Z 0-9_\.\/\[\]:!]*)$/"; // Consume entire class block -- valid or invalid. $matched = str_replace($cls[0], '', $matched); // Only allow a restricted subset of the CSS standard characters for classes/ids. // No encoding markers allowed. - if (preg_match("/\(([-a-zA-Z 0-9_\/\[\]\.\:\#]+)\)/U", $cls[0], $cls)) { + if (preg_match("/\(([-a-zA-Z 0-9_\/\[\].:!#]+)\)/U", $cls[0], $cls)) { $hashpos = strpos($cls[1], '#'); // If a textile class block attribute was found with a '#' in it // split it into the css class and css id... diff --git a/test/fixtures/issue-224.yaml b/test/fixtures/issue-224.yaml new file mode 100644 index 00000000..7b00dec4 --- /dev/null +++ b/test/fixtures/issue-224.yaml @@ -0,0 +1,10 @@ +Support exclamation marks and colons in class names: + input: | + p(md:mt-3). Paragraph + + p(!mt-3). Paragraph + + expect: | +

Paragraph

+ +

Paragraph