Typo3: How to remove empty paragraphs on page
Asked Answered
T

8

6

I'm using Typo3 v6.1 to create a standard page of the type “text”. In the view, Typo3 adds four empty paragraphs before and after the content created on the Rich Text Editor.

<p class="bodytext">&nbsp;</p>
<p class="bodytext">    <!--  CONTENT ELEMENT, uid:17/text [begin] --></p>
<p class="bodytext">        <a id="c17"></a></p>
<p class="bodytext">        <!--  Text: [begin] --></p>    

<p class="bodytext">The actual text added using the Rich Text Editor</p>    

<p class="bodytext">        <!--  Text: [end] --></p>
<p class="bodytext">&nbsp;</p>
<p class="bodytext">    <!--  CONTENT ELEMENT, uid:17/text [end] --></p>
<p class="bodytext">&nbsp;</p>  

It goes without saying, that I'd like to get rid off this clutter, especially since the &nbsp; are breaking the layout.

Tao answered 18/12, 2013 at 23:46 Comment(1)
You should add relevant typoscript, used extensions, TYPO3 Verison etc.Myrtamyrtaceous
M
8

There is a parseFunc < lib.parseFunc_RTE at the wrong place.

Looks like you have something like

page.10 = CONTENT
page.10.stdWrap.parseFunc < lib.parseFunc_RTE

Which would mean: render the content, and after that parse this content with lib.parseFunc_RTE. The code which activates the wrapping is

lib.parseFunc_RTE.nonTypoTagStdWrap.encapsLines.wrapNonWrappedLines = <p>|</p>

Removing would not solve the issue here, because the cause is, that lib.parseFunc_RTE is processed on the whole content element and not only on bodytext where it should be defined.

Have a look in your TypoScript or add it to your question.

for testing purpose:

Create a new Site on top level, and add only basic TypoScript (add css_styled_content template; Check clear setup and constants)

page = PAGE
page.10 < styles.content.get

Check that output, the content should not wrapped into p class="bodytext" anymore.

Update:

Using {content} where {content} is filled via styles.content.get f.e. the parseFunc is executed twice. styles.content.get executeds the parseFunc, so it can be outputted to the browser. But f:format.html executed lib.parseFunc too. So, that is, why your content is parsed twice.

# in this case, f:format.html does not need to execute the parseFunc again
<f:format.html  parseFuncTSPath="">{content}</f:format.html>

Use lib.parseFunc_RTE if you have an RTE field, use lib.parseFunc if you do not expect HTML-Code in the field (f.e. header).

Myrtamyrtaceous answered 19/12, 2013 at 7:49 Comment(2)
I just did a clean install (this time using 6.0 instead of 6.1) and it keeps happening. The only code in my template that affects lib.parseFunc_RTE is taken from this question. However, when I remove that, I still get those empty lines. When using a plugin like News, Typo3 even adds 30 empty paragraphs before the first heading.Tao
TYPO3 does not adds 30 empty paragraphs out of the box. It depends on your configuration, your template-files or perhaps an installed extension.Myrtamyrtaceous
E
6

add following lines in template script of root

In Constants :

content.RTE_compliant = 0

In Setup :

tt_content.stdWrap.dataWrap >
lib.parseFunc_RTE.nonTypoTagStdWrap.encapsLines>
Eelpout answered 12/2, 2014 at 9:11 Comment(2)
lib.parseFunc_RTE.nonTypoTagStdWrap.encapsLines> does the job for my own parse funcSaxecoburggotha
lib.parseFunc_RTE.nonTypoTagStdWrap.encapsLines> does the job even in 2021 in TYPO3 10Castano
R
1

This is a solution to a variant of the problem described in the post.

<f:format.html>
   {field.copyrightText}
</f:format.html>

gives you one paragraph before and after the expected paragraph

<f:format.html>{field.copyrightText}</f:format.html>

gives you no additional paragraphs. So the breaks in a template seem to be parsed by the format viewHelper.

hope this helps someone; have a good day

