MCPcopy Index your code
hub / github.com/plotly/plotly.py / _replace_newline

Function _replace_newline

plotly/tools.py:487–512  ·  view source on GitHub ↗

Replaces '\n' with ' ' for all strings in a collection.

(obj)

Source from the content-addressed store, hash-verified

485
486
487def _replace_newline(obj):
488 """Replaces '\n' with '<br>' for all strings in a collection."""
489 if isinstance(obj, dict):
490 d = dict()
491 for key, val in list(obj.items()):
492 d[key] = _replace_newline(val)
493 return d
494 elif isinstance(obj, list):
495 temp = list()
496 for index, entry in enumerate(obj):
497 temp += [_replace_newline(entry)]
498 return temp
499 elif isinstance(obj, str):
500 s = obj.replace("\n", "<br>")
501 if s != obj:
502 warnings.warn(
503 "Looks like you used a newline character: '\\n'.\n\n"
504 "Plotly uses a subset of HTML escape characters\n"
505 "to do things like newline (<br>), bold (<b></b>),\n"
506 "italics (<i></i>), etc. Your newline characters \n"
507 "have been converted to '<br>' so they will show \n"
508 "up right on your Plotly figure!"
509 )
510 return s
511 else:
512 return obj # we return the actual reference... but DON'T mutate.
513
514
515def return_figure_from_figure_or_data(figure_or_data, validate_figure):

Callers

nothing calls this directly

Calls 2

itemsMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected