简体   繁体   English

html/xhtml 中的语法糖

[英]Syntactic sugar in html/xhtml

I'm currently writing html/xhtml by hand, and that's fine to me, but I would like to ease things a little bit, especially for writing footnotes.我目前正在手工编写 html/xhtml,这对我来说很好,但我想稍微简化一下,尤其是在编写脚注时。

Today, here is how I write footnotes:今天,我是这样写脚注的:

<p>Here is a footnote<a id="ref1b" href="#ref1">[1]</a>.</p>
<!-- And at the end of the document -->
<div class="footnotes">
  <h2>Notes</h2>
  <p id="ref1">[1] But this one isn't very helpful.
    <!-- Let's add a go-back-to-the-text arrow -->
    <a href="#ref1b">↩</a>
  </p>
</div>

The idea would be to make things automatic, and potentially done on the client side (by the browser), so that I could write something like that:这个想法是让事情自动化,并可能在客户端(通过浏览器)完成,这样我就可以写这样的东西:

<p>Here is a footnote<ref id="1"/>.</p>
<!-- And at the end of the document -->
<div class="footnotes">
  <h2>Notes</h2>
  <ref-def id="1">But this one isn't very helpful.</ref-def>
</div>

So ref and ref-def would simply be evaluated on the fly by the browser.因此refref-def将简单地由浏览器即时评估。

Is this possible only using html/xhtml and css?这可能只使用 html/xhtml 和 css 吗?

the way you're doing this now has the advantage of being accessible and standards compliant - it will work with any browser - even with javascript disabled.您现在执行此操作的方式具有可访问性和符合标准的优势 - 它适用于任何浏览器 - 即使禁用了 javascript。 Also search engines will be able to make sense out of this.搜索引擎也将能够理解这一点。 So there are some benefits in doing it this way.所以这样做有一些好处。

if you decided to go for a shorter alternative, then there's plenty of jQuery plugins that will make your task more comfortable.如果您决定采用更短的替代方案,那么有很多 jQuery 插件可以让您的任务更轻松。 eg look at https://github.com/nicholascloud/footnote.js例如看https://github.com/nicholascloud/footnote.js

If you go for that approach please also note, that your site speed will suffer as users will have to download plenty of javascript to get your footnotes working.如果您采用这种方法,还请注意,您的网站速度将受到影响,因为用户必须下载大量 javascript 才能使您的脚注正常工作。

For completeness purpose.出于完整性的目的。 As of today there is a footnote tag in HTML.截至今天,HTML 中有一个footnote标签。

https://www.w3.org/MarkUp/html3/footnotes.html https://www.w3.org/MarkUp/html3/footnotes.html

How it is presented to clients is left to implementors.它如何呈现给客户由实现者决定。 Yo can use more html or css for a better formatting.你可以使用更多的 html 或 css 以获得更好的格式。

 <DL> <DT>Hamlet: <DD>You should not have believed me, for virtue cannot so <a href="#fn1">inoculate</a> our old stock but we shall <a href="#fn2">relish of it</a>. I loved you not. <DT>Ophelia: <DD> I was the more deceived. <DT>Hamlet: <DD>Get thee to a nunnery. Why wouldst thou be a breeder of sinners? I am myself <a href="#fn2">indifferent honest</a> ... </DL> <fn id=fn1><i>inoculate</i> - graft</fn> <fn id=fn2><i>relish of it</i> - smack of it (our old sinful nature)</fn> <fn id=fn3><i>indifferent honest</i> - moderately virtuous</fn>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM