Permalink
Browse files

Removed quoted attributes by making them completely uneccessary.

  • Loading branch information...
1 parent f0accb9 commit 2f9c545d6005b5bab518853961f32553e9b6fa0c @psychoticmeow psychoticmeow committed Sep 14, 2011
Showing with 33 additions and 20 deletions.
  1. +32 −19 libs/doccy-parser.php
  2. +1 −1 test.php
View
@@ -102,10 +102,10 @@ function openTag(\Doccy\Utilities\Data $data, \DOMElement $parent) {
$ended = false;
while ($data) {
- $token = $data->findToken('%^[a-z][a-z0-9]*|\s*"(.*?)"|(^|\s+)[@#.\%][a-z][a-z0-9\-]*|:\s*|[^:@"]+%');
+ $token = $data->findToken('%^[a-z][a-z0-9]*|:\s+|(^|\s+)[@#.\%][a-z][a-z0-9\-]*|.+?%');
// Ends here:
- if ($token->value->test('%^:\s*%')) {
+ if ($token->value->test('%^:\s+%')) {
list($before, $after) = $data->splitAt($token);
$data = $after;
@@ -117,17 +117,30 @@ function openTag(\Doccy\Utilities\Data $data, \DOMElement $parent) {
else if ($token->value->test('%^\s*@%')) {
list($before, $after) = $data->splitAt($token);
- $attribute = trim($token->value, '@ ');
+ $attribute = trim($token->value, "@\r\n\t ");
+ $attributes[$attribute] = null;
+ $data = $after;
+ continue;
+ }
+
+ // Data attribute:
+ else if ($token->value->test('%^\s*[\%]%')) {
+ list($before, $after) = $data->splitAt($token);
+
+ $attribute = 'data-' . trim($token->value, "%\r\n\t ");
$attributes[$attribute] = null;
$data = $after;
continue;
}
// Class attribute:
- else if ($token->value->test('%^\s*[.]%')) {
+ else if (
+ ($token->value->test('%^\s*[.]%') && is_null($attribute))
+ || $token->value->test('%^\s+[.]%')
+ ) {
list($before, $after) = $data->splitAt($token);
- $value = trim($token->value, '. ');
+ $value = trim($token->value, ".\r\n\t ");
$attributes['class'] = (
isset($attributes['class'])
@@ -139,21 +152,14 @@ function openTag(\Doccy\Utilities\Data $data, \DOMElement $parent) {
continue;
}
- // Data attribute:
- else if ($token->value->test('%^\s*[\%]%')) {
- list($before, $after) = $data->splitAt($token);
-
- $attribute = 'data-' . trim($token->value, '% ');
- $attributes[$attribute] = null;
- $data = $after;
- continue;
- }
-
// ID attribute:
- else if ($token->value->test('%^\s*#%')) {
+ else if (
+ ($token->value->test('%^\s*#%') && is_null($attribute))
+ || $token->value->test('%^\s+#%')
+ ) {
list($before, $after) = $data->splitAt($token);
- $value = trim($token->value, '# ');
+ $value = trim($token->value, "#\r\n\t ");
$attributes['id'] = $value;
$data = $after;
continue;
@@ -163,15 +169,21 @@ function openTag(\Doccy\Utilities\Data $data, \DOMElement $parent) {
else if (!is_null($attribute)) {
list($before, $after) = $data->splitAt($token);
- $value = trim($token->value);
+ // Trim any spaces off the start:
+ if (strlen($attributes[$attribute]) == 0) {
+ $value = ltrim($token->value);
+ }
+
+ else {
+ $value = $token->value;
+ }
// Quoted value:
if (substr($value, 0, 1) == '"' && substr($value, -1, 1) == '"') {
$value = substr($value, 1, -1);
}
$attributes[$attribute] .= $value;
- $attribute = null;
$data = $after;
continue;
}
@@ -197,6 +209,7 @@ function openTag(\Doccy\Utilities\Data $data, \DOMElement $parent) {
$parent->appendChild($element);
foreach ($attributes as $name => $value) {
+
$element->setAttribute($name, $value);
}
View
@@ -4,7 +4,7 @@
$tpl = new Doccy\Template();
$tpl->formatOutput = true;
- $tpl->parseString("First things first, you'll need a fresh copy of Symphony, so head to {a @href \"http://symphony-cms.com/downloads\": the Symphony webite} then download and extract the latest release.");
+ $tpl->parseString("First things first, you'll need a fresh copy of Symphony, so head to {a @href http://symphony-cms.com/downloads: the Symphony webite} then download and extract the latest release.");
echo '<pre style="white-space: pre-wrap;">';

0 comments on commit 2f9c545

Please sign in to comment.