diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-01-02 21:36:00 +0200 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-01-02 21:36:00 +0200 |
| commit | 89848de97da23a8c732f54bde15080b09e2bb9d9 (patch) | |
| tree | 8f257163125fbaff61fcc2f4565911acdbe4cf08 /htmtl/modifiers/truncate.py | |
| parent | 689fe2613765de71101214a482c928cfdb1b2be6 (diff) | |
bump
Diffstat (limited to 'htmtl/modifiers/truncate.py')
| -rw-r--r-- | htmtl/modifiers/truncate.py | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/htmtl/modifiers/truncate.py b/htmtl/modifiers/truncate.py index bac2862..85b1492 100644 --- a/htmtl/modifiers/truncate.py +++ b/htmtl/modifiers/truncate.py @@ -1,16 +1,11 @@ from typing import Any +from ..modifier import Modifier -from ..modifier import Modifier, modifier_name - -@modifier_name("truncate") class Truncate(Modifier): def modify(self, value: Any, opts: list[Any]) -> Any: - if isinstance(value, str) and len(opts) > 0: - if all([x in "1234567890" for x in opts[0]]): - char_limit = int(opts[0]) - - if len(value) > char_limit: - return f"{value[:char_limit - 3]}..." + if isinstance(value, str) and len(opts) > 0 and isinstance(opts[0], int): + if len(value) > opts[0]: + return f"{value[:opts[0] - 3]}..." return value |
