1

I am trying to write some documents for the web which have some special characters in them.

There's a few Unicode characters which do not have a "named character reference" but which I would like to include in my web pages. For example, here's a funky arrow:

0000 21FB RIGHTWARDS ARROW WITH DOUBLE VERTICAL STROKE

which looks like this: ⇻

If I want to make a habit of this, I would need to keep a big list handy which shows all these characters and their equivalent hex codes. It would be much easier if I could simply link to a css or javascript file, and then type an "alias" instead (similar to a named character reference). In other words, I'd like to be able to do this:

<p>Here is my arrow:  &my-special-arrow; </p>

Can anyone suggest a way to do this easily?

David H
  • 1,461
  • 2
  • 17
  • 37
  • 4
    You can do that by making your own DTD. – SLaks Aug 19 '15 at 16:27
  • 1
    You can check how [Font Awesome](https://fortawesome.github.io/Font-Awesome/cheatsheet/) works or you can use its icons directly – ChesuCR Aug 19 '15 at 16:40
  • Not trying to discourage you, but what are the intentions behind this? I understand it would make the code more readable, but the cons in the long run seem considerable (it's not standard, complex maintenance, larger code) – Alvaro Montoro Aug 19 '15 at 16:41
  • @AlvaroMontoro, I'd like to start publishing Z specifications in HTML. The existing tools for this are old and not well maintained; a straight css/javascript approach with HTML5 is feasible and relatively easy to implement IF we can get around this "memorizing unicode hex codes" bit. – David H Aug 19 '15 at 16:44
  • Check [this question](http://stackoverflow.com/questions/6508860/how-do-i-define-html-entity-references-inside-a-valid-xml-document) and [this one too](http://stackoverflow.com/questions/7321604/using-custom-entities-in-html-documents). – Alvaro Montoro Aug 19 '15 at 16:50
  • The solutions in the linked questions work, but only in XHTML documents. HTML is out. – Mr Lister Aug 19 '15 at 19:20
  • @DavidH What JavaScript solution are you thinking about? I could imagine traversing the whole document tree and changing all occurrences of the new entities, but I don't think it's nearly as efficient as the old fashioned XHTML way. – Mr Lister Aug 19 '15 at 19:23
  • Why do you need to use a hex code at all? Just type the character into the source directly, and ensure the document's encoding is properly declared. – 一二三 Aug 20 '15 at 02:00
  • @一二三 That would be too easy.... Seriously, what if you don't have control over the http headers that the server sends. – Mr Lister Aug 20 '15 at 06:40
  • @MrLister: HTML has `` tags to specify the page's charset (`` in HTML4, `` in HTML5), which can be used to override what the HTTP `Content-Type` header says. People have been using these tags for years and years. – Remy Lebeau Aug 20 '15 at 06:59
  • @RemyLebeau That's not true. If the HTTP header specifies the charset, you CANNOT override that with a `` element. `` http-equivs are only useful if there is no charset in the HTTP header. – Mr Lister Aug 20 '15 at 07:32
  • 1
    @MrLister If your server is uncontrollably setting the charset to something other than your page's actual encoding, I think you've got bigger problems... – 一二三 Aug 20 '15 at 10:08
  • @一二三, typing the character directly would be fine if I had a keyboard with lots of extra keys! To get that character into the source, I would still need to enter in the hex code. My goal here is to create a set of aliases once, which could be reused by anyone creating these sorts of documents. – David H Aug 20 '15 at 16:40

0 Answers0