When run through the ‘truncate’ function, leaving off the closing tag,
causing untold trouble and chaos. On top of that, the trunctate
function counts characters in the tag, so you end up getting somewhat
less than what you asked for.
So… is there a way to truncate html text properly?
By this I mean a function or set of functions that returns a chunk of
html with the tags properly closed and where the length of the text
outside the tags is the specified amount.
@Ezra… I would like to retain the HTML formatting if possible.
Stripping them out would work, but then the formatting gets lost. Not
ideal, but functional.
Closing the broken tags might work. I need to see how this works if a
tag gets chopped in half.
@Ezra… I would like to retain the HTML formatting if possible.
Stripping them out would work, but then the formatting gets lost. Not
ideal, but functional.
Closing the broken tags might work. I need to see how this works if a
tag gets chopped in half.
Perhaps if you explained why you want to truncate an HTML string, that
would help…
regards
Justin
@Justin:
The goal is to have an ‘article’ model. I would like to have the ‘list’
view generate a brief excerpt of the article body as a teaser. For now
the text itself is being generated from text using textile. I have
considered simply truncating the textile source and then generating html
from that, but you run into similar problems with unbalanced decorations
(sort of like my Christmas tree).
@Andreas, yes, removing the malformed tag at the end is easy. The rest
of it is a bit tricky, but I am making progress. It is a good learning
excercise for regex judo.
The goal is to have an ‘article’ model. I would like to have the ‘list’
view generate a brief excerpt of the article body as a teaser. For now
the text itself is being generated from text using textile. I have
considered simply truncating the textile source and then generating html
from that, but you run into similar problems with unbalanced decorations
(sort of like my Christmas tree).
Thanks, that’s useful. Have you looked at the feasibility of altering
the textile-to-html conversion, so that it works with a bound on the
number of content characters? On reaching the bound, it would just need
to emit closing tags for all currently unclosed HTML tags.
Thanks, that’s useful. Have you looked at the feasibility of altering
the textile-to-html conversion, so that it works with a bound on the
number of content characters? On reaching the bound, it would just need
to emit closing tags for all currently unclosed HTML tags.
regards
Justin
Thanks, that’s a good suggestion. This may solve my immediate problem
so long as I continue to use textile. However, I’m still interested in
finding a more general solution to the problem.