From 5246fb85df9c49607254125c73718a2ca6673738 Mon Sep 17 00:00:00 2001 From: Vaughn Kottler Date: Wed, 20 Nov 2024 21:47:26 -0800 Subject: [PATCH] 0.7.3 - Add better preformatting support --- .github/workflows/python-package.yml | 2 +- .pylintrc | 4 ++-- README.md | 4 ++-- local/variables/package.yaml | 2 +- pyproject.toml | 2 +- svgen/__init__.py | 4 ++-- svgen/element/__init__.py | 13 ++++++++++--- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index f2a3800..699e65f 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -77,7 +77,7 @@ jobs: - run: | mk python-release owner=vkottler \ - repo=svgen version=0.7.2 + repo=svgen version=0.7.3 if: | matrix.python-version == '3.12' && matrix.system == 'ubuntu-latest' diff --git a/.pylintrc b/.pylintrc index 56b8036..5291dbb 100644 --- a/.pylintrc +++ b/.pylintrc @@ -5,5 +5,5 @@ good-names=p1,p2,x1,x2,y1,y2,rx,ry,cx,cy,dx,dy,x,y disable=too-few-public-methods [DESIGN] -max-args=7 -max-positional-arguments=7 +max-args=8 +max-positional-arguments=8 diff --git a/README.md b/README.md index 6fcfbea..e5df015 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ===================================== generator=datazen version=3.1.4 - hash=e3b8e71cf8f2ff14724ec99f593e1171 + hash=29bb10f1b4ff2e59a4494421f8b4e3bd ===================================== --> -# svgen ([0.7.2](https://pypi.org/project/svgen/)) +# svgen ([0.7.3](https://pypi.org/project/svgen/)) [![python](https://img.shields.io/pypi/pyversions/svgen.svg)](https://pypi.org/project/svgen/) ![Build Status](https://github.com/vkottler/svgen/workflows/Python%20Package/badge.svg) diff --git a/local/variables/package.yaml b/local/variables/package.yaml index d03912c..edc98ae 100644 --- a/local/variables/package.yaml +++ b/local/variables/package.yaml @@ -1,5 +1,5 @@ --- major: 0 minor: 7 -patch: 2 +patch: 3 entry: svgen diff --git a/pyproject.toml b/pyproject.toml index 2240de9..06609ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__" [project] name = "svgen" -version = "0.7.2" +version = "0.7.3" description = "A tool for working with scalable vector graphics." readme = "README.md" requires-python = ">=3.11" diff --git a/svgen/__init__.py b/svgen/__init__.py index bf69713..cfd6af0 100644 --- a/svgen/__init__.py +++ b/svgen/__init__.py @@ -1,7 +1,7 @@ # ===================================== # generator=datazen # version=3.1.4 -# hash=9f3cbbe5ddb5066e39497cc0121eade3 +# hash=4a9d6524eb23c9bce3184c85e0a13fc3 # ===================================== """ @@ -10,4 +10,4 @@ DESCRIPTION = "A tool for working with scalable vector graphics." PKG_NAME = "svgen" -VERSION = "0.7.2" +VERSION = "0.7.3" diff --git a/svgen/element/__init__.py b/svgen/element/__init__.py index 6fe1062..5bfd49c 100644 --- a/svgen/element/__init__.py +++ b/svgen/element/__init__.py @@ -32,6 +32,7 @@ def __init__( children: List["Element"] = None, allow_no_end_tag: bool = True, class_str: str = None, + preformatted: bool = False, **extra, ) -> None: """Construct a new SVG element.""" @@ -52,6 +53,8 @@ def __init__( self.attributes: Dict[str, Attribute] = {} self.booleans: set[str] = set() + self.preformatted = preformatted + for attr in attrib + attributes(extra): self.add_attribute(attr) @@ -124,14 +127,18 @@ def closing(self, indent: int = 0) -> str: if not self.text and not self.children: return " />" if self.allow_no_end_tag else ">" + close_tag - return (" " * (indent * INDENT)) + close_tag + return ( + close_tag + if self.preformatted + else (" " * (indent * INDENT)) + close_tag + ) def _write_text( self, output: TextIO, indent_str: str, newlines: bool = True ) -> None: """Write the inner-text section of this element.""" - if not newlines: + if not newlines or self.preformatted: output.write(self.text) return @@ -152,7 +159,7 @@ def encode( # Indent will matter if we want lines. indent_str = " " * (indent * INDENT) - if newlines: + if newlines and not self.preformatted: output.write(indent_str) attr_strs = [x.encode(quote) for x in self.attributes.values()] + list(