Keep whitespaces in RTE for pre and code tags

2019-05-29 19:35发布

I want to display code through <pre> and/or <code> tags, which works fine. White spaces are saved on first save and displayed properly in the front-end. However, when reloading the content in the backend, the editor shows the code without the additional whitespaces. Saving again drops the whole code formatting.

I assume there is some setting for this but I couldn't find anything until now. Any hints on this?

For the code highlighting, I am using the GeshiLib and vjrtecodesnippetsextensions.

Edit:

Sorry, missed the configuration. There is the basic rtehtmlarea involved, currently v4.7.5, there is no TCA specific change since it is a standard bodytext field from TYPO3's standard Text content element (displayed through css_styled_content).

PageTS for the RTE looks like the following:

RTE.default.hidePStyleItems := removeFromList(pre)
RTE.default.proc {
  allowTags := addToList(pre)
  entryHTMLparser_db.allowTags < RTE.default.proc.allowTags

  overruleMode = tx_vjrtecodesnippets,ts_css,cleanenc
  allowTags := addToList(code)
  allowTagsOutside := addToList(code)

  entryHTMLparser_db {
    allowTags < RTE.default.proc.allowTags
    allowTagsOutside < RTE.default.proc.allowTagsOutside
  }

  HTMLparser_rte {
    allowTags < RTE.default.proc.allowTags
    allowTagsOutside < RTE.default.proc.allowTagsOutside
  }
}

Edit2: We've published the TYPO3 extension news_blog which does exactly this.

标签: typo3 rte
2条回答
迷人小祖宗
2楼-- · 2019-05-29 19:40

this works on typo3 7.4

    RTE.default.proc {
    allowTags := addToList(pre)

    HTMLparser_rte {
        allowTags < RTE.default.proc.allowTags
    }

    entryHTMLparser_db {
        allowTags < RTE.default.proc.allowTags
    }
}

for sure you can also add more tag names seperated with " , "

for more settings to your RTE in typoscript check out. https://docs.typo3.org/typo3cms/CoreApiReference/6.2/Rte/Transformations/Tsconfig/Index.html

查看更多
Anthone
3楼-- · 2019-05-29 19:55

I wanted to write a comment, but a short answer with sophisticated guesses might be just as good:

  • I checked at my own site, the <code> tag works fine. Whitespaces are stored as &nbsp; in the bodytext field, therefore preserved when saved and re-opened.
  • Have you tried deleting the line
    RTE.default.hidePStyleItems := removeFromList(pre)?
  • According to the manual, only <code> tags are supported by vjrtecodesnippets. Do you really need both tags for syntax highlighting?
  • Also, have you tried changing your PageTS like follows to enable <pre>?:

-

RTE.default.proc {
  allowTagsOutside := addToList(code,pre)
}

EDIT:
I found a related TypoScript snippet, which might be noteworthy for your case. Please try making the following adjustments:

In the Template SETUP section:

lib.parseFunc.allowTags := addToList(code,pre)
lib.parseFunc_RTE.allowTags := addToList(code,pre)

In the PAGE TSconfig:

RTE.default.proc {
  allowTags := addToList(code,pre)
  allowTagsOutside := addToList(code,pre)
  overruleMode = tx_vjrtecodesnippets,ts_css,cleanenc

  // CONTENT TO DATABASE
  HTMLparser_rte {
    allowTags < RTE.default.proc.allowTags
    allowTagsOutside < RTE.default.proc.allowTagsOutside
  }

  // Entry HTML parser
  entryHTMLparser_db {
    allowTags < RTE.default.proc.allowTags
    allowTagsOutside < RTE.default.proc.allowTagsOutside
  }
}
查看更多
登录 后发表回答