![]() The en dash is slightly narrow than the em dash, and the hypen is slightly narrower again.Īll three have different purposes, so be sure to use the correct character for your intended purpose. This is because the only difference (visually) between those three characters is their width. Note that an en dash should not be used for negative numbers, and that there should be no spaces. For example, David Foster Wallace (19622008) MayOctober. To the untrained eye, an em dash could easily be mistaken for an en dash or even a hypen. It is generally used in place of 'to' for connecting numbers in ranges, although it can also connect words (in which case, it means 'through'). Source CodeĪfter visiting the library-to read up on how mind affects matter-I proceeded to the gym and set a new world record for bench press.Īfter visiting the library-to read up on how mind affects matter-I proceeded to the gym and set a new world record for bench press. Here's an example of using an em dash within a sentence. ![]() ![]() This example uses the entity names to display the em dash. Here's how you use the HTML entity number to display an em dash. Type either the entity number or entity name where you'd like the em dash to appear. To create an em dash in HTML, use the appropriate HTML entity. The em dash is a punctuation mark that can be used in place of a comma, parentheses, or a colon - usually for the purposes of improved readibility. If ( ! page contains HTML code for adding an em dash within the text of your website or blog. If the target input does not contain the "emdashify" class, then we don't We only care about the dash - ignore any other key events at this time. follow an existing DASH, then we will replace the double-DASH with an EMDASH. If the event is for a DASH that is about to inputs that contain the "emdashify" class token.ĭocument.addEventListener( "keydown", handleKeydown, false ) document level using event-delegation. In this case, we're going to listen at the Will be converted to em dashes as you type. In some of the following textareas, double-dashes Replacing Double-Dashes With Em Dashes While Typing In JavaScript And, to demonstrate said targeting, I've included both activated and non-activated inputs in my demo: There's no right or wrong approach here - this was just an arbitrary decision.Īs a fun caveat to this experiment, I've decided to use event-delegation on the document, targeting any and all inputs that have the ".emdashify" class. Other implementations may wait for a space to be entered before executing the replacement. Now, in my implementation, I've decided to perform the auto-injection at the moment the user requests the second dash (essentially canceling and replacing their keydown event). In my implementation, I'm simply going to replace two dashes with an em dash. But, for this code kata, I'm not going to get that formal - I'll leave that as an exercise in measure for the user. And, in fact, on some platforms, like Medium, the JavaScript controlling the page won't even let you add a space before or after an Em Dash. Officially, when an Em Dash (or an En Dash) is used, it's supposed to butt-up against the words on either side of it. View this code in my JavaScript Demos project on GitHub. Run this demo in my JavaScript Demos project on GitHub.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |