Closed einarsvan closed 6 years ago
Thanks for your PR :)
Isn't it better to replace newLines by br-tag instead of removing the line-break? I think, in most castes, an author inserts a line-break if he want's to see a line-break in frontend. Removing is a little bit inconsistent, I think?
You're right. We're using an Rte for the image description field and this works for us. I guess if you don't have an Rte it makes more sense to replace newlines with break tag. Haven't tested this on a non-rte image.
On May 4, 2017 12:25, "Jonathan Heilmann" notifications@github.com wrote:
Thanks for your PR :)
Isn't it better to replace newLines by br-tag instead of removing the line-break? I think, in most castes, an author inserts a line-break if he want's to see a line-break in frontend. Removing is a little bit inconsistent, I think?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jonathanheilmann/ext-jh_photoswipe/pull/28#issuecomment-299148269, or mute the thread https://github.com/notifications/unsubscribe-auth/AAnijF1cnIPoaqjvoClEd5ve5rKqwQsZks5r2aewgaJpZM4NM8GD .
How did you enable rte for image caption? I want to do some tests to support both use-cases (rte with processing and default non-rte with nl2br), but I'm not able to enable rte :/
Hi @jonathanheilmann
Sorry for the delayed response. I'm on paternity leave and not really in front of a computer all the time :)
I've taken a second look at the regex I sent you and our code, and what you say is completely true. The reason it "worked" for me the first time was that I had used some old converted html data that contained actual br tags - which worked fine.
However, if I enter some text in our RTE-enabled image description, the new lines disappear.
To enable an RTE in the description field of sys_file_reference we do this (some_extension/Configuration/TCA/Overrides/sys_file_reference.php):
$GLOBALS['TCA']['sys_file_reference']['columns']['description'] = array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.description',
'config' => array(
'type' => 'text',
'cols' => 40,
'rows' => 15,
),
);
Writing three lines of text with some html in it looks like this in the DB:
This is the first line
Second line with a <link http://dr.dk>link</link>
Third line with some <b>bold</b> and <i>italic</i> text
The output is:
title:'This is the first line Second line with a <link http://dr.dk>link</link> Third line with some <b>bold</b> and <i>italic</i> text'
but should be:
title:'This is the first line<br> Second line with a <link http://dr.dk>link</link><br> Third line with some <b>bold</b> and <i>italic</i> text'
In conclusion, the regex needs to insert br tags and not just strip the new lines :)
I've done some test and created another solution. This solution handles every image cation field as rte field, parses the content to valid html and removes all newlines to create a valid javascript result.
It's done by replacing line 95 in PhotoswipeItemViewHelper by
/** @var ContentObjectRenderer $contentObject */
$contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
$description = $contentObject->parseFunc(trim($properties['description']), [], '< lib.parseFunc_RTE');
$result .= ",\n title:'".preg_replace("/\r|\n/", "", $description)."'";
In your css you could add a new rule to remove bottom padding/margin of the last p-tag in class pswp__caption__center
.
It would be great if you could test this change and leave some feedback.
I've done some testing with our setup and this works really well. There is one thing missing, though. Single quotes in the text need to be escaped (we use these quite frequently):
I've updated your PR and will merge this before releasing version 0.2.0
Should the description property of a file reference contain a new line, the whole FE rendering of PS items breaks. By trimming and replacing new lines before outputting them, it is now possible to render longer descriptions with/without html.
Clean up based on: http://stackoverflow.com/a/3760830/1788026