Browse files

only self-close tags that are explicitly marked as having a content m…

…odel of EMPTY.
  • Loading branch information...
1 parent cf4702c commit 87be134e6a2f509ec1833c6aa84c99297e4613b3 Tim Burks committed Mar 9, 2010
Showing with 21 additions and 6 deletions.
  1. +11 −2 nu/xhtml.nu
  2. +7 −1 objc/markup.m
  3. +3 −3 test/test_markup.nu
View
13 nu/xhtml.nu
@@ -30,7 +30,7 @@ END))
h6
img
input
- label
+ label
li
link
meta
@@ -45,9 +45,18 @@ END))
style
table
td
- textarea
+ textarea
th
title
tr
tbody
ul)
+
+(send &meta setEmpty:YES)
+(send &link setEmpty:YES)
+(send &hr setEmpty:YES)
+(send &br setEmpty:YES)
+(send &img setEmpty:YES)
+(send &area setEmpty:YES)
+(send &input setEmpty:YES)
+(send &col setEmpty:YES)
View
8 objc/markup.m
@@ -12,10 +12,12 @@ @interface NuMarkupOperator : NuOperator
{
NSString *tag;
NSString *prefix;
+ BOOL empty;
}
- (id) initWithTag:(NSString *) tag;
- (id) initWithTag:(NSString *) tag prefix:(NSString *) prefix;
+- (void) setEmpty:(BOOL) e;
@end
@implementation NuMarkupOperator
@@ -43,6 +45,10 @@ - (id) initWithTag:(NSString *) _tag prefix:(NSString *) _prefix
return self;
}
+- (void) setEmpty:(BOOL) e {
+ empty = e;
+}
+
- (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
{
NSMutableString *body = [NSMutableString string];
@@ -85,7 +91,7 @@ - (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
cursor = [cursor cdr];
}
- if ([body length]) {
+ if ([body length] || !empty) {
return [NSString stringWithFormat:@"%@<%@%@>%@</%@>", prefix, tag, attributes, body, tag];
}
else {
View
6 test/test_markup.nu
@@ -11,9 +11,9 @@
(set &html (NuMarkupOperator operatorWithTag:"html" prefix:"<!DOCTYPE html>\n"))
(set &body (NuMarkupOperator operatorWithTag:"body"))
- (assert_equal "<body/>" (&body))
- (assert_equal "<body/>" (&body incomplete:))
- (assert_equal "<body attr=\"val\"/>" (&body attr:"val"))
+ (assert_equal "<body></body>" (&body))
+ (assert_equal "<body></body>" (&body incomplete:))
+ (assert_equal "<body attr=\"val\"></body>" (&body attr:"val"))
(assert_equal "<!DOCTYPE html>\n<html><body this=\"is\" a=\"test\">hello, world</body></html>" (&html (&body this:"is" a:"test" "hello," " world")))
(assert_equal "<body>abc123</body>" (&body (array "a" "b" "c") 123))
(assert_equal "<body>12.</body>" (&body "1" (if (eq 1 1) 2) (if (eq 1 2) 3) "."))))

0 comments on commit 87be134

Please sign in to comment.