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

Helper method to get the rest of given html #65

Open
ElvinEfendi opened this issue May 31, 2015 · 0 comments
Open

Helper method to get the rest of given html #65

ElvinEfendi opened this issue May 31, 2015 · 0 comments

Comments

@ElvinEfendi
Copy link

Sometimes there is a requirement to toggle the rest of given html text using Javascript(show more/show less functionality). In order to implement this without duplicating truncated html I need the rest of it.
I tried to get the rest of html as following:

truncated_content = truncate_html(item.content, length: 300, omission: '')
trunc_length = truncated_content.length
rest = item.content[trunc_length, item.content.length]

But when there are extra consecutive whitespace in the given html, above code won't produce correct output. This is because in TruncateHtml::HtmlString#html_tokens method consecutive whitespace are being reduced to single whitespace.

Therefore I propose to create new helper "slice_html" that returns both truncated html and
the rest as following:

truncated_content, rest = slice_html(item.content, length: 300, omission: '')
ElvinEfendi added a commit to ElvinEfendi/truncate_html that referenced this issue May 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant