mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(grade): add data attributes for footer attribution in widgets
This commit is contained in:
@@ -5,9 +5,23 @@ from ..themes import THEMES
|
||||
from ..utils import escape
|
||||
|
||||
|
||||
_ATTRIBUTION_RE = re.compile(
|
||||
r'<text\b[^>]*\bdata-gh-attribution="1"[^>]*>[^<]*</text>',
|
||||
re.DOTALL,
|
||||
)
|
||||
_ATTRIBUTION_H_RE = re.compile(r'\bdata-gh-h="(\d+)"')
|
||||
|
||||
|
||||
def _extract_inner(svg: str, widget_key: str) -> tuple[str, int]:
|
||||
"""Extract the inner content from a widget SVG and rewrite IDs to be unique.
|
||||
|
||||
Also strips any per-widget "Generated with gh-stats" attribution text
|
||||
(marked with data-gh-attribution="1") and shrinks the reported height
|
||||
by data-gh-h so the composite doesn't reserve empty space for the
|
||||
removed footer. The composite has its own attribution at the bottom
|
||||
of the whole card; per-widget attributions are for the standalone
|
||||
/api/<u>/<widget>.svg embed paths.
|
||||
|
||||
Returns (inner_svg_content, height).
|
||||
"""
|
||||
# Parse height
|
||||
@@ -31,6 +45,14 @@ def _extract_inner(svg: str, widget_key: str) -> tuple[str, int]:
|
||||
inner = re.sub(r'<svg[^>]*>', '', inner, count=1)
|
||||
inner = re.sub(r'</svg>\s*$', '', inner)
|
||||
|
||||
# Strip any embedded attribution and reclaim its reserved height.
|
||||
attr_match = _ATTRIBUTION_RE.search(inner)
|
||||
if attr_match:
|
||||
inner = inner.replace(attr_match.group(0), '', 1)
|
||||
h_match = _ATTRIBUTION_H_RE.search(attr_match.group(0))
|
||||
if h_match:
|
||||
h -= int(h_match.group(1))
|
||||
|
||||
return inner, h
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user