Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

How to tell if the content of one tag is completely contained within another?

by prasadbabu (Prior)
on Oct 06, 2004 at 16:15 UTC ( [id://397057]=perlquestion: print w/replies, xml ) Need Help??

prasadbabu has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I have some problem

The title should not have fully formatted

For example,

<title><b>Meta&hyphen;Ethics and The Problem of Creeping Minimalism</b></title>

In the above case we have <b> tag and the title is fully formatted by bold tag.

But the title can have partial formattings.

<title>Meta&hyphen;Ethics and <b>The Problem of Creeping</b> <b>Minimalism</b></title>

The above partial formatting is allowed.

If fully formatted, "ERROR: The <title> is fully formatted"

How we can solve this problem?

Thanks in advance

Prasad

Edited by demerphq to fix run-on bold tag and retitled from 'matching'

Replies are listed 'Best First'.
Re: matching
by demerphq (Chancellor) on Oct 06, 2004 at 16:28 UTC

    Its not very clear what you are asking. If you want to know how to tell if the bold tags cover the fully content of the title tag maybe:

    sub is_all_in_bold { my $title=shift; my ($title_content)=$title=~m!<title>(.*?)</title>!s; $title_content=~s!<b>.*?</b>!!sg; return !$title_content; } while (<DATA>) { print; chomp; print is_all_in_bold($_) ? "Its all in bold\n" : "Its not all in b +old\n"; } __END__ <title><b>Meta&hyphen;Ethics and The Problem of Creeping Minimalism</b +></title> <title>Meta&hyphen;Ethics and <b>The Problem of Creeping</b> <b>Minima +lism</b></title>

    But i could have totally misunderstood the question.


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi

      Flux8


      That reports Its not all in bold on: <title><b>foo<b>bar</b></b></title>

        Yep and illustrates nicely why handling HTML with regexes is not recommended. Anyway, I think the following works:

        sub is_all_in_bold { my $title=shift; my ($title_content)=$title=~m!<title>(.*?)</title>!s; 1 while $title_content=~s#<b>(?:[^<>]+|(?!</?b>).)*</b>##s; print "$title_content\n"; return !$title_content; } while (<DATA>) { print; chomp; next unless /\S/; print is_all_in_bold($_) ? "Its all in bold\n" : "Its not all in b +old\n"; } __END__ <title><b>Meta&hyphen;Ethics and The Problem of Creeping Minimalism</b +></title> <title>Meta&hyphen;Ethics and <b>The Problem of Creeping</b> <b>Minima +lism</b></title> <title><b>foo<b>bar</b></b></title>

        ---
        demerphq

          First they ignore you, then they laugh at you, then they fight you, then you win.
          -- Gandhi

          Flux8


Re: matching
by data64 (Chaplain) on Oct 06, 2004 at 16:32 UTC

    HTML::TokeParser might be useful for this. It will return each tag one by one and you can write your logic around it.


    Just a tongue-tied, twisted, earth-bound misfit. -- Pink Floyd

Re: matching
by Joost (Canon) on Oct 06, 2004 at 16:23 UTC
    I'm not sure what you mean, but having markup in <title> tags is not allowed by the standard anyway.

    Also, please use <code> tags if you want to show code. :-)

    update: I'm assuming that you're trying to create HTML, where you shouldn't have ANY formatting in the title.

    What I can't figure out is wether you want the error message to appear, or if you want the message to go away. :-/

Re: How to tell if the content of one tag is completely contained within another?
by bibo (Pilgrim) on Oct 06, 2004 at 17:01 UTC
    Two comments on your question:

    First, it's considered bad form here to keep reposting the same question. Your reposted question was removed from the queue for this reason. You should do some reading over at the FAQ to learn more about how things work here: About the PerlMonks FAQ

    Secondly, I'd love to know where are you getting this Error message from? What program? What operating system? More background info will help all of us understand your question.

    We want to help you, if you can provide us more info.

    --bibo

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://397057]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-24 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found