所以我想建立一个基于 XHTML 1.0 Strict 的网站。使用 Notepad++ 进行语法突出显示是我的一个想法。但是当我尝试放置 XML 声明时(如规范中所述,正确的 XHTML 页面应使用 XML 声明并以 application/xhtml+xml 的形式提供),我无法正确突出显示整个文档。这是我用于基本页面的代码:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<title>Page</title>
<script type="application/javascript">
alert("A perfectly valid xHTML page...");
</script>
<style type="text/css">
#test {
text-align: center;
}
</style>
</head>
<body>
<h1 id="test">TEST</h1>
</body>
</html>
将其粘贴到 Notepad++ 中,您会发现,如果语言设置为 XML,它不会突出显示<script type="application/javascript">
和之间的代码</script>
(它会将其背景呈现为白色)。如果我将语言设置为 HTML,则脚本会正确突出显示,但 XML 声明不会。该怎么办?如何制作混合语言 - XML 和 HTML 的组合?
答案1
Notepad++ 使用文件的扩展名来决定要使用的 Lexer(即高亮器)。如果您将文件保存为 .xhtml,那么它应该会开始正确高亮。实际上,您可以将文件保存为 .html,因为它们都使用相同的 Lexer。
如果你查看 Notepad++ 文件,langs.model.xml
你就会明白我的意思:
<Language name="html" ext="html htm shtml shtm xhtml hta" commentLine="" commentStart="<!--" commentEnd="-->">
<Keywords name="instre1">!doctype a abbr accept accept-charset accesskey acronym action address align alink alt applet archive area article aside audio axis b background base basefont bdo bgcolor big blockquote body border br button canvas caption cellpadding cellspacing center char charoff charset checkbox checked cite class classid clear code codebase codetype col colgroup color cols colspan command compact content contenteditable contextmenu coords data datafld dataformatas datalist datapagesize datasrc datetime dd declare defer del details dfn dir disabled div dl draggable dropzone dt em embed enctype event face fieldset figcaption figure file font footer for form frame frameborder frameset h1 h2 h3 h4 h5 h6 head header height hgroup hidden hr href hreflang hspace html http-equiv i id iframe image img input ins isindex ismap kbd keygen label lang language leftmargin legend li link longdesc map marginheight marginwidth mark marquee maxlength media menu meta meter method multiple name nav noframes nohref noresize noscript noshade nowrap object ol onabort onafterprint onbeforeonload onbeforeprint onblur oncanplay oncanplaythrough onchange onclick oncontextmenu ondblclick ondrag ondragend ondragenter ondragleave ondragover ondragstart ondrop ondurationchange ondurationchange onemptied onended onerror onfocus onformchange onforminput onhaschange oninput oninvalid onkeydown onkeypress onkeyup onload onloadeddata onloadedmetadata onloadstart onmessage onmousedown onmousemove onmouseout onmouseover onmouseup onmousewheel onoffline ononline onpagehide onpageshow onpause onplay onplaying onpopstate onprogress onratechange onreadystatechange onredo onreset onresize onscroll onseeked onseeking onselect onselect onstalled onstorage onsubmit onsubmit onsuspend ontimeupdate onundo onunload onunload onvolumechange onwaiting optgroup option output p param password placeholder pre profile progress prompt public q radio readonly rel reset rev rows rowspan rp rt ruby rules s samp scheme scope script section select selected shape size small source span spellcheck src standby start strike strong style sub submit summary sup tabindex table target tbody td text textarea tfoot th thead time title topmargin tr tt type u ul usemap valign value valuetype var version video vlink vspace wbr width xml xmlns</Keywords>
</Language>