MCPcopy Create free account
hub / github.com/ipython/ipython / _mime_format

Method _mime_format

IPython/core/oinspect.py:515–550  ·  view source on GitHub ↗

Return a mime bundle representation of the input text. - if `formatter` is None, the returned mime bundle has a `text/plain` field, with the input text. a `text/html` field with a ` ` tag containing the input text. - if `formatter` is not None, it must be

(self, text:str, formatter=None)

Source from the content-addressed store, hash-verified

513
514
515 def _mime_format(self, text:str, formatter=None) -> dict:
516 """Return a mime bundle representation of the input text.
517
518 - if `formatter` is None, the returned mime bundle has
519 a `text/plain` field, with the input text.
520 a `text/html` field with a `<pre>` tag containing the input text.
521
522 - if `formatter` is not None, it must be a callable transforming the
523 input text into a mime bundle. Default values for `text/plain` and
524 `text/html` representations are the ones described above.
525
526 Note:
527
528 Formatters returning strings are supported but this behavior is deprecated.
529
530 """
531 defaults = {
532 'text/plain': text,
533 'text/html': '<pre>' + text + '</pre>'
534 }
535
536 if formatter is None:
537 return defaults
538 else:
539 formatted = formatter(text)
540
541 if not isinstance(formatted, dict):
542 # Handle the deprecated behavior of a formatter returning
543 # a string instead of a mime bundle.
544 return {
545 'text/plain': formatted,
546 'text/html': '<pre>' + formatted + '</pre>'
547 }
548
549 else:
550 return dict(defaults, **formatted)
551
552
553 def format_mime(self, bundle):

Callers 1

append_fieldMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected