Skip to content

Helper method to get the rest of given html #65

@ElvinEfendi

Description

@ElvinEfendi

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: '')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions