Comments (13)
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.
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.
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.
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.
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.
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.
Agreed! Will look into this this week.
from decoda.
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.
Have you had a change to test it out? I'm sure you have more concrete test cases than I do.
from decoda.
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.
Just tagged 4.1.0-beta, so feel free to submit pull requests with the updated code.
from decoda.
Finally got around to testing this. All my test cases worked perfectly. Thank you!
from decoda.
Awesome, lucky me I don't have to push another tag :]
from decoda.
Related Issues (20)
- Emoticons not parsed when having the next to it HOT 3
- Uppercase Tags don't set defaults HOT 1
- Two bugs HOT 3
- Links and ClickableHook HOT 8
- Support for BBCode standalone tags? HOT 4
- caching HOT 2
- Problem with ulr tag which contain "_" HOT 2
- Force img tag to be https on https site HOT 3
- Support for [noparse] tag HOT 2
- Library Broken with PHP 7.3 HOT 2
- removeFilter('Video') Broken
- PHP5.6+? HOT 3
- Did not parse color if the color parameter is not enclosed with " HOT 1
- PHP7.2+ HOT 6
- Pass string as method argument HOT 3
- Use MediaEmbed for video filter HOT 1
- Normal "quotes" are not escaped HOT 4
- Url filter problems HOT 1
- Is there any way to use this without composer? HOT 1
- 6 UU
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from decoda.