def CookedBody(self, stx_level=None, setlevel=0, rest_level=None): """ Get the "cooked" (ready for presentation) form of the text. The prepared basic rendering of an object. For Documents, this means pre-rendered structured text, or what was between the <BODY> tags of HTML. If the format is html, and 'stx_level' or 'rest_level' are not passed in or is the same as the object's current settings, return the cached cooked text. Otherwise, recook. If we recook and 'setlevel' is true, then set the recooked text and stx_level or rest_level on the object. """ if ((self.text_format == 'html' or self.text_format == 'plain' or (stx_level is None) or (stx_level == self._stx_level)) and ((rest_level is None) or (rest_level == self._rest_level))): return self.cooked_text elif rest_level is not None: cooked = ReST(self.text, initial_header_level=rest_level) if setlevel: self._rest_level = rest_level self.cooked_text = cooked return cooked else: cooked = stx2html(self.text, level=stx_level, header=0) if setlevel: self._stx_level = stx_level self.cooked_text = cooked return cooked
def _edit(self, text): """ Edit the Document and cook the body. """ self._size = len(text) text_format = self.text_format if not text_format: text_format = self.text_format if text_format != 'html': normalizer = queryUtility(ILinebreakNormalizer) if normalizer is not None: self.text = normalizer.normalizeIncoming(self, text) else: self.text = text else: self.text = text if text_format == 'html': self.cooked_text = text elif text_format == 'plain': self.cooked_text = html_quote(text).replace('\n', '<br />') elif text_format == 'restructured-text': self.cooked_text = ReST(text, initial_header_level=self._rest_level) else: self.cooked_text = stx2html(text, level=self._stx_level, header=0)