Generate a slug just like GitHub does for markdown headings. (JavaScript Port)
Project description
github-slugger
This is a Python Fork of the JavaScript
github-sluggerpackage
Generate a slug just like GitHub does for markdown headings. It also ensures slugs are unique in the same way GitHub does it. The overall goal of this package is to emulate the way GitHub handles generating markdown heading anchors as close as possible.
This project is not a markdown or HTML parser: passing alpha *bravo* charlie
or alpha <em>bravo</em> charlie doesn’t work.
Instead pass the plain text value of the heading: alpha bravo charlie.
Install
pip install github-slugger
Usage
from github_slugger import GithubSlugger
slugger = GithubSlugger()
slugger.slug('foo')
# returns 'foo'
slugger.slug('foo')
# returns 'foo-1'
slugger.slug('bar')
# returns 'bar'
slugger.slug('foo')
# returns 'foo-2'
slugger.slug('Привет non-latin 你好')
# returns 'привет-non-latin-你好'
slugger.slug('😄 emoji')
# returns '-emoji'
slugger.reset()
slugger.slug('foo')
# returns 'foo'
Check test/fixtures.json for more examples.
If you need, you can also use the underlying implementation which does not keep track of the previously slugged strings (not recommended):
from github_slugger import slug
slug('foo bar baz')
# returns 'foo-bar-baz'
slug('foo bar baz')
# returns the same slug 'foo-bar-baz' because it does not keep track
Contributing
Contributions welcome! Please read the contributing guidelines first.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file github-slugger-0.0.3.tar.gz.
File metadata
- Download URL: github-slugger-0.0.3.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e607450e8568c0c1b9a41f5748f422e5a22c1d9799d52bc6dd6575397c1ccb22
|
|
| MD5 |
64fa4563ea1ecc6132be20d181b0b776
|
|
| BLAKE2b-256 |
fee9c3fcf0d020dd1911c02f7c6b75e9ff809252c423dd4c3bcf8f1b0b86bf31
|
File details
Details for the file github_slugger-0.0.3-py3-none-any.whl.
File metadata
- Download URL: github_slugger-0.0.3-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d531ff0e439762900bf0ec3be10771b1d3635a6d4486113f1352fa19c091a91
|
|
| MD5 |
d419807df596f60eb24b3421079757e1
|
|
| BLAKE2b-256 |
31410cfe9970e00c3e9470a5ab559d27a5320695f553b7c240b3933ddf7e9825
|