Code Sample |
function html_begin(title) print('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n'.. '"http://www.w3.org/TR/html4/strict.dtd">\n'.. '<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">\n'.. '<title>'..title..'</title>\n'.. '<link href="/style.css" rel="stylesheet" type="text/css"></head><body>') end |
Code Sample |
function html_begin(doctype,title,style) |
Code Sample |
-- create the document type declaration (dtd) function add_doctype(major,minor) -- major: 2.0 3.2 4.0 4.01 x1.0 x1.1 minor: strict transitional frameset local def_doctype = "HTML 4.01" local def_dtd = "\"http://www.w3.org/TR/html4/strict.dtd\"" local doctype,dtd if major == "4.01" then if minor == "transitional" then doctype,dtd = "HTML 4.01 Transitional","\"http://www.w3.org/TR/html4/loose.dtd\"" elseif minor == "frameset" then doctype,dtd = "HTML 4.01 Frameset","\"http://www.w3.org/TR/html4/frameset.dtd\"" else doctype,dtd = "HTML 4.01","\"http://www.w3.org/TR/html4/strict.dtd\"" end elseif major == "x1.0" then if minor == "transitional" then doctype,dtd = "XHTML 1.0 Transitional","\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"" elseif minor == "frameset" then doctype,dtd = "XHTML 1.0 Frameset","\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\"" else doctype,dtd = "XHTML 1.0 Strict","\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"" end elseif major == "x1.1" then doctype,dtd = "XHTML 1.1","" elseif major == "2.0" then doctype,dtd = "HTML 2.0","" elseif major == "3.2" then doctype,dtd = "HTML 3.2 Final","" else doctype,dtd = def_doctype,def_dtd end print('<!DOCTYPE HTML PUBLIC "-//W3C//DTD '..doctype..'//EN"\n'..dtd) end -- EXAMPLES -- add_doctype("4.01","transitional") -> HTML 4.01 Transitional -- add_doctype() -> HTML 4.01 Strict (the default) -- add_doctype("x1.0") -> XHTML 1.0 Strict -- add doctype(nil,"transitional") -> if major is nil, it uses the default HTML 4.01 Strict -- create the "head" part and open the body function html_begin(title,style,charset) if not title then title = "untitled" end if not charset then charset = "ISO-8859-1" end print('<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset='..charset..'" />\n<title>'..title..'</title>') if style then print('<link href="'..style..'" rel="stylesheet" type="text/css" />') end print('</head>\n\n<body>\n') end -- EXAMPLES -- html_begin("my page","/css/mystyle.css") -> uses iso-8859-1 charset and custom stylesheet -- html_begin("my page") -> uses iso-8859-1 charset and no stylesheet -- html_begin("my page",nil,"utf-8") -> uses utf-8 charset and no stylesheet -- html_begin() -> uses iso-8859-1 charset, no stylesheet, and page title "untitled" -- a simplified version that combines both of the above functions, -- with a static doctype declaration (XHTML 1.0 Strict) function my_html_begin(title,style,charset) if not title then title = "untitled" end if not charset then charset = "ISO-8859-1" end print('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n'.. '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'.. '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n'.. '<head>\n<meta http-equiv="Content-Type" content="text/html; charset='..charset..'" />') if style then print('<link href="'..style..'" rel="stylesheet" type="text/css" />') end print('<title>'..title..'</title>\n</head>\n\n<body>\n') end |