Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put two spaces after every period in our HTML?

Tags:

html

spaces

I need there to be two spaces after every period in every sentence in our entire site (don't ask).

One way to do it is to embark on manually adding a &nbsp  after every single period. This will take several hours.

We can't just find and replace every period, because we have concatenations in PHP and other cases where there is a period and then a space, but it's not in a sentence.

Is there a way to do this...and everything still work in Internet Explorer 6?

[edit] - The tricky part is that in the code, there are lines of PHP that include dots with spaces around them like this:

<?php echo site_url('/css/' . $some_name .'.css');?>

I definitely don't want extra spaces to break lines like that, so I would be happy adding two visible spaces after each period in all P tags.

like image 866
SpaceNinja Avatar asked Oct 07 '11 16:10

SpaceNinja


People also ask

How do you put two spaces in HTML?

Since there is no blank space keyboard character in HTML, you must type the entity &nbsp; for each space to add. To insert blank spaces in text in HTML, type &nbsp; for each space to add. For example, to create five blank spaces between two words, type the &nbsp; entity five times between the words.

How do you double space after a period?

Choose Preferences. Select Spelling & Grammar from the box. Click the Settings button next to Grammar & Refinements. Next to Space Between Sentences, choose between don't check, single space, and double space.

How do you put spaces after text in HTML?

The simplest way to add a space in HTML (besides hitting the spacebar) is with the non-breaking space entity, written as &nbsp; or &#160;.

What style uses two spaces after a period?

The Publication Manual of the American Psychological Association (APA) was the only style guide that overtly recommended two spaces after a period, and even that long-time holdout for two spaces changed its guideline to one space in its 2019 update. The MLA Handbook for Writers of Research Papers (MLA) waffles.


2 Answers

As we all know, HTML collapses white space, but it only does this for display. The extra spaces are still there. So if the source material was created with two spaces after each period, then some of these substitution methods that are being suggested can be made to work reliably - search for "period-space-space" and replace it with something more suituble, like period-space-&emsp14;. Please note that you shouldn't use &nbsp; because it can prevent proper wrapping at margins. (If you're using ragged right, the margin change won't be noticeable as long as you use the the nbsp BEFORE the space.)

You can also wrap each sentence in a span and use the :after selector to add a space and format it to be wide with "word-spacing". Or you can wrap the space between sentences itself in a span and style that directly.

I've written a javascript solution for blogger that does this on the fly, looks for period-space-space, and replaces it with a spanned, styled space that appears wider.

If however your original material doesn't include this sort of thing then you'll have to study up on sentence boundary detection algorithms (which are not so simple), and then modify one to also not trip over PHP code.

like image 75
thomasafine Avatar answered Oct 27 '22 10:10

thomasafine


You might be able to use the JavaScript split method or regex depending on the scope of the text.

Here's the split method:

var el = document.getElementById("mydiv");
if (el){
    el.innerText = el.innerText.split(".").join(".\xA0 ");   
}

Test case:

Hello world.Insert spaces after the period.Using the split method.

Result:

Hello world. Insert spaces after the period. Using the split method.

like image 43
James Johnson Avatar answered Oct 27 '22 11:10

James Johnson