By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,836 Members | 1,704 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,836 IT Pros & Developers. It's quick & easy.

Blank lines and paragraph break in html

P: n/a
Hi there,

I have a quick question. In my html document, I want to make a new
paragraph whenever I have a blank line in the html source. Using <p>
and </pevery time is kind of cumbersome (I want to do it the LaTeX
way). Is it possible at all?

Thanks for your time,
Yogi

May 11 '07 #1
Share this Question
Share on Google+
15 Replies


P: n/a
Yogi wrote:
I have a quick question. In my html document, I want to make a new
paragraph whenever I have a blank line in the html source. Using <p>
and </pevery time is kind of cumbersome (I want to do it the LaTeX
way). Is it possible at all?
<pis the semantically correct way to mark up a paragraph. You
shouldn't want to change that.

You can style it however you like with CSS.

p { margin-bottom: 4em; }

Play with the numbers.

Sorry, what is the LaTeX way?

--
-bts
-Motorcycles defy gravity; cars just suck
May 11 '07 #2

P: n/a
Yogi wrote:
Hi there,

I have a quick question. In my html document, I want to make a new
paragraph whenever I have a blank line in the html source. Using <p>
and </pevery time is kind of cumbersome (I want to do it the LaTeX
way). Is it possible at all?

Thanks for your time,
Yogi
HTML stands for HyperText Markup Language. To be HTML, it must have the
markups (e.g., <p>).

In most cases, the end-tag </pis optional. I use the end-tag only
when I have declared a style for <p(e.g., via a class attribute) that
I don't want to continue into content where I don't want to declare a
new paragraph.

--

David E. Ross
<http://www.rossde.com/>.

Don't ask "Why is there road rage?" Instead, ask
"Why NOT Road Rage?" or "Why Is There No Such
Thing as Fast Enough?"
<http://www.rossde.com/roadrage.html>
May 11 '07 #3

P: n/a
Yogi wrote:
>
I have a quick question. In my html document, I want to make a new
paragraph whenever I have a blank line in the html source. Using <p>
and </pevery time is kind of cumbersome (I want to do it the LaTeX
way). Is it possible at all?
You can try making your content as a text file, with <preand </pre>
deliminating it, and hope for the best. I'm not sure what HTML markup
you'll be able to use inside the <preelement, but I'll leave that
discovery to you.

I must say, though, that it's a weird request. Marking up paragraphs as
paragraphs in documents is part of Web publishing. HTML is the means to
do that. Throwing out a three-byte tag because it's too long is jsut
bizarre to me. But then, I am not a follower of the LaTeX Way.

--
John
May 11 '07 #4

P: n/a
"Beauregard T. Shagnasty" <a.*********@example.invalidwrites:
Yogi wrote:
>I have a quick question. In my html document, I want to make a new
paragraph whenever I have a blank line in the html source. Using <p>
and </pevery time is kind of cumbersome (I want to do it the LaTeX
way). Is it possible at all?

<pis the semantically correct way to mark up a paragraph. You
shouldn't want to change that.

You can style it however you like with CSS.

p { margin-bottom: 4em; }

Play with the numbers.

Sorry, what is the LaTeX way?
The LaTeX way is for blank lines in source to denote paragraph breaks.
If it looks like a paragraph in source, it's a paragraph in the output.

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
May 11 '07 #5

P: n/a
Yogi <yo*************@gmail.comwrites:
I have a quick question. In my html document, I want to make a new
paragraph whenever I have a blank line in the html source. Using <p>
and </pevery time is kind of cumbersome (I want to do it the LaTeX
way). Is it possible at all?
You might have a look at Markdown:

<http://en.wikipedia.org/wiki/Markdown>
<http://daringfireball.net/projects/markdown/syntax>

Browsers don't understand Markdown, but many CMS systems and editors do,
and can automagically translate it into HTML.

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
May 11 '07 #6

P: n/a
On 11 May, 03:31, Yogi <yogeshwersha...@gmail.comwrote:
I have a quick question. In my html document, I want to make a new
paragraph whenever I have a blank line in the html source.
Just regex pairs of adjacent linebreaks into <p>.

s/\n(\s*\n\s*)+/\n<p>/

