tryingtolearn
tryingtolearn

Reputation: 29

How to code multiple paragraphs?

I want to make a website with lots and lots of paragraphs, but I'm wondering if there is a more efficient way of achieving the spacing in the code without having to go back and place <p> tags for every paragraph. I have a feeling that it is not just simply HTML and CSS to achieve this. I have tried the <pre>element but it is spacing out each line, not the paragraph itself.

Could anyone help steer me in the right direction of how to do this?

Upvotes: 2

Views: 12004

Answers (5)

Will
Will

Reputation: 20235

You could write your paragraphs in Markdown and then convert them to HTML. In Markdown, paragraphs are delimited by two line breaks, not with tags. (Stack Overflow uses Markdown for posts.)

Example:

This is one paragraph in Markdown.

This is a second paragraph. As you can see, no `<p></p>` tags are necessary.

Upvotes: 1

Lavi Avigdor
Lavi Avigdor

Reputation: 4182

If I understand you correctly, you have a long text that is divided to paragraphs, and you want to display it "correctly" in the browser. Paragraph division in texts is usually achieved by a blank line between them.

So - you should parse the existing paragraphs from the text:

var paragraphs  = text.match(/[^\r\n]+/g);

Add HTML paragraph formatting:

var paragraphsInHtml = paragraphs.map(function(paragraph) {
    return "<p>" + paragraph + "</p>";
});

And reform the text:

var formattedText = paragraphsInHtml.join();

[code snippets are in javascript]

Upvotes: 0

James Snowy
James Snowy

Reputation: 415

A solution could be writing a full properly p element and then just copy and paste it as much as you want and need.

To add space between each p element, use the br element which gives you space as it "breaks" up the rows.

Hope this helped you, happy programming!

Upvotes: 0

Matthew
Matthew

Reputation: 4339

<p> is the correct way to make a paragraph. The HTML5 specification allows you to exclude the ending </p> tag but many browsers and blogging engines require it so I'd advise you to include it. A <br> tag can be used to make a generic line break but doesn't allow you to apply CSS styles to your paragraph, so don't use it for paragraphs.

If you just don't want to type out <p> every time, then what you want is an IDE or a rich-text editor that can output the html for you.

Upvotes: 4

Gregorie
Gregorie

Reputation: 129

You want use snippets? For fast codding you can use emmet. For example:

You can write p.class_name*4 and after that you will get

<p class="class_name"></p>
<p class="class_name"></p>
<p class="class_name"></p>
<p class="class_name"></p>

I hope i understand you correctly.

Upvotes: 0

Related Questions