rkingon / Craft-Plugin--Trimmer

27 stars 1 forks source link

Stripping of P tags leave no spaces. #1

Closed kragit closed 10 years ago

kragit commented 10 years ago

If a <p></p> tag par is stripped from the HTML, the resulting text/sentences are smushed together without a space.

<p>News: China has officially banned Battlefield 4 because of it's threat to national security, 
the country's Ministry of Culture has said.</p>

<p>The ban came shortly after the China Rising DLC for [...] </p>

turns into

[...] country's Ministry of Culture has said.The ban came [...] 

I've negated the issue by adding

$str = preg_replace('/(<\/p>)(<p>)/', '$1 $2', $str);

preceding the strip_tags line (around line 36 in TrimmerTwigExtension.php), but an actual "fix" would likely be more flexible.

rkingon commented 10 years ago

Interesting.. you must not have a space or a line break separating your paragraph tags. Something php's striptags should really take into consideration.

would be wiser to change your regex to this: /(<[^<]+?>)(<[^<]+?>)/

That'll target all html tags vs just the p's. I'll take a look at a few options and update the code. Thanks! :)

kragit commented 10 years ago

I considered changing the regex to that, but I believe that would also introduce spaces after stylistic tags such as b, strong, i, em, etc.

rkingon commented 10 years ago

extra spaces won't make a difference on the output. html collapse's all "breaking" spaces into 1 space (vs non-breaking - nbsp)

rkingon commented 10 years ago

I misinterpreted what you were saying earlier- with the stylistic tags.

Basically, we would need block type tags to have the space, but inline ones shouldn't. just incase the tag is "mid-word." I think it's a pretty small use case though that one would have that.

Imma look into this today and see what I come up with.. oh php how i love thee

rkingon commented 10 years ago

Hey- latest commit: 9a821825922186b4004244e50f34f75150c6e9d4 should fix this up for ya. let me know if any other problems! :)