def CookedBody(self, stx_level=None, setlevel=0): """\ 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' is 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 on the object. """ if (self.text_format == 'html' or self.text_format == 'plain' or (stx_level is None) or (stx_level == self._stx_level)): return self.cooked_text else: cooked = _format_stx(self.text, stx_level) if setlevel: self._stx_level = stx_level self.cooked_text = cooked return cooked
def CookedBody(self, stx_level=None, setlevel=0): """\ 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' is 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 on the object. """ if (self.text_format == 'html' or self.text_format == 'plain' or (stx_level is None) or (stx_level == self._stx_level)): return self.cooked_text else: cooked = _format_stx(self.text, stx_level) if setlevel: self._stx_level = stx_level self.cooked_text = cooked return cooked
def _edit(self, text, text_format='', safety_belt=''): """ Edit the Document - Parses headers and cooks the body""" headers = {} level = self._stx_level if not text_format: text_format = self.text_format if not safety_belt: safety_belt = headers.get('SafetyBelt', '') if not self._safety_belt_update(safety_belt=safety_belt): msg = ("Intervening changes from elsewhere detected." " Please refetch the document and reapply your changes." " (You may be able to recover your version using the" " browser 'back' button, but will have to apply them" " to a freshly fetched copy.)") raise 'EditingConflict', msg if text_format == 'html': self.text = self.cooked_text = text else: cooked = _format_stx(text=text, level=level) self.cooked_text = cooked self.text = text
def _edit(self, text, text_format='', safety_belt=''): """ Edit the Document - Parses headers and cooks the body""" headers = {} level = self._stx_level if not text_format: text_format = self.text_format if not safety_belt: safety_belt = headers.get('SafetyBelt', '') if not self._safety_belt_update(safety_belt=safety_belt): msg = ("Intervening changes from elsewhere detected." " Please refetch the document and reapply your changes." " (You may be able to recover your version using the" " browser 'back' button, but will have to apply them" " to a freshly fetched copy.)") raise 'EditingConflict', msg if text_format == 'html': self.text = self.cooked_text = text else: cooked = _format_stx(text=text, level=level) self.cooked_text = cooked self.text = text
def handleText(self, text, format=None): """ Handles the raw text, returning headers, body, cooked, format """ headers = {} body = cooked = text if not format: format = self.guessFormat(text) if format == 'html': parser = SimpleHTMLParser() parser.feed(text) headers.update(parser.metatags) if parser.title: headers['Title'] = parser.title bodyfound = bodyfinder.search(text) if bodyfound: cooked = body = bodyfound.group('bodycontent') else: headers, body = parseHeadersBody(text, headers) cooked = _format_stx(text=body) return headers, body, cooked, format
def handleText(self, text, format=None): """ Handles the raw text, returning headers, body, cooked, format """ headers = {} body = cooked = text if not format: format = self.guessFormat(text) if format == 'html': parser = SimpleHTMLParser() parser.feed(text) headers.update(parser.metatags) if parser.title: headers['Title'] = parser.title bodyfound = bodyfinder.search(text) if bodyfound: cooked = body = bodyfound.group('bodycontent') else: headers, body = parseHeadersBody(text, headers) cooked = _format_stx(text=body) return headers, body, cooked, format
def handleText(self, text, format=None, stx_level=None): """ Handles the raw text, returning headers, body, cooked, format """ headers = {} body = cooked = text level = stx_level or self._stx_level if not format: format = self.guessFormat(text) if format == 'html': parser = SimpleHTMLParser() parser.feed(text) headers.update(parser.metatags) if parser.title: headers['Title'] = parser.title bodyfound = bodyfinder(text) if bodyfound: cooked = body = bodyfound else: headers, body = parseHeadersBody(text, headers) cooked = _format_stx(text=body, level=level) self._stx_level = level return headers, body, cooked, format