Skip to content

Commit

Permalink
only self-close tags that are explicitly marked as having a content m…
Browse files Browse the repository at this point in the history
…odel of EMPTY.
  • Loading branch information
Tim Burks committed Mar 10, 2010
1 parent cf4702c commit 87be134
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
13 changes: 11 additions & 2 deletions nu/xhtml.nu
Expand Up @@ -30,7 +30,7 @@ END))
h6
img
input
label
label
li
link
meta
Expand All @@ -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)
8 changes: 7 additions & 1 deletion objc/markup.m
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions test/test_markup.nu
Expand Up @@ -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.