Skip to main content

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.

Instead of name, a placeholder may be selected by its numeric index in the layout with idx (e.g. <placeholder idx="13" type="text">). Add the attribute remove (<placeholder idx="13" remove></placeholder>) to delete the placeholder from the slide.

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" auto-size="text-to-fit-shape">
  <li>Hello Earth!</li>
  <li>Hello Mars!</li>
  <li>Hello Jupiter!</li>
  <li>Hello Saturn!</li>
  <li>Hello Uranus!</li>
</placeholder>

<strong>, <i>/<em> and <a> tags may be used for inline formating and linking, and they may be nested (e.g. <strong>bold and <em>italic</em></strong>). A <span style="color:#c62828"> colors the text with the given hex color.

A <p> or <li> may have a one-based level attribute (<p level="2">) which sets the paragraph level (indentation) as defined in the base presentation.

The auto-size attribute may be set to autosize either the text (text-to-fit-shape) or the shape (shape-to-fit-text).

<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" vertical-alignment="top>
  <img src="path/to/image.png">
</placeholder>

Use attributes vertical-alignment (or va) and horizontal-alignment (or ha) for positioning.

Note that the placeholder explicitly has to be either a picture or an object 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).

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>

A table may also have a font-size attribute which sets the font size for the table, a row or a cell.

<placeholder type="table">
  <table font-size="10">
    <tr font-size="12">
      <td font-size="14">Country</td>
      <td>Happiness</td>
    </tr>
  </table>
</placeholder>

To specify the width of a column in a table, use the width attribute on the first row of the table. Width is specified in points (1pt = 1/72 inch).

<placeholder type="table">
  <table>
    <tr>
      <th scope="col" width="200">Kommun</th>
      <th scope="col" width="100">Placering i länet</th>
    </tr>
  </table>
</placeholder>

Notes

A slide may contain <notes> tag containing slide notes. The content will be parsed as text just as regular text placeholders.

<notes>
  <li>Here is an important thing to keep in mind!</<li>
</notes>

Presentation metadata

Presentation level metadata such as title, author and comments may be defined as attributes of a <presentation> tag. Available properties equals the core properties of the pptx library.

<presentation title="My Report" author="John Smith" created="2020-01-01">
</presentation>

Developing

To run tests:

python3 -m pytest test

Deployment

To deploy a new version to PyPi:

  1. Update Changelog below.

  2. Update version.py

  3. Build: python3 setup.py sdist bdist_wheel

  4. Upload: python3 -m twine upload dist/newsworthy_slides-X.Y.X*

…assuming you have Twine installed (pip install twine) and configured.

Changelog

  • 1.9.0

    • New feature: Select placeholders by idx and remove them with remove

    • New feature: Nested inline formatting, paragraph level and span colors

  • 1.8.0

    • New feature: Table column width

  • 1.7.0

    • New feature: Table font size

  • 1.6.0

    • New feature: Notes

  • 1.5.0

    • Enable alignment of images.

  • 1.4.0

    • Enable autosizing of text.

  • 1.3.0

    • Enable insertion of image to general purpose object placeholders.

  • 1.2.0

    • Adds ability to parse presentation level metadata.

  • 1.1.1

    • Bug fix: Handle negative rotation.

  • 1.1.0

    • Makes it possible to rotate images.

  • 1.0.2

    • Fixes ordering bug in table

  • 1.0.1

    • Add custom exception if image is missing

  • 1.0.0

    • First version

Metadata

Release files for newsworthy-slides 1.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for newsworthy-slides 1.9.0
File Size Uploaded Provenance
newsworthy_slides-1.9.0.tar.gz 20.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for newsworthy-slides 1.9.0
File Interpreter ABI Platform
newsworthy_slides-1.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.0 kB

Release files / newsworthy_slides-1.9.0.tar.gz

Download URL newsworthy_slides-1.9.0.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
90550da1610ed03d740a71701cca83ef0b3f93e0b988b50d35b509231056c7a5
BLAKE2b-256 checksum
How to use checksums
12d863ee687cf64c9e504073502129e701eb15cbba06517fbffe8b83955ac537
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.19

Release files / newsworthy_slides-1.9.0-py3-none-any.whl

Download URL newsworthy_slides-1.9.0-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76feb8eea464f99d52fb5c9f512a545bb11f1681e47c0d13c57608a109530d73
BLAKE2b-256 checksum
How to use checksums
a8d1c173b077362f46bd1826179d2d5f335e7faf47a30212e2f276849ac4f9d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.19

Security for newsworthy-slides 1.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page