Generate PPTX slides and presentations from HTML markup.
Project description
Installing
pip install newsworthy_slides
Using
This library has one main function: slides_from_xml() which lets you generate and slides from a custom HTML structure (described below).
Basic usage:
from newsworthy_slides import slides_from_xml
slides_xml = """
<slide layout="Title and content">
<placeholder type="text">
Hello world!
</placeholder>
</slide>
"""
# Generate to new, empty presentation
pres = slides_from_xml(slides_xml)
# Generate to existing presentation
pres = slides_from_xml(slides_xml, "path/to/my_base_slides.pptx")
# pres is an instance of pptx.Presentation and can be saved easily:
pres.save('my_presentation.pptx')
The XML structure
Slides
A slide must always have a layout attribute referring to the name of a slide layout.
<slide layout="Title and content">
</slide>
A slide _may_ have position attribute which defines where in the presentation the slide is to be added.
A slide consists of a number of placeholders.
<slide layout="Title and content">
<placeholder type="text">
Hello world!
</placeholder>
</slide>
Each placeholder must have a type attribute, which can be either text, image, table. The type attribute defines how the content of the tag is to be interpreted.
The placeholders may also have a name attribute. This attribute should refer to a placeholder name in the slide layout.
<slide layout="Title and content">
<placeholder type="text" name="Text Placeholder 1">Hello</placeholder>
<placeholder type="text" name="Text Placeholder 2">World!</placeholder>
</slide>
If no placeholder name is defined the placeholders will be positioned in order.
<slide layout="Title and content">
<placeholder type="text">First placeholder</placeholder>
<placeholder type="text">Second placeholder</placeholder>
</slide>
The different placeholders types are defined below.
Text placeholders
Text placeholders may contain plain text or basic html. <p> and <li> tags are interpreted as paragraphs.
<placeholder type="text">
Hello world!
</placeholder>
<placeholder type="text">
<p>Hello Earth!</p>
<p>Hello Mars!</p>
</placeholder>
<placeholder type="text">
<li>Hello Earth!</li>
<li>Hello Mars!</li>
</placeholder>
<strong>, <i>/<em> and <a> tags may be used for inline formating and linking.
<placeholder type="text">
Hello <strong>world</strong>. Considering a <a href="http://outer.space">Mars</a>?
</placeholder>
Image placeholders
An image placeholder recognizes <img> tags and picks up the path (or url) to the image from the src attribute.
<placeholder type="image">
<img src="path/to/image.png">
</placeholder>
Note that the placeholder explicitly has to be a picture placeholder. This has to be set manually in Powerpoint. At the moment of writing Google Slides does not support picture placeholders (neither does Libre Office). A base presentation from Google Slides will not, in other words, be able to handle this image placeholders.
Table placeholders
A table placeholder should contain an html table. All <tr> tags are parsed as rows. <td> and <th> tags are parsed as cells. The cells may contain same basic text formatting as paragraphs (<strong> for bold, <i> for italic etc).
Cells with class=”value” are interpreted as numbers and right-aligned.
<thead> and <tbody> may be present, but does not bring any meaning. <caption> is _not_ parsed.
<placeholder type="table">
<table>
<tr>
<td>Country</td>
<td>Happiness</td>
</tr>
<tr>
<td>Finland</td>
<td class="value">9.5</td>
</tr>
<tr>
<td>Sweden</td>
<td class="value">8.5</td>
</tr>
</table>
</placeholder>
Developing
To run tests:
python3 -m pytest test
Deployment
To deploy a new version to PyPi:
Update Changelog below.
Update version.py
Build: python3 setup.py sdist bdist_wheel
Upload: python3 -m twine upload dist/newsworthy_slides-X.Y.X*
…assuming you have Twine installed (pip install twine) and configured.
Changelog
1.0.0 First version
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 Distributions
Built Distribution
Hashes for newsworthy_slides-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7e1698bd3837f822c9acb966eead78c54e8c9de0bfa4201e16e198e01d1c0d9 |
|
MD5 | 735025cfc188bbe0835eed6167c6dbe8 |
|
BLAKE2b-256 | b1455b5412165791b4323bdf1268ee423a121403fad289794eefa8f422035a8b |