mirror of
https://github.com/jongracecox/anybadge.git
synced 2025-07-21 12:21:03 +02:00
29
README.md
29
README.md
@@ -161,6 +161,35 @@ Available named colors are:
|
||||
| yellow | #DFB317 |  |
|
||||
| yellow_green | #A4A61D |  |
|
||||
|
||||
### Emojis
|
||||
|
||||
It is possible to use emoji characters in badge labels and values. Here are some examples:
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
These files were created by using the **actual** emoji character in the label/value text. For example:
|
||||
|
||||
```python
|
||||
badge = anybadge.Badge(label="Pipeline status", value="😄")
|
||||
```
|
||||
|
||||
There are some caveats worth mentioning:
|
||||
- The "look" of the emoji is determined by the client (Emoji characters are placed as-is into the SVG file, and are
|
||||
rendered client-side)
|
||||
- Rendering may fail in some viewers and developer IDEs (for example, PyCharm does not render emojis in the svg viewer)
|
||||
- Emojis can have different widths, so the layout may be affected. You can use `num_label_padding_chars` and
|
||||
`num_value_padding_chars` to fix (see below)
|
||||
|
||||
Here are some examples to show how to use padding to fix layout:
|
||||
|
||||
| Badge | Code |
|
||||
| ----- |----------------------------------------------------------------------|
|
||||
|  | `anybadge.Badge("Pipeline status", "😄")` |
|
||||
|  | `anybadge.Badge("Pipeline status", "😄", num_value_padding_chars=1)` |
|
||||
|
||||
### Semantic version support
|
||||
|
||||
Anybadge supports semantic versions for value and threshold keys. This supports color-coded
|
||||
|
@@ -1,7 +1,10 @@
|
||||
from pathlib import Path
|
||||
|
||||
import anybadge
|
||||
|
||||
|
||||
def main():
|
||||
def color_examples_table():
|
||||
"""Output the Markdown table containing color examples."""
|
||||
print(
|
||||
"""
|
||||
| Color Name | Hex | Example |
|
||||
@@ -21,5 +24,30 @@ def main():
|
||||
)
|
||||
|
||||
|
||||
def emoji_examples():
|
||||
"""Generate emoji example badges used in documentation."""
|
||||
examples_dir = Path(__file__).parent / Path("examples")
|
||||
for label, value, file, kwargs in [
|
||||
("Pipeline status", "😄", "pipeline_smile.svg", {}),
|
||||
(
|
||||
"Pipeline status",
|
||||
"😄",
|
||||
"pipeline_smile_padding.svg",
|
||||
{"num_value_padding_chars": 1},
|
||||
),
|
||||
("Pipeline status", "😟", "pipeline_frown.svg", {"default_color": "Red"}),
|
||||
("🔗", "Documentation", "documentation_link.svg", {}),
|
||||
("🔗", "PyPi", "pypi_link.svg", {}),
|
||||
]:
|
||||
anybadge.Badge(label=label, value=value, **kwargs).write_badge(
|
||||
examples_dir / Path(file), overwrite=True
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
color_examples_table()
|
||||
emoji_examples()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Reference in New Issue
Block a user