Skip to content

Commit

Permalink
Support : and ! characters in CSS class names
Browse files Browse the repository at this point in the history
Fixes #224
  • Loading branch information
gocom committed Jan 2, 2024
1 parent 430b87a commit 29e5a13
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/Netcarver/Textile/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/issue-224.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Support exclamation marks and colons in class names:
input: |
p(md:mt-3). Paragraph
p(!mt-3). Paragraph
expect: |
<p class="md:mt-3">Paragraph</p>
<p class="!mt-3">Paragraph</p>

0 comments on commit 29e5a13

Please sign in to comment.