An HTML/XML generator
Project description
MarkupPy
This is MarkupPy - a Python module that attempts to make it easier to generate HTML/XML from a Python program in an intuitive, lightweight, customizable and pythonic way. It works with both python 2 and 3.
Installation:
pip install MarkupPy
Documentation and further info is at https://tylerbakke.github.io/MarkupPy/
Please send bug reports, feature requests, enhancement ideas or questions to tylerbakke@gmail.com.
The Python Package can be found at https://pypi.python.org/pypi/MarkupPy.
The code is in the public domain. Version: 1.17 as of March 12 2024.
Usage Examples
Basic Example
from MarkupPy import markup
# Create an HTML page
page = markup.page()
page.init(title="My Title")
page.p("Hello, World!")
page.p.close()
# Print the HTML
print(page)
Inline Styles and Scripts (v1.16+)
You can now add inline CSS and JavaScript directly in the init method:
page = markup.page()
page.init(
title="My Styled Page",
style_content="body { background-color: #f0f0f0; } h1 { color: blue; }",
script_content="function greet() { alert('Hello!'); }"
)
You can also pass multiple styles/scripts as a list:
page.init(
title="My Styled Page",
style_content=[
"body { background-color: #f0f0f0; }",
"h1 { color: blue; }"
],
script_content=[
"function greet() { alert('Hello!'); }",
"function goodbye() { alert('Goodbye!'); }"
]
)
Avoiding Extra Newlines in Pre Tags (v1.17+)
When adding content to <pre> elements, you might want to avoid extra newlines. The add_raw method helps with this:
page = markup.page()
page.init()
page.pre.open()
# Standard add method (inserts extra newlines between each addition)
page.add("Line 1")
page.add("Line 2") # This will create extra space between lines
# Better approach with add_raw (no extra newlines)
page.add_raw("Line 3\n")
page.add_raw("Line 4\n") # Only the explicit newlines are included
page.pre.close()
For pre-formatted text with tables or code samples, add_raw preserves the exact formatting you specify.
Running Tests
The package includes tests for all features. To run the tests:
# Navigate to the MarkupPy directory
cd MarkupPy
# Run all tests
python tests/run_tests.py
# Run specific test modules
python tests/test_inline_features.py
python tests/test_add_raw.py
The tests verify that:
- Inline styles and scripts work correctly in the
initmethod - The
add_rawmethod properly handles pre-formatted content without adding unwanted newlines
For Maintainers
Release Process
When publishing a new release to PyPI, follow these steps:
-
Update the version number in both:
MarkupPy/markup.py(update__version__and__date__)pyproject.toml(updateversionunder[project])
-
Add a Git tag for the release:
git tag -a v1.XX -m "Version 1.XX - Brief description of changes" git push origin v1.XX
-
Build and upload to PyPI:
python -m build python -m twine upload dist/markuppy-1.XX*
Tagging each PyPI release in the Git repository makes it easier to track releases and find specific versions of code.
Automated Release Process
The project uses GitHub Actions for automated releases. There are two ways to trigger a release:
Automatic Release on Version Bump
-
Update the version number in both:
MarkupPy/markup.py(update__version__and__date__)pyproject.toml(updateversionunder[project])
-
Commit and push the changes to GitHub:
git add MarkupPy/markup.py pyproject.toml git commit -m "Bump version to X.XX" git push origin main
The workflow will automatically:
- Detect the version change
- Verify that the version numbers match
- Create a Git tag
- Build the package
- Publish to PyPI using trusted publishing
Manual Release
If you need to run the release process manually:
- Go to the GitHub repository, click on "Actions" tab
- Select the "Build and Publish" workflow
- Click "Run workflow"
- Enter the version number (e.g., 1.18)
- Enable the "Create git tag" option if you want to automatically tag the release
- Click "Run workflow"
The workflow will perform the same steps as the automatic release process.
This automated process helps ensure consistency and reduces manual steps in the release process.
Project details
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 markuppy-1.18.tar.gz.
File metadata
- Download URL: markuppy-1.18.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
540f31b835076260339368890ac4f44eb3971d75fdbd97b49fa1f8b6685513d3
|
|
| MD5 |
ad078fc9263efced5ee743266a251588
|
|
| BLAKE2b-256 |
46122f2426faf45655dceacccf04a927a3d9f24e74fbccabbb39784034139dcc
|
Provenance
The following attestation bundles were made for markuppy-1.18.tar.gz:
Publisher:
publish.yml on tylerbakke/MarkupPy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
markuppy-1.18.tar.gz -
Subject digest:
540f31b835076260339368890ac4f44eb3971d75fdbd97b49fa1f8b6685513d3 - Sigstore transparency entry: 185121304
- Sigstore integration time:
-
Permalink:
tylerbakke/MarkupPy@7c8ab8c240e62bafdb250fa7a842c6e7e6c410ca -
Branch / Tag:
refs/tags/v1.18 - Owner: https://github.com/tylerbakke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7c8ab8c240e62bafdb250fa7a842c6e7e6c410ca -
Trigger Event:
push
-
Statement type:
File details
Details for the file markuppy-1.18-py3-none-any.whl.
File metadata
- Download URL: markuppy-1.18-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
788115ef3d529c2f8a298da4799f0838f57805a5e47068bcb9903092391466b3
|
|
| MD5 |
a532f990e624a0c5aabffe24cfcbeea7
|
|
| BLAKE2b-256 |
3a0615436a52f281ff43a9a54d1587b602536716645c8534fbb76c58b266f32b
|
Provenance
The following attestation bundles were made for markuppy-1.18-py3-none-any.whl:
Publisher:
publish.yml on tylerbakke/MarkupPy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
markuppy-1.18-py3-none-any.whl -
Subject digest:
788115ef3d529c2f8a298da4799f0838f57805a5e47068bcb9903092391466b3 - Sigstore transparency entry: 185121306
- Sigstore integration time:
-
Permalink:
tylerbakke/MarkupPy@7c8ab8c240e62bafdb250fa7a842c6e7e6c410ca -
Branch / Tag:
refs/tags/v1.18 - Owner: https://github.com/tylerbakke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7c8ab8c240e62bafdb250fa7a842c6e7e6c410ca -
Trigger Event:
push
-
Statement type: