HTML Code for an Apostrophe

HTML code for an apostrophe

If you are looking for straight apostrophe ' (U+00027), it is

' or ' (latest is HTLM 5 only)

If you are looking for the curly apostrophe (U+02019), then yes, it is

or

As of to know which one to use, there are great answers in the Graphic Design community: What’s the right character for an apostrophe?.

Escaping apostrophe (single quote) character in javascript and html

You need to have both ' and " in your string, so you will need a third way to delcare a string, you can use template strings for that. Declare your ba'r string as a template string and escape its apostrophe using a backslash \:

document.querySelector('#myDiv').innerHTML =    '<a href="javascript:foo(`ba\'r`)">link</a>';
function foo(data) { console.log(data);}
<div id="myDiv"></div>

HTML::Entities and encoding an apostrophe

The character entity ' was introduced only in HTML5 and is invalid in HTML4 and earlier. Some browsers will not represent it correctly

The
Wikipedia page
that simbabque links to
in his comment
says this

The use of ' or custom entity references may not be supported and may produce unpredictable results.

HTML::Entities takes the safe route of encoding it as ' which is valid in any iteration of the standard

The module uses a hard-coded hash %entity2char, and uses it to build the inverse mapping for encoding in %char2entity. The entry for the apostrophe is then explicitly deleted to force a numeric entity to be used

delete $char2entity{"'"};  # only one-way decoding

(The comment is in the original code)

If you are willing to commit to using HTML5 throughout then
I suggest that you use HTML::HTML5::Entities which is a
"drop-in replacement for HTML::Entities"
but provides for all the standard HTML5 entities, including '

How to code Apostrophe Letter in HTML?

Would a html entity code solve your problem? You can view them below
http://unicode.e-workers.de/entities.php

For your case ' for '?

Update: Oh or do you mean the html tag TED<sup>x</sup> for sth like
TEDx

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sub

Handling apostrophes when generating HTML with PHP

use htmlspecialchars():

<input type="radio" ... value="<?php echo htmlspecialchars($array[0], ENT_QUOTES) ?>" ... />

It's explicitly intended to allow safe insertion of arbitrary text into html without 'breaking' the html. Note the 'ent_quotes' option. By default htmlspecialchars will only handle <>", but since you're using ', you need the option to tell htmlspecialchars to handle those too.

Escaping apostrophes in HTML with Spring

As noted in your question, the apostrophe is successfully converted into an HTML entity reference by the HtmlUtils class to become '. The behavior you described is occurring because the HTML parsers resolve entity references in attribute values before content is handed off to the JavaScript engine. The entity in the onclick(...) statement is therefore decoded into the original character ' as shown below.

onClick="clicked('Any'String');" => onClick="clicked('Any'String');".

Therefore to the JS engine, the two onClick(...) statements are equivalent.

See this related discussion discussion for more information on the issue.

How to display an apostrophe in HTML for viewmodel string property

According to this answer ActionLink encodes what is passed in. Therefore, it's being double encoded.

Check the value of @ClientName().ToString(), that may already be encoded because helpers encode their output by default; you may need to un-encode it, or not encode it from your helper.

One solution is to make your helper not escape its content

@{ WriteLiteral(((ClientModel)Session["CurrentClient"]).Name); }

or

@Html.Raw(((ClientModel)Session["CurrentClient"]).Name))

If you must un-encode the results of @ClientName().ToString(), use

@Html.ActionLink(
"Client[" +
HttpUtility.HtmlDecode(@ClientName().ToString()) +
"]",
"Index", "Home")

HTML Best Practices: Should I use ’ or the special keyboard shortcut?

I don't think that one is better than the other in general; it depends on how you intend to use it.

  • If you want to store it in a DB column that has a charset/collation that does not support the right single quote character, you may run into storing it as the multi-byte character instead of 7-bit ASCII ().
  • If you are displaying it on an html element that specifies a charset that does not support it, it may not display in either case.
  • If many developers are going to be editing/viewing this file with editors/keyboards that do not support properly typing or displaying the character, you may want to use the entity
  • If you need to convert the file between various character encodings or formats, you may want to use the entity
  • If your HTML code may escape entities improperly, you may want to use the character.

In general I would lean more towards using the character because as you point out it is easier to read and type.



Related Topics



Leave a reply



Submit