def render_token( token:Token, # token to render config:TokenSelectorConfig, # config for this instance ids:TokenSelectorHtmlIds, # HTML IDs state:Optional=None, # current state for highlighting style_callback:Optional=None, # (TokenRenderContext) -> str for extra CSS read_only:bool=False, # disable interaction)->Any: # Span element for this token
Render a single interactive word token.
from cjm_fasthtml_token_selector.core.config import _reset_prefix_counter_reset_prefix_counter()cfg = TokenSelectorConfig(prefix="test")test_ids = TokenSelectorHtmlIds(prefix="test")t = Token("hello", 0)s = TokenSelectorState(anchor=0, focus=0, word_count=5)# Basic renderel = render_token(t, cfg, test_ids, s)assert el isnotNoneprint("render_token basic test passed!")# Read-only: no onclickel_ro = render_token(t, cfg, test_ids, s, read_only=True)assert el_ro isnotNoneprint("render_token read_only test passed!")
render_token basic test passed!
render_token read_only test passed!
End Token
render_end_token
def render_end_token( config:TokenSelectorConfig, # config for this instance ids:TokenSelectorHtmlIds, # HTML IDs state:Optional=None, # current state read_only:bool=False, # disable interaction)->Any: # end sentinel Span element
Render the end-of-text sentinel token.
_reset_prefix_counter()cfg = TokenSelectorConfig(prefix="test")test_ids = TokenSelectorHtmlIds(prefix="test")s = TokenSelectorState(anchor=5, focus=5, word_count=5)el = render_end_token(cfg, test_ids, s)assert el isnotNoneprint("render_end_token test passed!")
render_end_token test passed!
Token Grid
render_token_grid
def render_token_grid( tokens:List, # token list to render config:TokenSelectorConfig, # config for this instance ids:TokenSelectorHtmlIds, # HTML IDs state:Optional=None, # current state for highlighting style_callback:Optional=None, # (TokenRenderContext) -> str for extra CSS read_only:bool=False, # disable all interaction)->Any: # Div containing the complete token grid
render_token_grid test passed!
render_token_grid read_only test passed!
render_token_grid word mode test passed!
render_token_grid span mode test passed!