summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2014-01-09 17:27:24 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2014-01-09 17:27:24 -0500
commit55d485365f4d52a84d06bc38d6d34b6a47890b57 (patch)
tree67ed3697d7f212b698cdc3cfc8c530c54e5fba64 /src
parentbb567cd6c1490dcabf53a3dd18f1aebd8e3055e0 (diff)
Add 'html5' .urp directive
Diffstat (limited to 'src')
-rw-r--r--src/c/urweb.c12
-rw-r--r--src/cjr_print.sml12
-rw-r--r--src/compiler.sml1
-rw-r--r--src/settings.sig3
-rw-r--r--src/settings.sml4
5 files changed, 23 insertions, 9 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 3a5933c5..c0c339c1 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -3241,7 +3241,8 @@ int uw_rollback(uw_context ctx, int will_retry) {
return 0;
}
-static const char begin_xhtml[] = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">";
+const char uw_begin_xhtml[] = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">";
+const char uw_begin_html5[] = "<!DOCTYPE html><html>";
extern int uw_hash_blocksize;
@@ -3331,11 +3332,14 @@ int uw_commit(uw_context ctx) {
uw_check(ctx, 1);
*ctx->page.front = 0;
- if (!ctx->returning_indirectly && !strncmp(ctx->page.start, begin_xhtml, sizeof begin_xhtml - 1)) {
+ if (!ctx->returning_indirectly
+ && (ctx->app->is_html5
+ ? !strncmp(ctx->page.start, uw_begin_html5, sizeof uw_begin_html5 - 1)
+ : !strncmp(ctx->page.start, uw_begin_xhtml, sizeof uw_begin_xhtml - 1))) {
char *s;
// Splice script data into appropriate part of page, also adding <head> if needed.
- s = ctx->page.start + sizeof begin_xhtml - 1;
+ s = ctx->page.start + (ctx->app->is_html5 ? sizeof uw_begin_html5 - 1 : sizeof uw_begin_xhtml - 1);
s = strchr(s, '<');
if (s == NULL) {
// Weird. Document has no tags!
@@ -4170,7 +4174,7 @@ failure_kind uw_begin_onError(uw_context ctx, char *msg) {
uw_write_header(ctx, "Status: ");
uw_write_header(ctx, "500 Internal Server Error\r\n");
uw_write_header(ctx, "Content-type: text/html\r\n");
- uw_write(ctx, begin_xhtml);
+ uw_write(ctx, ctx->app->is_html5 ? uw_begin_html5 : uw_begin_xhtml);
ctx->app->on_error(ctx, msg);
uw_write(ctx, "</html>");
}
diff --git a/src/cjr_print.sml b/src/cjr_print.sml
index 1fc0b40f..05dce35e 100644
--- a/src/cjr_print.sml
+++ b/src/cjr_print.sml
@@ -3083,7 +3083,11 @@ fun p_file env (ds, ps) =
ServerOnly => box []
| _ => box [string "uw_write_header(ctx, \"Content-script-type: text/javascript\\r\\n\");",
newline],
- string "uw_write(ctx, begin_xhtml);",
+ string ("uw_write(ctx, uw_begin_" ^
+ (if Settings.getIsHtml5 () then
+ "html5"
+ else
+ "xhtml") ^ ");"),
newline,
string "uw_mayReturnIndirectly(ctx);",
newline,
@@ -3374,9 +3378,6 @@ fun p_file env (ds, ps) =
newline,
newline,
- string "static const char begin_xhtml[] = \"<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\" ?>\\n<!DOCTYPE html PUBLIC \\\"-//W3C//DTD XHTML 1.0 Transitional//EN\\\" \\\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\\\">\\n<html xmlns=\\\"http://www.w3.org/1999/xhtml\\\" xml:lang=\\\"en\\\" lang=\\\"en\\\">\";",
- newline,
- newline,
p_list_sep newline (fn x => x) pds,
newline,
@@ -3588,7 +3589,8 @@ fun p_file env (ds, ps) =
"uw_handle",
"uw_input_num", "uw_cookie_sig", "uw_check_url", "uw_check_mime", "uw_check_requestHeader", "uw_check_responseHeader", "uw_check_envVar",
case onError of NONE => "NULL" | SOME _ => "uw_onError", "my_periodics",
- "\"" ^ Prim.toCString (Settings.getTimeFormat ()) ^ "\""],
+ "\"" ^ Prim.toCString (Settings.getTimeFormat ()) ^ "\"",
+ if Settings.getIsHtml5 () then "1" else "0"],
string "};",
newline]
end
diff --git a/src/compiler.sml b/src/compiler.sml
index 5e60288b..0ffab01c 100644
--- a/src/compiler.sml
+++ b/src/compiler.sml
@@ -865,6 +865,7 @@ fun parseUrp' accLibs fname =
| "noXsrfProtection" => Settings.addNoXsrfProtection arg
| "timeFormat" => Settings.setTimeFormat arg
| "noMangleSql" => Settings.setMangleSql false
+ | "html5" => Settings.setIsHtml5 true
| _ => ErrorMsg.error ("Unrecognized command '" ^ cmd ^ "'");
read ()
diff --git a/src/settings.sig b/src/settings.sig
index 847cb5f6..a7a41447 100644
--- a/src/settings.sig
+++ b/src/settings.sig
@@ -265,4 +265,7 @@ signature SETTINGS = sig
val mangleSql : string -> string
val mangleSqlCatalog : string -> string
val mangleSqlTable : string -> string
+
+ val setIsHtml5 : bool -> unit
+ val getIsHtml5 : unit -> bool
end
diff --git a/src/settings.sml b/src/settings.sml
index ebe38b17..be998ec2 100644
--- a/src/settings.sml
+++ b/src/settings.sml
@@ -716,4 +716,8 @@ fun mangleSql s = if !mangle then "uw_" ^ s
else "\"" ^ lowercase s ^ "\""
fun mangleSqlCatalog s = if !mangle then "uw_" ^ s else lowercase s
+val html5 = ref false
+fun setIsHtml5 b = html5 := b
+fun getIsHtml5 () = !html5
+
end