Git Product home page Git Product logo

Comments (13)

milesj avatar milesj commented on August 21, 2024

You could just use strip_tags().

echo strip_tags($code->parse());

I don't really see the usefulness of removing all text within tags.

from decoda.

patrickheeney avatar patrickheeney commented on August 21, 2024

Removing all text within tags is only one portion of this which would be useful when you want to parse content with no tags. In my case I have added 60+ Filters that do many different things so the need for this is probably more apparent in my situation.

However I still think there is a need to remove the tags AND remove the internal content. Image trying to render an excerpt of a page by cutting out the first 200 characters you might end up with something like this Some text here [b]this is great. In this case removing the shortcodes before generating an excerpt would give correct results. Now imagine the first text you have on the page is some [code]blah blah blah[/code]. Without being able to remove the tag AND the content then once again the except is not the desired output.

That is just one use case but lets also say you want to render a mobile version of a page that you dont want to be compatible with lets say your [video], [audio], [googlemap], etc tags. You could blacklist these but it does not solve the need to completely remove the tag AND the content or remove the tags but KEEP the content.

I could see uses for both and these are just a couple thoughts of what I am running into by adding more Filters.

from decoda.

milesj avatar milesj commented on August 21, 2024

I see what you mean. All the ideas popping in my head are rather complex as each tag would need its own stripping options.

from decoda.

patrickheeney avatar patrickheeney commented on August 21, 2024

I was thinking it would only need one new option which would default leaving the inner content. It just needs an option to tell it whether to strip the inner content or not. No matter what it will strip the [codes] so we just care about if we leave [code]this stuff[/code] or not.

In the $code->striptags() function could run parse() but instead of replacing the content and searching for attributes it would instead just substr(strpos('['), strpos(']'), open tag and close tag). And if the strip inner content setting is on it would substr(strpos('['), strpos(']'), open tag through the closing tag).

Know what I mean? Or should I write a pseudocode example?

from decoda.

milesj avatar milesj commented on August 21, 2024

Right, but the way I see it, you would want to keep content with simple tags like b, i, u, etc... but not content within code, quote, etc. But there should be a way to dynamically flag each tag during cleanup.

Perhaps in each Filter a new option can be added to every tag that has a default functionality, then you can override per tag as well.

from decoda.

patrickheeney avatar patrickheeney commented on August 21, 2024

Exactly. Thats what I meant with the 'stripContent' => false idea on the FilterAbstract. It would default to keeping the content in [b], [i], etc tags. Then in [video], [code], etc you would set it to 'stripContent' => true to override.

from decoda.

milesj avatar milesj commented on August 21, 2024

Agreed! Will look into this this week.

from decoda.

milesj avatar milesj commented on August 21, 2024

I pushed some code to master if you want to mess around with it. I have no way of doing individual flags when strip() is called though.

from decoda.

milesj avatar milesj commented on August 21, 2024

Have you had a change to test it out? I'm sure you have more concrete test cases than I do.

from decoda.

patrickheeney avatar patrickheeney commented on August 21, 2024

Hey sorry, was out of town. My code is modified a bit so I will try and merge these in and give it a test. Thanks for your quick work!

from decoda.

milesj avatar milesj commented on August 21, 2024

Just tagged 4.1.0-beta, so feel free to submit pull requests with the updated code.

from decoda.

patrickheeney avatar patrickheeney commented on August 21, 2024

Finally got around to testing this. All my test cases worked perfectly. Thank you!

from decoda.

milesj avatar milesj commented on August 21, 2024

Awesome, lucky me I don't have to push another tag :]

from decoda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.