Replaces '\n' with ' ' for all strings in a collection.
(obj)
| 485 | |
| 486 | |
| 487 | def _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 | |
| 515 | def return_figure_from_figure_or_data(figure_or_data, validate_figure): |