diff --git a/card.py b/card.py index 09984a8..7e9b6f4 100644 --- a/card.py +++ b/card.py @@ -19,12 +19,14 @@ def __init__( self.graphicShape = None self.graphicDimensions = None self.graphicTitle = None + self.printableFilename = None - self.videoInfo = None - self.videoDimensions = None - self.videoShape = None - + # Both audio and video + self.mediaInfo = None + self.mediaDimensions = None + self.mediaShape = None + self.mediaURL = None self.backgroundShape = None diff --git a/docs/user-guide.html b/docs/user-guide.html index 52a031b..d6f6ddb 100644 --- a/docs/user-guide.html +++ b/docs/user-guide.html @@ -1124,7 +1124,7 @@
CardGraphicPosition
, CardGraphicSize
, and CardGraphicPadding
.CardGraphicPosition
, CardGraphicSize
, and CardGraphicPadding
.Videos and audio files are supported in a similar way to graphics slides. However, there is no Markdown support for embedding videos or audio files. Fortunately, Markdown processors support HTML.
+You should be aware that, though you can legitimately embed a video or audio, Powerpoint might not be able to play it on all platforms.
md2pptx supports embedding videos using the HTML <video>
element.
(See Card Title Position for more information.)
You can suppress a title by coding its text value to
. If you do this for all the titles on a card slide the space reserved for card titles will be zero. If there are some titles not treated this way the
-titled cards will have a gap where the title would have been.
You can add a graphic or a video to a card. They can be placed in reserved areas before or after the card bulleted list contents.
-Place any graphic or video declaration between the card’s title and the card’s contents. For example:
+ +You can add a single graphic, video, or audio file to each card. They can be placed in reserved areas before or after the card bulleted list contents.
+Place any graphic, video, or audio declaration between the card’s title and the card’s contents. For example:
#### Card One
![](block.png)
@@ -2323,11 +2329,16 @@ Card Graphics & VideoAs you can see, the image reference is just a standard Markdown one. A video reference might be of the form:
<video height=300 width=400 src="waterdrop.mp4"></video>
+An audio reference might be of the form:
+<audio src="audiotest.mp3" poster="Battery W2M.png"></audio>
+
+In this case the poster
attribute is coded. This enables a graphic to be shown when the audio player isn’t activated. You can also code the poster
attribute for a video.
Notes:
- You must code a non-zero value for
CardGraphicSize
for graphics or videos to be shown. The default is 0.
- If a card doesn’t have a graphic or a video the bulleted list contents can fill the whole of the card (except for any title inside the card).
-- Card graphics can have tooltips and can be clickable. See Graphics Slides for how to code this.
+- Card graphics can have tooltips and can be clickable. See Graphics Slides for how to code this. (audio and video can’t.)
+- Media (audio or video) might not be playable on a specific platform, even though it has been legitimately embedded in a presentation.
Code Slides
diff --git a/docs/user-guide.log b/docs/user-guide.log
index 92fd6c8..df61afc 100644
--- a/docs/user-guide.log
+++ b/docs/user-guide.log
@@ -5,8 +5,8 @@ mdpre Markdown Preprocessor v0.6.7 (17 December, 2023)
Def mdpre_date = 17 December, 2023
Def mdpre_level = 0.6.7
Def userid = martinpacker
-Def time = 20:24
-Def date = 17 January, 2024
+Def time = 16:52
+Def date = 20 January, 2024
Def TOC = Table Of Contents
Def md = Markdown
Def pp = Powerpoint
@@ -44,7 +44,7 @@ CSV Stop
..... ..... ..... Multi-Column Table Cells
..... ..... Card Slides
..... ..... ..... Card Titles
-..... ..... ..... Card Graphics & Video
+..... ..... ..... Card Graphics, Video, & Audio
..... ..... Code Slides
..... ..... ..... ``
..... ..... ..... Triple Backticks (```)
diff --git a/docs/user-guide.md b/docs/user-guide.md
index 41753ab..8f91c0d 100644
--- a/docs/user-guide.md
+++ b/docs/user-guide.md
@@ -37,7 +37,7 @@ As you can see in the [change log](#change-log), md2pptx is frequently updated -
* [Multi-Column Table Cells](#multicolumn-table-cells)
* [Card Slides](#card-slides)
* [Card Titles](#card-titles)
- * [Card Graphics & Video](#card-graphics-&-video)
+ * [Card Graphics, Video, & Audio](#card-graphics-video-&-audio)
* [Code Slides](#code-slides)
* [``](#)
* [Triple Backticks (```)](#triple-backticks-())
@@ -348,9 +348,10 @@ To quote from the python-pptx license statement:
|Level|Date|What|
|:-|-:|:-|
-|4.3.2|17 January 2024|Cards can now have a video where a graphic might be.|
+|4.3.3|20 January 2024|Cards can now have audio where a graphic might be. Also media can have a "poster" image for when the media isn't playing. See [Card Graphics, Video, & Audio](#card-graphics-video-audio).|
+|4.3.2|17 January 2024|Cards can now have a video where a graphic might be. See [Card Graphics, Video, & Audio](#card-graphics-video-audio).|
|4.3.1|13 January 2024|Card graphics are now clickable and can have tooltips. They can also use `data:` URL's.|
-|4.3|3 January 2024|Added [card graphics](#card-graphics-&-video) support and [`CardGraphicPosition`](#card-graphic-positioning-cardgraphicposition), [`CardGraphicSize`](#card-graphic-size-cardgraphicsize), and [`CardGraphicPadding`](#card-graphic-padding-cardgraphicpadding).|
+|4.3|3 January 2024|Added [card graphics](#card-graphics-video-audio) support and [`CardGraphicPosition`](#card-graphic-positioning-cardgraphicposition), [`CardGraphicSize`](#card-graphic-size-cardgraphicsize), and [`CardGraphicPadding`](#card-graphic-padding-cardgraphicpadding).|
|4.2.1|28 December 2023|Made [`backgroundImage`](#specifying-slide-background-images-with-backgroundimage) create **real** slide backgrounds.|
|4.2|27 December 2023|Added background image support using [`backgroundImage`](#specifying-slide-background-images-with-backgroundimage).|
|4.1.2|11 July 2023|Fixed two bugs: Using `` & `` causes a crash. Also [Card Slides](#card-slides) cause a crash.|
@@ -670,6 +671,8 @@ You can optionally have md2pptx export the temporary PNG files. See [Exporting C
Videos and audio files are supported in a similar way to [graphics slides](#graphics-slides). However, there is no Markdown support for embedding videos or audio files. Fortunately, Markdown processors support HTML.
+You should be aware that, though you can legitimately embed a video or audio, Powerpoint might not be able to play it on all platforms.
+
##### Video Slides
@@ -927,12 +930,12 @@ In the above examples the card titles are above the cards. You can specify that
You can suppress a title by coding its text value to ` `. If you do this for all the titles on a card slide the space reserved for card titles will be zero. If there are some titles not treated this way the ` `-titled cards will have a gap where the title would have been.
-
-#### Card Graphics & Video
+
+#### Card Graphics, Video, & Audio
-You can add a graphic or a video to a card. They can be placed in reserved areas before or after the card bulleted list contents.
+You can add a single graphic, video, or audio file to each card. They can be placed in reserved areas before or after the card bulleted list contents.
-Place any graphic or video declaration between the card's title and the card's contents. For example:
+Place any graphic, video, or audio declaration between the card's title and the card's contents. For example:
#### Card One
@@ -945,11 +948,18 @@ As you can see, the image reference is just a standard Markdown one. A video ref
+An audio reference might be of the form:
+
+
+
+In this case the `poster` attribute is coded. This enables a graphic to be shown when the audio player isn't activated. You can also code the `poster` attribute for a video.
+
**Notes:**
1. You must code a non-zero value for [`CardGraphicSize`](#card-graphic-size-cardgraphicsize) for graphics or videos to be shown. The default is 0.
2. If a card doesn't have a graphic or a video the bulleted list contents can fill the whole of the card (except for any title inside the card).
-3. Card graphics can have tooltips and can be clickable. See [Graphics Slides](#graphics-slides) for how to code this.
+3. Card graphics can have tooltips and can be clickable. See [Graphics Slides](#graphics-slides) for how to code this. (audio and video can't.)
+4. Media (audio or video) might not be playable on a specific platform, even though it has been legitimately embedded in a presentation.
### Code Slides
diff --git a/docs/user-guide.mdp b/docs/user-guide.mdp
index a2511dd..ee9bdb1 100644
--- a/docs/user-guide.mdp
+++ b/docs/user-guide.mdp
@@ -154,9 +154,10 @@ To quote from the python-pptx license statement:
=colalign l r l
=csv
Level,Date,What
-4.3.2,17 January 2024,Cards can now have a video where a graphic might be.
+4.3.3,20 January 2024,Cards can now have audio where a graphic might be. Also media can have a "poster" image for when the media isn't playing. See [Card Graphics, Video, & Audio](#card-graphics-video-audio).
+4.3.2,17 January 2024,Cards can now have a video where a graphic might be. See [Card Graphics, Video, & Audio](#card-graphics-video-audio).
4.3.1,13 January 2024,Card graphics are now clickable and can have tooltips. They can also use `data:` URL's.
-4.3,3 January 2024,Added [card graphics](#card-graphics-&-video) support and [`CardGraphicPosition`](#card-graphic-positioning-cardgraphicposition), [`CardGraphicSize`](#card-graphic-size-cardgraphicsize), and [`CardGraphicPadding`](#card-graphic-padding-cardgraphicpadding).
+4.3,3 January 2024,Added [card graphics](#card-graphics-video-audio) support and [`CardGraphicPosition`](#card-graphic-positioning-cardgraphicposition), [`CardGraphicSize`](#card-graphic-size-cardgraphicsize), and [`CardGraphicPadding`](#card-graphic-padding-cardgraphicpadding).
4.2.1,28 December 2023,Made [`backgroundImage`](#specifying-slide-background-images-with-backgroundimage) create **real** slide backgrounds.
4.2,27 December 2023,Added background image support using [`backgroundImage`](#specifying-slide-background-images-with-backgroundimage).
4.1.2,11 July 2023,Fixed two bugs: Using `` & `` causes a crash. Also [Card Slides](#card-slides) cause a crash.
@@ -516,6 +517,8 @@ Videos and audio files are supported in a similar way to [graphics slides](#grap
However, there is no Markdown support for embedding videos or audio files. \
Fortunately, Markdown processors support HTML.
+You should be aware that, though you can legitimately embed a video or audio, Powerpoint might not be able to play it on all platforms.
+
##### Video Slides
@@ -809,13 +812,13 @@ You can suppress a title by coding its text value to ` `. \
If you do this for all the titles on a card slide the space reserved for card titles will be zero. \
If there are some titles not treated this way the ` `-titled cards will have a gap where the title would have been.
-
-#### Card Graphics & Video
+
+#### Card Graphics, Video, & Audio
-You can add a graphic or a video to a card. \
+You can add a single graphic, video, or audio file to each card. \
They can be placed in reserved areas before or after the card bulleted list contents.
-Place any graphic or video declaration between the card's title and the card's contents. \
+Place any graphic, video, or audio declaration between the card's title and the card's contents. \
For example:
#### Card One
@@ -829,6 +832,14 @@ As you can see, the image reference is just a standard Markdown one. \
A video reference might be of the form:
+
+An audio reference might be of the form:
+
+
+
+In this case the `poster` attribute is coded. \
+This enables a graphic to be shown when the audio player isn't activated. \
+You can also code the `poster` attribute for a video.
**Notes:**
@@ -836,7 +847,9 @@ A video reference might be of the form:
The default is 0.
2. If a card doesn't have a graphic or a video the bulleted list contents can fill the whole of the card (except for any title inside the card).
3. Card graphics can have tooltips and can be clickable. \
-See [Graphics Slides](#graphics-slides) for how to code this.
+See [Graphics Slides](#graphics-slides) for how to code this. \
+(audio and video can't.)
+4. Media (audio or video) might not be playable on a specific platform, even though it has been legitimately embedded in a presentation.
### Code Slides
diff --git a/md2pptx b/md2pptx
index cea6f76..0c30064 100755
--- a/md2pptx
+++ b/md2pptx
@@ -19,7 +19,7 @@ from pptx import __version__ as pptx_version
from pptx.util import Inches, Pt
from pptx.dml.color import RGBColor, MSO_THEME_COLOR
from pptx.enum.text import MSO_AUTO_SIZE, PP_ALIGN
-from pptx.enum.shapes import PP_PLACEHOLDER
+from pptx.enum.shapes import PP_PLACEHOLDER, PP_MEDIA_TYPE
from pptx.enum.shapes import MSO_SHAPE, MSO_CONNECTOR
from pptx.enum.text import MSO_ANCHOR
from pptx.enum.action import PP_ACTION
@@ -80,8 +80,8 @@ except:
have_graphviz = False
-md2pptx_level = "4.3.2"
-md2pptx_date = "17 January, 2024"
+md2pptx_level = "4.3.3"
+md2pptx_date = "20 January, 2024"
namespaceURL = {
"mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
@@ -2859,13 +2859,13 @@ def createListBlock(slideInfo, slide, renderingRectangle):
card.titleShape = cardTitleShape
- if (cardGraphicFilename := card.graphic) != "":
+ if card.graphic != "":
# This card has a graphic so get its name
- card.graphicDimensions = getGraphicDimensions(cardGraphicFilename)
+ card.graphicDimensions = getGraphicDimensions(card.graphic)
# Create card graphic shape - to be resized later
card.graphicShape = slide.shapes.add_picture(
- cardGraphicFilename,
+ card.graphic,
Inches(0),
Inches(0),
)
@@ -2875,27 +2875,24 @@ def createListBlock(slideInfo, slide, renderingRectangle):
if (card.mediaURL is not None) | (card.graphicTitle is not None):
mediaURL = card.mediaURL
- if card.graphicTitle == None:
- graphicTitle = ""
- else:
- graphicTitle = card.graphicTitle
+ graphicTitle = "" if card.graphicTitle == None else card.graphicTitle
pictureInfos.append(
(card.graphicShape, mediaURL, graphicTitle)
)
- elif (cardVideoInfo := card.videoInfo) is not None:
+ elif card.mediaInfo is not None:
# This card has a video so get its dimensions etc
- card.videoDimensions = getVideoInfo(cardVideoInfo)
+ card.mediaDimensions = getVideoInfo(card.mediaInfo)
# Create card video shape - to be resized later
- card.videoShape = slide.shapes.add_movie(
- card.videoInfo.source,
+ card.mediaShape = slide.shapes.add_movie(
+ card.mediaInfo.source,
Inches(0),
Inches(0),
Inches(0),
Inches(0),
- None
+ card.mediaInfo.poster
)
reportGraphicFilenames(card.printableFilename)
@@ -2903,7 +2900,7 @@ def createListBlock(slideInfo, slide, renderingRectangle):
else:
# Some of this is probably not needed
card.graphicDimensions = None
- card.videoDimensions = None
+ card.mediaDimensions = None
# Clear text from cloned title and add in the title text
cardTitleShape.text_frame.paragraphs[0].text = ""
@@ -3016,14 +3013,14 @@ def createListBlock(slideInfo, slide, renderingRectangle):
cardTitleShape = card.titleShape
cardBodyShape = card.bodyShape
cardGraphicShape = card.graphicShape
- cardVideoShape = card.videoShape
+ cardMediaShape = card.mediaShape
# Get dimensions of any graphic
if cardGraphicShape is not None :
cardMediaNativeWidth, cardMediaNativeHeight = card.graphicDimensions
- elif cardVideoShape is not None:
- cardMediaNativeWidth, cardMediaNativeHeight, _, _ = card.videoDimensions
+ elif cardMediaShape is not None:
+ cardMediaNativeWidth, cardMediaNativeHeight, _, _ = card.mediaDimensions
else:
cardMediaNativeWidth, cardMediaNativeHeight = (0, 0)
@@ -3099,14 +3096,14 @@ def createListBlock(slideInfo, slide, renderingRectangle):
dividingLine.line.width = Pt(2.0)
# Position card body shape
- if (cardGraphicShape == None) & (cardVideoShape == None):
+ if (cardGraphicShape == None) & (cardMediaShape == None):
# No graphic on this card
cardBodyShape.top = card.bodyTop
cardBodyShape.height = cardBodyHeight
cardBodyShape.left = card.left
cardBodyShape.width = cardWidth
else:
- # Make room for graphic or video
+ # Make room for graphic, audio, or video
if cardGraphicPosition == "before":
# Graphic before
if cardLayout == "horizontal":
@@ -3135,7 +3132,7 @@ def createListBlock(slideInfo, slide, renderingRectangle):
else:
cardBodyShape.height = cardBodyHeight
- # Scale graphic or video
+ # Scale graphic, audio, or video
(cardMediaWidth, cardMediaHeight, scaledByHeight) = scalePicture(
cardGraphicSizeRaw,
cardGraphicSizeRaw,
@@ -3146,7 +3143,7 @@ def createListBlock(slideInfo, slide, renderingRectangle):
if cardGraphicShape is not None:
cardMediaShape = cardGraphicShape
else:
- cardMediaShape = cardVideoShape
+ cardMediaShape = cardMediaShape
# Vertically position graphic shape
if cardGraphicPosition == "before":
@@ -6616,13 +6613,21 @@ for lineNumber, line in enumerate(linesAfterConcatenation):
cards[-1].printableFilename,
_ ,
_ ,
- cards[-1].videoInfo,
+ cards[-1].mediaInfo,
_ ,
) = parseMedia(videoRegexMatch.group(0), 0)
else:
- # Might implement this later on
- print("Audio not supported")
+ audioRegexMatch = audioRegex.match(line)
+ (
+ _ ,
+ _ ,
+ cards[-1].printableFilename,
+ _ ,
+ _ ,
+ cards[-1].mediaInfo,
+ _ ,
+ ) = parseMedia(audioRegexMatch.group(0), 0)
else:
# Cell contains a non-clickable graphic