Coder Social home page Coder Social logo

Comments (12)

joemsak avatar joemsak commented on July 19, 2024

Interesting, I'm not sure where that preserve option comes from, then,
because I've seen it around Refinery before... thanks for highlighting this

I am in the process of integrating a syntax highlighter and noticed that

line breaks and whitespace was not preserved on the index page of the blog.
I was mainly concerned for the content within "pre" and "code" tags. The
show page seemed to render fine.

I traced it back to the teaser helper:

def blog_post_teaser(post)
if post.respond_to?(:custom_teaser) && post.custom_teaser.present?
post.custom_teaser.html_safe
else
truncate(post.body, {
:length => RefinerySetting.find_or_set(:blog_post_teaser_length,
250),
:preserve_html_tags => true
}).html_safe
end
end

It seems that the truncate method is not preserving html properly. I had a
look at the rails api and I couldn't find a method to support the
:preserve_html_tags being passed. In addition, the truncate method states
in the documentation
that it does not preserve valid html.

Does the blog use another custom truncate method to preserve tags? Is this
a valid option? Perhaps something like this would be better?

Thanks!

Reply to this email directly or view it on GitHub:
https://github.com/resolve/refinerycms-blog/issues/98

from refinerycms-blog.

ugisozols avatar ugisozols commented on July 19, 2024

Refinery uses this plugin https://github.com/hgimenez/truncate_html and here's Refinery helper https://github.com/resolve/refinerycms/blob/master/core/lib/refinery/helpers/html_truncation_helper.rb which uses that plugin.

from refinerycms-blog.

astjohn avatar astjohn commented on July 19, 2024

I believe that might be the same one I found earlier. Any idea why
whitespace and line breaks are removed?

On Thu, Jul 7, 2011 at 2:22 PM, ugisozols <
[email protected]>wrote:

Refinery uses this plugin https://github.com/hgimenez/truncate_html and
here's Refinery helper
https://github.com/resolve/refinerycms/blob/master/core/lib/refinery/helpers/html_truncation_helper.rbwhich uses that plugin.

Reply to this email directly or view it on GitHub:
https://github.com/resolve/refinerycms-blog/issues/98#issuecomment-1524859

from refinerycms-blog.

ugisozols avatar ugisozols commented on July 19, 2024

By taking a quick look at truncate_html specs https://github.com/hgimenez/truncate_html/blob/master/spec/truncate_html/html_string_spec.rb#L10-16 it's clear that removing continuous whitespace is intended behavior.

Dunno about line breaks as I haven't looked any further yet.

from refinerycms-blog.

parndt avatar parndt commented on July 19, 2024

@joemsak @ugisozols @astjohn status?

from refinerycms-blog.

astjohn avatar astjohn commented on July 19, 2024

@parndt, as ugisozois has pointed out, whitespace is intentionally removed by the truncate_html gem. This effectively breaks the ability to use code and pre blocks.

For my own personal use, I have since disabled the teaser functionality. Either refinerycms-blog will have to roll it's own solution, or the gem will have to perhaps add an option to preserve whitespace. Unfortunately, I don't have time at the moment to contribute.

from refinerycms-blog.

ugisozols avatar ugisozols commented on July 19, 2024

I haven't looked into this issue any further... should I?

from refinerycms-blog.

parndt avatar parndt commented on July 19, 2024

@ugisozols sure if you like, the best option might be to contribute a patch to truncate_html that allows an option for preserving whitespace.

from refinerycms-blog.

parndt avatar parndt commented on July 19, 2024

Any failing test would do too

from refinerycms-blog.

budu avatar budu commented on July 19, 2024

@astjohn how do you disable teasers?

from refinerycms-blog.

astjohn avatar astjohn commented on July 19, 2024

@budu, Unfortunately, it's been a while and I have moved away from refinery. At the time, I believe I ended up removing anything that would have rendered them while I customized the views. Not ideal.

from refinerycms-blog.

parndt avatar parndt commented on July 19, 2024

I think an acceptable workaround is to enter content into the custom_teaser field :-)

from refinerycms-blog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.