From 56031b8446982f1815c990b94ba05989bc2aec1a Mon Sep 17 00:00:00 2001 From: ChanTsune <41658782+ChanTsune@users.noreply.github.com> Date: Sat, 26 Sep 2020 22:31:48 +0900 Subject: [PATCH 1/2] Add suffix of id attribute in element of svg --- pybadges/__init__.py | 3 +++ pybadges/badge-template-full.svg | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pybadges/__init__.py b/pybadges/__init__.py index e3c6d61..8a62a83 100644 --- a/pybadges/__init__.py +++ b/pybadges/__init__.py @@ -126,6 +126,7 @@ def badge( whole_title: Optional[str] = None, left_title: Optional[str] = None, right_title: Optional[str] = None, + id_suffix: str = '', ) -> str: """Creates a github-style badge as an SVG image. @@ -173,6 +174,7 @@ def badge( right_title: The title attribute to associate with the right part of the badge. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/title. + id_suffix: The suffix of id attribute in element of svg. """ if measurer is None: measurer = ( @@ -200,6 +202,7 @@ def badge( whole_title=whole_title, left_title=left_title, right_title=right_title, + id_suffix=id_suffix, ) xml = minidom.parseString(svg) _remove_blanks(xml) diff --git a/pybadges/badge-template-full.svg b/pybadges/badge-template-full.svg index 2094fee..9b70728 100644 --- a/pybadges/badge-template-full.svg +++ b/pybadges/badge-template-full.svg @@ -2,20 +2,22 @@ {% set logo_padding = 3 if (logo and left_text) else 0 %} {% set left_width = left_text_width + 10 + logo_width + logo_padding %} {% set right_width = right_text_width + 10 %} +{% set id_smooth = 'smooth' + id_suffix %} +{% set id_round = 'round' + id_suffix %} {% if whole_title %} {{ whole_title }} {% endif %} - + - + - + {% if left_title %} {{ left_title }} @@ -26,7 +28,7 @@ {{ right_title }} {% endif %} - + From e246a513c79c06c6267a972df9b69ff20196b1f0 Mon Sep 17 00:00:00 2001 From: ChanTsune <41658782+ChanTsune@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:13:48 +0900 Subject: [PATCH 2/2] Update docstring --- pybadges/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pybadges/__init__.py b/pybadges/__init__.py index 8a62a83..589be6a 100644 --- a/pybadges/__init__.py +++ b/pybadges/__init__.py @@ -174,7 +174,9 @@ def badge( right_title: The title attribute to associate with the right part of the badge. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/title. - id_suffix: The suffix of id attribute in element of svg. + id_suffix: The suffix of the id attributes used in the SVG's elements. + Use to prevent duplicate ids if several badges are embedded on the + same page. """ if measurer is None: measurer = (