snip.snippets.link.LinkSnip¶
- class snip.snippets.link.LinkSnip(snip: S, href: str, **kwargs)¶
Test link snip.
Attributes
The identifier of the book the snippet belongs to
The deployment URL of the snippet
The bounding box of the snip.
The height of the snip.
icon_styleGet the inner snip.
The mirror of the snip.
Position of the snippet on a page.
The rotation of the snip.
Schema to validate the snippet.
The size of the snip.
The type identifier of the snippet e.g. 'text', 'image' etc.
The width of the snip.
The x-coordinate of the snip.
The y-coordinate of the snip.
sniphrefMethods
__init__(snip, href, **kwargs)Create a new snippet.
as_json([validate])Return the snippet as a dictionary in basic snippet json format.
preview([token])Generate a snippet preview.
upload([book_id, token, validate])Upload the snippet to the labbook.
- as_json(validate=True) dict¶
Return the snippet as a dictionary in basic snippet json format.
Returns a dict in the basic snippet structure.
{ "book_id": 123 "type": "text" "data": {} "view": {} }
If the schema is set in the class it is used to validate the snippet data before returning it.
- Parameters:
validate (bool, optional) – If True, the snippet is validated against the schema. Defaults to True.
- Raises:
jsonschema.ValidationError – If the snippet does not match the schema.
- property bounding_box¶
The bounding box of the snip.
Returns the bounding box of the nested snip.
- property height¶
The height of the snip.
Returns the height of the nested snip.
- property inner: S¶
Get the inner snip.
- property mirror¶
The mirror of the snip.
Returns the mirror of the nested snip.
- property pos: Tuple[float, float] | None¶
Position of the snippet on a page.
Returns none if the position is not set yet.
- preview(token: Token | None = None, **kwargs) Image | None¶
Generate a snippet preview.
This requests a server side rendering of the snippet and returns the preview image.
- Returns:
token (Token) – The token to use for the request. If None, the token gets inferred if possible.
**kwargs (Any) – Additional keyword arguments to pass to the requests function.
- property rotation¶
The rotation of the snip.
Returns the rotation of the nested snip.
- property schema: dict | None¶
Schema to validate the snippet.
The schema is used to validate the snippet and should be a valid
jsonschema.Draft202012Validatorschema.- Returns:
The schema for this snippet class if available. If none is available, None is returned and the schema functionality is disabled.
- Return type:
schema
- property size¶
The size of the snip.
Returns the size of the nested snip.
- upload(book_id: int | None = None, token: BookToken | None = None, validate=True, **kwargs)¶
Upload the snippet to the labbook.
This method uploads this snippet to a labbok given the snippets book_id and deployment url.
If no token is provided, the token is inferred from the book_id and deployment.
- Parameters:
book_id (int, optional) – The book_id of the snippet. Defaults to None. If None, the snippet book_id is derived
token (Token) – The token to use for the request. If None, the token gets inferred if possible.
validate (bool, optional) – Weather to validate the snippet before uploading. Defaults to True.
**kwargs (Any) – Additional keyword arguments to pass to the requests function.
- property width¶
The width of the snip.
Returns the width of the nested snip.
- property x¶
The x-coordinate of the snip.
Returns the x-coordinate of the nested snip.
- property y¶
The y-coordinate of the snip.
Returns the y-coordinate of the nested snip.