You can ignore the </pin HTML (but don't use XHTML).

Remember that in HTML a <pmarks the _start_ of a paragraph, not a
"paragraph break". The difference is subtle, but significant. I don't
know how TeX regards this.

Don't confuse this with <br>. That's a linebreak, which is an inline
thing not paras, and it also is a "break" marker, not a "start"
marker.

If you don't like the rendered whitespace you get, fix that with CSS,
not by changing the underlying HTML

If you really care, run the converted HTML through Tidy afterwards.
May 11 '07 #7

P: n/a
On 2007-05-11, Andy Dingley wrote:
On 11 May, 03:31, Yogi <yogeshwersha...@gmail.comwrote:
>I have a quick question. In my html document, I want to make a new
paragraph whenever I have a blank line in the html source.

Just regex pairs of adjacent linebreaks into <p>.

s/\n(\s*\n\s*)+/\n<p>/
That will not work. Text utilities read a line at a time, and a
line cannot contain a newline.

With awk:

awk '
/./ && empty { empty = 0; printf "<p>" }
!/./ { empty = 1 }
{print}
'

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
========= Do not reply to the From: address; use Reply-To: ========
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
May 12 '07 #8

P: n/a
"Chris F.A. Johnson" <cf********@gmail.comwrites:
On 2007-05-11, Andy Dingley wrote:
>On 11 May, 03:31, Yogi <yogeshwersha...@gmail.comwrote:
>>I have a quick question. In my html document, I want to make a new
paragraph whenever I have a blank line in the html source.

Just regex pairs of adjacent linebreaks into <p>.

s/\n(\s*\n\s*)+/\n<p>/

That will not work. Text utilities read a line at a time
s/Text utilities/Awk/

I hate to break it to you, but Awk is not the only text utility in
the world. It may still have that old one-line-at-a-time limit, but
the rest of the world moved past that years ago.

If you use something reasonably modern - Perl, Ruby, Python, Java,
any of a variety of regex-aware editors, etc. - the above will work
just fine.

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
May 12 '07 #9

P: n/a
On 2007-05-12, Sherm Pendley wrote:
"Chris F.A. Johnson" <cf********@gmail.comwrites:
>On 2007-05-11, Andy Dingley wrote:
>>On 11 May, 03:31, Yogi <yogeshwersha...@gmail.comwrote:

I have a quick question. In my html document, I want to make a new
paragraph whenever I have a blank line in the html source.

Just regex pairs of adjacent linebreaks into <p>.

s/\n(\s*\n\s*)+/\n<p>/

That will not work. Text utilities read a line at a time

s/Text utilities/Awk/
And sed and other text utilities.
I hate to break it to you, but Awk is not the only text utility in
the world. It may still have that old one-line-at-a-time limit, but
the rest of the world moved past that years ago.

If you use something reasonably modern - Perl, Ruby, Python, Java,
any of a variety of regex-aware editors, etc. - the above will work
just fine.
Those are overkill for a simple task that can be done easily in sed
or awk.

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
========= Do not reply to the From: address; use Reply-To: ========
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
May 12 '07 #10

P: n/a
"Chris F.A. Johnson" <cf********@gmail.comwrites:
On 2007-05-12, Sherm Pendley wrote:
>"Chris F.A. Johnson" <cf********@gmail.comwrites:
>>On 2007-05-11, Andy Dingley wrote:
On 11 May, 03:31, Yogi <yogeshwersha...@gmail.comwrote:

I have a quick question. In my html document, I want to make a new
paragraph whenever I have a blank line in the html source.

Just regex pairs of adjacent linebreaks into <p>.

s/\n(\s*\n\s*)+/\n<p>/

That will not work. Text utilities read a line at a time

s/Text utilities/Awk/

And sed and other text utilities.
s/other/other ancient, obscure, rarely used in the modern world/
>I hate to break it to you, but Awk is not the only text utility in
the world. It may still have that old one-line-at-a-time limit, but
the rest of the world moved past that years ago.

If you use something reasonably modern - Perl, Ruby, Python, Java,
any of a variety of regex-aware editors, etc. - the above will work
just fine.

Those are overkill for a simple task that can be done easily in sed
or awk.
You had to write four lines of code to work around Awk's one line at a
time limitation, when the tools I mentioned can do the same with one
line of code. You have a curious definition of "easily."

perl -p -i -e 's/^$/<p>/m' foo.html

Yeah, that one command is sooooo much more difficult than your four
lines of obscurity. Total overkill. Not.

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
May 12 '07 #11

P: n/a
On Fri, 11 May 2007 21:13:49 -0400, "Chris F.A. Johnson"
<cf********@gmail.comwrote:
That will not work. Text utilities read a line at a time, and a
line cannot contain a newline.
If your favoured stream editor can't span multiple lines, you need to
upgrade it to one that does. Plenty out there. You may well need to
supply a parameter to it to turn this feature on.

Most people these days are probably doing this inside an interactive
screen editor. jEdit in my case, which would have no problem at all
doing it.

May 12 '07 #12

P: n/a
On 2007-05-12, Sherm Pendley wrote:
"Chris F.A. Johnson" <cf********@gmail.comwrites:
>On 2007-05-12, Sherm Pendley wrote:
>>"Chris F.A. Johnson" <cf********@gmail.comwrites:

On 2007-05-11, Andy Dingley wrote:
On 11 May, 03:31, Yogi <yogeshwersha...@gmail.comwrote:
>
>I have a quick question. In my html document, I want to make a new
>paragraph whenever I have a blank line in the html source.
>
Just regex pairs of adjacent linebreaks into <p>.
>
s/\n(\s*\n\s*)+/\n<p>/

That will not work. Text utilities read a line at a time

s/Text utilities/Awk/

And sed and other text utilities.

s/other/other ancient, obscure, rarely used in the modern world/
>>I hate to break it to you, but Awk is not the only text utility in
the world. It may still have that old one-line-at-a-time limit, but
the rest of the world moved past that years ago.

If you use something reasonably modern - Perl, Ruby, Python, Java,
any of a variety of regex-aware editors, etc. - the above will work
just fine.

Those are overkill for a simple task that can be done easily in sed
or awk.

You had to write four lines of code to work around Awk's one line at a
time limitation, when the tools I mentioned can do the same with one
line of code. You have a curious definition of "easily."

perl -p -i -e 's/^$/<p>/m' foo.html

Yeah, that one command is sooooo much more difficult than your four
lines of obscurity. Total overkill. Not.
That doesn't do what the awk script I posted does. The awk
equivalent of your perl script is:

awk '/^$/{print "<p>"}1' foo.html

Or in sed:

sed 's/^$/<p>/'

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
========= Do not reply to the From: address; use Reply-To: ========
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
May 12 '07 #13

P: n/a
I must say, though, that it's a weird request. Marking up paragraphs as
paragraphs in documents is part of Web publishing. HTML is the means to
do that. Throwing out a three-byte tag because it's too long is jsut
bizarre to me. But then, I am not a follower of the LaTeX Way.

--
John
Thanks for your opinion. I do not think that three-byte tag is too
long, it is just that I happen to use many paragraph breaks, and LaTeX-
way makes it a little bit easy to read the code (not a whole lot
easier though).

Thanks,
Yogi
May 13 '07 #14

P: n/a
Yogi wrote:
>I must say, though, that it's a weird request. Marking up paragraphs as
paragraphs in documents is part of Web publishing. HTML is the means to
do that. Throwing out a three-byte tag because it's too long is jsut
bizarre to me. But then, I am not a follower of the LaTeX Way.

--
John

Thanks for your opinion. I do not think that three-byte tag is too
long, it is just that I happen to use many paragraph breaks, and LaTeX-
way makes it a little bit easy to read the code (not a whole lot
easier though).
Obviously, you need a LaTeX browser, not an HTML browser.

--

David E. Ross
<http://www.rossde.com/>.

Don't ask "Why is there road rage?" Instead, ask
"Why NOT Road Rage?" or "Why Is There No Such
Thing as Fast Enough?"
<http://www.rossde.com/roadrage.html>
May 13 '07 #15

P: n/a
On 12 May 2007 17:39:01 -0700, Yogi <yo*************@gmail.comwrote:
>... I happen to use many paragraph breaks, and LaTeX-
way makes it a little bit easy to read the code (not a whole lot
easier though).
My solution is to have a nearly blank line in the code. The markup is
used, and there's enough of a visual break to assist readability.

<h2>Section Title</h2>
<p>
This is a paragraph.</p>
<p>
This is another.</p>
--

Charles
May 14 '07 #16

This discussion thread is closed

Replies have been disabled for this discussion.