|
2 | 2 |
|
3 | 3 | # %% auto 0 |
4 | 4 | __all__ = ['Placements', 'empty', 'get_db', 'find_var', 'find_dialog_id', 'find_msgs', 'find_msg_id', 'read_msg_ids', 'msg_idx', |
5 | | - 'read_msg', 'del_msg', 'add_msg', 'update_msg', 'load_gist', 'gist_file', 'import_string', 'is_usable_tool', |
6 | | - 'mk_toollist', 'import_gist', 'export_dialog', 'import_dialog', 'tool_info', 'asdict'] |
| 5 | + 'read_msg', 'add_html', 'del_msg', 'add_msg', 'update_msg', 'load_gist', 'gist_file', 'import_string', |
| 6 | + 'is_usable_tool', 'mk_toollist', 'import_gist', 'export_dialog', 'import_dialog', 'tool_info', 'asdict'] |
7 | 7 |
|
8 | 8 | # %% ../nbs/00_core.ipynb |
9 | 9 | import json, importlib, linecache |
10 | 10 | from typing import Dict |
11 | 11 | from tempfile import TemporaryDirectory |
12 | 12 | from ipykernel_helper import * |
13 | 13 | from dataclasses import dataclass |
| 14 | +from fastcore.xml import to_xml |
14 | 15 |
|
15 | 16 | from fastcore.utils import * |
16 | 17 | from fastcore.meta import delegates |
@@ -98,6 +99,14 @@ def read_msg(n:int=-1, # Message index (if relative, +ve is downwards) |
98 | 99 | db = get_db() |
99 | 100 | return db.t.message.selectone('sid=?', [ids[idx]]) |
100 | 101 |
|
| 102 | +# %% ../nbs/00_core.ipynb |
| 103 | +def add_html( |
| 104 | + content:str, # The HTML to send to the client (generally should include hx-swap-oob) |
| 105 | +): |
| 106 | + "Send HTML to the browser to be swapped into the DOM" |
| 107 | + res = to_xml(content) |
| 108 | + xpost('http://localhost:5001/add_html_', data=dict(content=res)) |
| 109 | + |
101 | 110 | # %% ../nbs/00_core.ipynb |
102 | 111 | def del_msg( |
103 | 112 | sid:str=None, # sid (stable id -- pk) of message that placement is relative to (if None, uses current message) |
@@ -280,6 +289,7 @@ def import_dialog(fname, add_header=True): |
280 | 289 | def tool_info(): |
281 | 290 | cts='''Tools available from `dialoghelper`: |
282 | 291 |
|
| 292 | +- &`add_html`: Send HTML to the browser to be swapped into the DOM using hx-swap-oob. |
283 | 293 | - &`find_dialog_id`: Get the current dialog id. |
284 | 294 | - &`find_msg_id`: Get the current message id. |
285 | 295 | - &`find_msgs`: Find messages in current specific dialog that contain the given information. |
|
0 commit comments