Friday, September 2, 2011

Re: How do I capitalize text bewteen HTML tags?


On Fri, Sep 2, 2011 at 1:31 PM, Tim Chase <vim@tim.thechases.com> wrote:
On 09/02/11 11:29, tplarkin7 wrote:
I then used VIM to capitalize the text since ordinary regex does not have
that ability.

For those that can't see the code I posted, it is visible in VIM's forum.

Ah, you're posting through Nabble which doesn't seem to pass along the HTML to the official Vim list (vim@vim.org, mirrored at vim_use@googlegroups.com).

Pulling in the source from the URL in your Nabble email I get the following:

       
This post was updated on .

I would like to capitalize the words, "Narrator (v.o.)" between the paragraph tags below:

<P STYLE="margin-left: 2in; margin-bottom: 0in">Narrator
(v.o.)</P>



I need to keep the entire tag as shown. For example, other tags have a margin of 1in, and I don't want to capitalize between them.

Another issue is the hard return after "Narrator". Some of the lines in my HTML file have no return such as the line below:

<P STYLE="margin-left: 2in; margin-bottom: 0in">Aristobulus</P>


Thanks for your help!

EDIT:
I'm slowly figuring this out:

I've successfully capitalized the following example:

Before code:

<P ALIGN=CENTER>Narrator (v.o.)</P>


After code:

<P ALIGN=CENTER>NARRATOR (V.O.)</P>


Code used:

:%s:\(<P ALIGN=CENTER>\)\(.*\)\(<\):\1\U\2\3:g


I attempted the same for

<P STYLE="margin-left: 2in; margin-bottom: 0in">Aristobulus</P>


But, it gave me an error.

You don't give the error or the command you gave, so it's hard to track down what went wrong.  I'd try something like

 :%s/\c<P style="[^"]*2in[^"]*"[^>]*>\zs\_[^<]*\ze</\U&/g

It has odd edge-cases where you might have nested tags, but it should handle most of the cases.

A totally different approach would be to use semantic markup with CSS and get rid of all the inline styles leaving you with much cleaner HTML, as God and the W3C intended.

<style>
.narrator {text-transform: uppercase}
</style>

<p class="narrator">Narrator (v.o.)</p>
-- 
/George V. Reilly  george@reilly.org  Twitter: @georgevreilly
http://www.georgevreilly.com/blog  http://blogs.cozi.com/tech


 

--
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

No comments:

Post a Comment