Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treat a p tag as an nbsp? #10

Open
joepagan opened this issue Jun 30, 2015 · 9 comments
Open

treat a p tag as an nbsp? #10

joepagan opened this issue Jun 30, 2015 · 9 comments

Comments

@joepagan
Copy link

Hey,

I was wondering if there was a way of dealing with adding an nbsp to replace a paragraph, for example an excerpt of text looks like this at the moment:
operators and infrastructure owners.We work on

Could we change this somehow to output like this?:
operators and infrastructure owners. We work on

@joepagan
Copy link
Author

Or even treat a p tag as a <br> where the closing </p> would be?

@ryanshrum
Copy link
Contributor

I'm not sure I'm following what you're trying to do. By default Hacksaw shouldn't remove a space. Are you sure there is a space in the Rich Text field?

@joepagan
Copy link
Author

joepagan commented Jul 1, 2015

Hi Ryan, Sorry I'm probs not being clear.

Currently using this in my template:
{{ subEntry.pageContent|hacksaw(words='36', append=' [&hellip;]') }}
will output this:
"operators and infrastructure owners.We work on"

Instead, I would like to output it like this:
"operators and infrastructure owners. We work on"

The problem is that there are multiple paragraphs in my variable, after the "." there is a closing </p>, I feel that it should maybe add a nbsp to replace the closing paragraph tag, or at least give us an option for it.

@ryanshrum
Copy link
Contributor

Are you in the Slack channel? I just tested what you've put here and there is a space between the "." and the "We". I also tested an large ipsum lorem block with multiple <p> and Hacksaw returned the expected string.

dbnde3lyly_oyq3ssm5n-kh7vba5ltezpvuwghmrgom

m4dtf3a1ktuebqwef-1u0l6pi87r_xxe7pwzhiwud5o

ofmf9evi6wu92ax5dmgdsbjza3uoronr3g3leupqm1w

@joepagan
Copy link
Author

joepagan commented Jul 1, 2015

I'm not at the moment, I've just left for the day, though I'll take another
look tomorrow. Though I think the issue is more when you have something
like this

text.

more text

.

My text will be straight from a rich text field, so I guess depends on what
ever redactor has done to it.

On 1 July 2015 at 16:08, Ryan Shrum [email protected] wrote:

Are you in the Slack channel? I just tested what you've put here and there
is a space between the "." and the "We". I also tested an large ipsum lorem
block with multiple

and Hacksaw returned the expected string.

[image: dbnde3lyly_oyq3ssm5n-kh7vba5ltezpvuwghmrgom]
https://cloud.githubusercontent.com/assets/1153690/8457761/5e73a2da-1fe1-11e5-9688-9e250eebf2a9.png

[image: m4dtf3a1ktuebqwef-1u0l6pi87r_xxe7pwzhiwud5o]
https://cloud.githubusercontent.com/assets/1153690/8457759/5bd86240-1fe1-11e5-9d8a-20e205f362d8.png

[image: ofmf9evi6wu92ax5dmgdsbjza3uoronr3g3leupqm1w]
https://cloud.githubusercontent.com/assets/1153690/8457718/2003d5f6-1fe1-11e5-96bf-1a040ffa1f65.png


Reply to this email directly or view it on GitHub
#10 (comment)
.

@shantamg
Copy link

shantamg commented Jun 5, 2016

I am seeing this issue as well. I think it would be good to add a space (doesn't even have to be an nbsp) if there isn't one between p tags. If the closing p and the following opening p have no space between them then it will look like a typo where there's no space between sentences.

@joepagan
Copy link
Author

joepagan commented Jun 5, 2016

I totally forgot to look at this, I've marked your notification as unread so I can look at it again tomorrow.

@shantamg
Copy link

shantamg commented Jun 5, 2016

Looking at the plugin, it's using the php function strip_tags().

What do you guys think of this type of solution?

The idea is to use a regex to add a space where an opening tag directly follows a close tag:

$html = preg_replace('/(<\/[^>]+?>)(<[^>\/][^>]*?>)/', '$1 $2', $html);
$html = strip_tags($html);

@joepagan
Copy link
Author

joepagan commented Jun 6, 2016

Just revisited this, sorry for the 6month delay lol. So I can confirm that it still appears to behave in this way. This code:

{{ '<p>hello how are you doing.</p><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias ad soluta impedit odit nisi quam possimus quo laborum provident dicta.</p>'|hacksaw(words='15', append=' [&hellip;]') }}

Outputs this:

hello how are you doing.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias ad soluta [&hellip;]

If there is a closing paragraph (or even any other element), I believe that a space should occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants