From af2e508004bcf4401a40e1ce5d465292b054f011 Mon Sep 17 00:00:00 2001 From: Johan Hidding Date: Mon, 16 Sep 2024 16:34:57 +0200 Subject: [PATCH] add special `classes` attribute in the `quarto_attributes` hook --- README.md | 2 ++ entangled/hooks/quarto_attributes.py | 6 +++++- pyproject.toml | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 406f578..c65686d 100644 --- a/README.md +++ b/README.md @@ -271,6 +271,8 @@ if __name__ == "__main__": ``` ~~~ +The `id` attribute is reserved for the code's identifier (normally indicated with `#`) and the `classes` attribute can be used to indicate a list of classes in addition to the language class already given. + ## Brei Entangled has a small build engine (similar to GNU Make) embedded, called Brei. You may give it a list of tasks (specified in TOML) that may depend on one another. Brei will run these when dependencies are newer than the target. Execution is lazy and in parallel. Brei supports: diff --git a/entangled/hooks/quarto_attributes.py b/entangled/hooks/quarto_attributes.py index c7e28e4..fc7d056 100644 --- a/entangled/hooks/quarto_attributes.py +++ b/entangled/hooks/quarto_attributes.py @@ -3,7 +3,7 @@ from itertools import takewhile import yaml -from ..properties import Attribute, Id +from ..properties import Attribute, Class, Id from ..document import ReferenceId, ReferenceMap, CodeBlock from .base import HookBase from ..logging import logger @@ -37,6 +37,10 @@ def on_read(self, code: CodeBlock): if "id" in attrs: code.properties.append(Id(attrs["id"])) + + if "classes" in attrs: + code.properties.extend(Class(c) for c in attrs["classes"]) + code.properties.extend(Attribute(k, v) for k, v in attrs.items()) log.debug("quarto attributes: %s", attrs) diff --git a/pyproject.toml b/pyproject.toml index 7c0ee99..e1c997c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "entangled-cli" -version = "2.1.4" +version = "2.1.5" description = "Literate Programming toolbox" repository = "https://github.com/entangled/entangled.py" homepage = "https://entangled.github.io/"