Rounder answered 18/9, 2017 at 15:27 Comment(1)
Perfect thanks, that helps also in TYPO3 8.7.12 to remove the empty paragraphs. I used this for usage for Resource-Relation on Page-Properties without any RTE inside - just the Image-Description aka Caption.Fervency
T
0

I did some more research and stumbled across people running into the same problem. The div tags and the comments are the result of so-called "CSS Styled Content". This content is passed to the frontend using content < styles.content.get, which is—according to my Fluid templating tutorial–the common way to pass content from the RTE to the template.

One website described these as solution (or workaround):

# standard enclosure for header
lib.stdheader.10.1.fontTag = <h1>|</h1>    

# remove .csc-header
lib.stdheader.stdWrap.dataWrap >    

# plain headings
lib.stdheader.2.headerStyle >
lib.stdheader.3.headerClass >    

# (unknown, german version read "remove other stuff"
tt_content.stdWrap.dataWrap =    

# disable .bodytext in RTE paragraphs
lib.parseFunc_RTE.nonTypoTagStdWrap.encapsLines.addAttributes.P.class >    

# disable paragraph-enclosure for these tags
lib.parseFunc_RTE.nonTypoTagStdWrap.encapsLines.encapsTagList = cite, div, p, pre, hr, h1, h2, h3, h4, h5, h6,table,tr,td    

# remove paragraphs in tables
#lib.parseFunc_RTE.externalBlocks.table.stdWrap.HTMLparser.removeTags = p    

# allow classes in tables
lib.parseFunc_RTE.externalBlocks.table.stdWrap.HTMLparser.tags.table.fixAttrib.class.list >

Warning: I can not speak for the quality of this workaround. It did solve most problems (divs, comments and classes were removed), but the p tags remained.

Tao answered 8/1, 2014 at 17:20 Comment(2)
now, we know you work with fluid. If you would like to understand what happens, it can be helpfull to show the part of the HTML-Template and the according TypoScript.Myrtamyrtaceous
In my template I'm using a simple <f:format.html>{content}</f:format.html> and the TypoScript mentioned aboveTao
J
0

Can be corrected by removing linebreaks/spaces inside format.html tag

Incorrect:

<f:format.html>{data_item.tx_mask_content_rte} </f:format.html>

Correct <f:format.html>{data_item.tx_mask_content_rte}</f:format.html>

Same applies to <f:format.date>, where having linebreaks/spaces can lead to fatal errors.

Again poorly handled by fluid imho.

Hope it helps

Junina answered 4/1, 2018 at 9:1 Comment(1)
this is a correct answer... but also here 4 month agoFervency
I
0

I had this issue too, sometimes it helped to use this setup:

lib.parseFunc_RTE.nonTypoTagStdWrap.encapsLines>

But it cased that I wasn't able to use
in the tables. So I jump a little bit inside and found this possibility:

lib.parseFunc_RTE.nonTypoTagStdWrap.encapsLines.innerStdWrap_all.ifBlank =

Insipid answered 30/8, 2021 at 15:27 Comment(0)
T
-1

Here is what did the job for me, I added the following line to my setup.

config.disablePrefixComment = 1
Tao answered 22/12, 2013 at 14:9 Comment(1)
This is not a real solution for the problem. It just configures TYPO3 to not render the comments like "CONTENT ELEMENT". So maybe it looks OK for you, but there is still a configuration problem.Restful
F
-5

Please add this code above the end of body tag,

<script>
   var elems = document.getElementsByTagName('p');
   var elemsLenght = elems.length;
   for (var i = 0; i < elemsLenght; ++i) {
       if (elems[i].innerHTML == '' || elems[i].innerHTML == ' ' || >elems[i].innerHTML == '&nbsp;')
      { 
          elems[i].innerHTML="";
          elems[i].className="";
      }
    }
 </script>
Fivespot answered 19/12, 2013 at 6:44 Comment(1)
Not a clean solution. How if the user doesnt have javascript. I think you can get ride of the prob qith TYPO3Calyces

© 2022 - 2024 — McMap. All rights reserved.