Keep whitespaces in RTE for pre and code tags

谁都会走 提交于 2019-12-08 04:55:21

问题


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.


回答1:


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
  }
}



回答2:


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



来源:https://stackoverflow.com/questions/13172051/keep-whitespaces-in-rte-for-pre-and-code-tags

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!