Monday, June 3, 2013

Re: HTML blank insertion program

On 2013-06-03 01:42, Steve Litt wrote:
> I was concerned about Vim's weird indentation of HTML, and Tim Chase
> clued me in about Tidy, which does most of what I want but leaves no
> blank lines. I want 3 blank lines above each <h1>, and one blank
> line above each of <h[[:digit:]]>, <ol>, <ul>, <table>, <p>,
> <body>, and <div>.
>
> However, to make <h1> stand out even more, I don't want any blank
> lines immediately below an <h1>,

It sounds like you should be able to do something like

:%s@\%(\s*\n\)*\(<h1\_.\{-}</h1>\)\%(\n\s*\)*@\r\r\r\r\1

which consumes all blank lines[1] before a <h1> tag, captures the <h1>
element, then captures all trailing blank lines, and replaces it with
4 newlines[2] and the captured <h1> contents. This does make some
assumptions that your tags are lower-case and you're not doing
anything pathological-though-legal like

< h1>There are extra spaces in the tags?!< / h1>

-tim

[1]
It also strips the trailing whitespace+newline off the last line of
content, so when we do the replacement...

[2]
we need to put that one extra newline back in.




--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: