問題描述
當我寫主題時,我確定它符合 XHTML 1.1 和 CSS 2.1 。然後我添加了插件,主題不再符合 XHTM1 1.1 。然後我在我的 CSS 中使用了 Google API 字體,並且它符合 CSS 2.1 。
有沒有辦法保持合規性,而不會擺脱插件,字體等,還是應該忽略驗證錯誤?
最佳解決方案
更正,您的主題仍然符合 XHTML 1.1 和 CSS 2.1,但您添加的 plug-ins 注入了不符合的附加代碼。
不幸的是,如果您使用 plug-ins,則沒有簡單的方法來維護合規性。你可以做的最好的是驗證你的主題和你個人負責的所有標記,然後希望其他開發人員花時間驗證自己的工作。
另一種選擇是您的工作更多 – 您仍然可以使用 plug-ins 的核心功能,但不允許他們向瀏覽器輸出任何標記。添加您自己的自定義層,解開 plug-in 觸摸的所有內容,並構建自己的輸出緩衝區。這是您可以控制發送到瀏覽器的標記樣式的唯一方法。
幾個 plug-ins 開始使用 HTML 5 … 其他人試圖使用 CSS3 。如果您安裝這些 plug-ins,並且不採取步驟來清理和驗證其輸出,那麼您的站點將停止正確驗證。
次佳解決方案
每個插件都將生成要生成的代碼,其中一些不符合 XHTML 1.1 標準。糾正的唯一合理的方法是審核每一個,並修改違規者或讓開發人員修改或使用您的修改作為補丁。
替代你可以嘗試寫一個過濾器來清理它,但試圖抓住所有的特殊情況似乎是一個我自己的個人惡夢的版本,它也會影響性能的可怕的好處。
你有一個客户/老闆想要這個,還是隻是假定是一個”nice-to-have?”(是的,有些人對此感到強烈,我不是其中的一個) 。
也就是説,XHTML 在網絡上失去了 「fair-haired 子」 狀態; 甚至 Tim Berners-Lee 在 2006 年回來説:
Some things are clearer with hindsight of several years. It is necessary to evolve HTML incrementally. The attempt to get the world to switch to XML, including quotes around attribute values and slashes in empty tags and namespaces all at once didn’t work. The large HTML-generating public did not move, largely because the browsers didn’t complain. Some large communities did shift and are enjoying the fruits of well-formed systems, but not all. It is important to maintain HTML incrementally, as well as continuing a transition to well-formed world, and developing more power in that world.
您可能還希望閲讀 HTML5 比 XHTML 1.0 更容易編寫。在 StackOverflow 上。這是他們的總結:
Just syntax-wise, when you use HTML5, you end up with cleaner, easier to read markup that always invokes standards mode. When you use XHTML 1.0 (served as text/html), you’re specifying a bunch of crud (in order to validate against a crappy dtd) that the browser will do automatically.
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。