Skip to content

Commit

Permalink
v1.9 Flexibility in slide master slide selection
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPacker committed Feb 17, 2021
1 parent aa31475 commit 9971527
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 149 deletions.
67 changes: 44 additions & 23 deletions md2pptx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ try:
except:
have_cairosvg = False

md2pptx_level = "1.8.1"
md2pptx_date = "10 February, 2021"
md2pptx_level = "1.9"
md2pptx_date = "17 February, 2021"


class slideInfo:
Expand Down Expand Up @@ -399,6 +399,7 @@ def formatTitle(presentation, title, titleText):
title.text_frame.paragraphs[0].font.size = Pt(pageTitleSize)
title.text_frame.vertical_anchor = MSO_ANCHOR.TOP

# Return where the next shape below the title would be - vertically
return title.top + title.height + Inches(0.1)


Expand Down Expand Up @@ -974,9 +975,9 @@ def addFooter(presentation, slideNumber, slide):
shapes = slide.shapes
footer = shapes.add_textbox(
Inches(0.1),
presentation.slide_height - numbers_height,
presentation.slide_height - numbersHeight,
Inches(0.2),
numbers_height / 2,
numbersHeight / 2,
)
frame = footer.text_frame
p = frame.paragraphs[0]
Expand Down Expand Up @@ -1021,10 +1022,7 @@ def processingSummarySlide(presentation, metadata):

# Figure out table height
maxTableHeight = (
presentation.slide_height
- slideTitleBottom
- numbers_content_margin
- marginBase
presentation.slide_height - slideTitleBottom - numbersContentMargin - marginBase
)
tableHeight = min(maxTableHeight, Inches(0.25) * rows)

Expand Down Expand Up @@ -1328,7 +1326,7 @@ def createAbstractSlide(presentation, slideNumber, titleText, subtitleText, bull

def createContentSlide(presentation, slideNumber, titleText, subtitleText, bullets):
slide = presentation.slides.add_slide(
presentation.slide_layouts[createContentSlideLayout]
presentation.slide_layouts[contentSlideLayout]
)

shapes = slide.shapes
Expand Down Expand Up @@ -1641,10 +1639,7 @@ def createTOCSlide(presentation, slideNumber, titleText, subtitleText, bullets):

# Figure out TOC height
maxTOCHeight = (
presentation.slide_height
- slideTitleBottom
- numbers_content_margin
- marginBase
presentation.slide_height - slideTitleBottom - numbersContentMargin - marginBase
)

# Figure out table width
Expand Down Expand Up @@ -1984,7 +1979,7 @@ def createTableSlide(presentation, slideNumber, titleText, table):

# Figure out graphic height on slide
maxPicHeight = (
presentation.slide_height - slideTitleBottom - numbers_content_margin
presentation.slide_height - slideTitleBottom - numbersContentMargin
)

if gridRows == 2:
Expand Down Expand Up @@ -2037,6 +2032,7 @@ def createTableSlide(presentation, slideNumber, titleText, table):
topLeftPicY = (
slideTitleBottom + marginBase + (maxPicHeight - topLeftPicHeight) / 2
)

if gridRows == 2:
topLeftPicY -= Inches(0.2)

Expand Down Expand Up @@ -2306,7 +2302,7 @@ def createTableSlide(presentation, slideNumber, titleText, table):
maxTableHeight = (
presentation.slide_height
- slideTitleBottom
- numbers_content_margin
- numbersContentMargin
- marginBase
)
tableHeight = min(maxTableHeight, Inches(0.25) * rows)
Expand Down Expand Up @@ -2446,6 +2442,7 @@ def createSlide(presentation, slideNumber, SI):
)
elif SI.blockType == "code":
slide = createCodeSlide(presentation, slideNumber, SI.titleText, SI.bodyText)

elif SI.blockType == "table":
slide = createTableSlide(presentation, slideNumber, SI.titleText, SI.tableRows)

Expand Down Expand Up @@ -2690,10 +2687,10 @@ anchorRegex = re.compile("^<a id=[\"'](.+)[\"']></a>")
dynamicMetadataRegex = re.compile("^<!-- md2pptx: (.+): (.+) -->")


# Slide layout enumeration
# Default slide layout enumeration
titleSlideLayout = 0
sectionSlideLayout = 1
createContentSlideLayout = 2
contentSlideLayout = 2
titleOnlyLayout = 5
blankLayout = 6

Expand Down Expand Up @@ -2835,11 +2832,11 @@ marginBase = Inches(0.2)
tableMargin = Inches(0.2)

# Space to leave at bottom if numbers
numbers_height = Inches(0.4)
numbersHeight = Inches(0.4)

# If no numbers leave all the above height anyway
numbers_content_margin = numbers_height
numbers_headings_margin = numbers_content_margin
numbersContentMargin = numbersHeight
numbersHeadingsMargin = numbersContentMargin

# Background colour class correspondence
bgcolors = {}
Expand Down Expand Up @@ -2878,14 +2875,14 @@ for line in metadata_lines:
if value.lower() == "yes":
# Want slide numbers everywhere
want_numbers_headings = True
numbers_headings_margin = numbers_height
numbersHeadingsMargin = numbersHeight
want_numbers_content = True
numbers_content_margin = numbers_height
numbersContentMargin = numbersHeight
elif value.lower() == "content":
# Want slide numbers on content slides but not headings & sections
want_numbers_headings = False
want_numbers_content = True
numbers_content_margin = numbers_height
numbersContentMargin = numbersHeight
else:
# Don't want slide numbers - but they could still be added by slide master
# (Can code any other value, including 'no' or omit this metadata type)
Expand Down Expand Up @@ -3015,8 +3012,32 @@ for line in metadata_lines:

elif name == "taskslides":
taskSlides = value

elif name == "tasksperpage":
tasksPerPage = int(value)

elif name == "titleslidelayout":
titleSlideLayout = int(value)

elif name == "sectionslidelayout":
sectionSlideLayout = int(value)

elif name == "contentslidelayout":
contentSlideLayout = int(value)

elif name == "titleonlylayout":
titleOnlyLayout = int(value)

elif name == "blanklayout":
blankLayout = int(value)

elif name == "numbersheight":
numbersHeight = Inches(float(value))

# If no numbers leave all the above height anyway
numbersContentMargin = numbersHeight
numbersHeadingsMargin = numbersContentMargin

elif name == "glossarytitle":
glossaryTitle = value
elif name == "glossaryterm":
Expand Down
47 changes: 45 additions & 2 deletions user-guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,14 @@ <h3 id="table-of-contents">Table Of Contents<a class="headerlink" href="#table-o
<li><a href="#modifying-the-slide-template">Modifying The Slide Template</a><ul>
<li><a href="#basics">Basics</a></li>
<li><a href="#slide-template-sequence">Slide Template Sequence</a></li>
<li><a href="#template-slide-types">Template Slide Types</a><ul>
<li><a href="#title-slide-titleslidelayout">Title Slide - <code>TitleSlideLayout</code></a></li>
<li><a href="#section-slide-sectionslidelayout">Section Slide - <code>SectionSlideLayout</code></a></li>
<li><a href="#title-only-slide-titleonlylayout">Title Only Slide - <code>TitleOnlyLayout</code></a></li>
<li><a href="#blank-slide-blanklayout">Blank Slide - <code>BlankLayout</code></a></li>
<li><a href="#content-slide-contentslidelayout">Content Slide - <code>ContentSlideLayout</code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -1204,6 +1212,11 @@ <h2 id="change-log">Change Log<a class="headerlink" href="#change-log" title="Pe
</thead>
<tbody>
<tr>
<td align="left">1.9</td>
<td align="right">17&nbsp;February&nbsp;2021</td>
<td align="left">Add support to specify which slide in master. Also numbersMargin</td>
</tr>
<tr>
<td align="left">1.8.1</td>
<td align="right">10&nbsp;February&nbsp;2021</td>
<td align="left">Card options: Rounded versus square corners. Titles above or in cards</td>
Expand Down Expand Up @@ -2523,7 +2536,12 @@ <h2 id="modifying-the-slide-template">Modifying The Slide Template<a class="head
<p>This section is a basic introduction to the rules of the game for doing so.</p>
<h3 id="basics">Basics<a class="headerlink" href="#basics" title="Permanent link"></a></h3>
<p><a id="basics"></a></p>
<p>Don&rsquo;t change the order of the slides in the slide master view and don&rsquo;t delete any elements. It&rsquo;s probably also not useful to add elements. Take care with moving and resizing elements; It&rsquo;s probably best to experiment to see what effects you get.</p>
<p>It&rsquo;s best not to change the order of the slides in the slide master view and not to delete any elements. If you have a slide template presentation where the necessary slides are in the wrong order you can override where md2pptx picks its slides from. See the table below for metadata items to specify different template slides i.e override what md2pptx expects. Here&rsquo;s an example:</p>
<div class="codehilite"><pre>BlankLayout: 14
</pre></div>

<p>In this example, the slide in the template presentation to use for blank slides is number 14, with 0 being the first.</p>
<p>It&rsquo;s probably also not useful to add elements. Take care with moving and resizing elements; It&rsquo;s probably best to experiment to see what effects you get.</p>
<h3 id="slide-template-sequence">Slide Template Sequence<a class="headerlink" href="#slide-template-sequence" title="Permanent link"></a></h3>
<p><a id="slide-template-sequence"></a></p>
<p>The following table shows how each slide type is created.</p>
Expand All @@ -2532,53 +2550,63 @@ <h3 id="slide-template-sequence">Slide Template Sequence<a class="headerlink" hr
<tr>
<th align="left">Slide Type</th>
<th align="right">Origin</th>
<th align="left">Metadata<br/>Override</th>
<th align="left">Non-Title Content</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Processing Summary</td>
<td align="right">Original slide from Template</td>
<td align="left"></td>
<td align="left">Metadata: Second Shape</td>
</tr>
<tr>
<td align="left">Presentation Title</td>
<td align="right">Slide Layout 0</td>
<td align="left">TitleSlideLayout</td>
<td align="left">Subtitle: Second Shape</td>
</tr>
<tr>
<td align="left">Section</td>
<td align="right">Slide Layout 1</td>
<td align="left">SectionSlideLayout</td>
<td align="left">Subtitle: Second Shape</td>
</tr>
<tr>
<td align="left">Graphic With Title</td>
<td align="right">Slide Layout 5</td>
<td align="left">TitleOnlyLayout</td>
<td align="left">Graphic: New Shape</td>
</tr>
<tr>
<td align="left">Graphic Without Title</td>
<td align="right">Slide Layout 6</td>
<td align="left">BlankLayout</td>
<td align="left">Graphic: New Shape</td>
</tr>
<tr>
<td align="left">Code</td>
<td align="right">Slide Layout 5</td>
<td align="left">TitleOnlyLayout</td>
<td align="left">Code: New Shape</td>
</tr>
<tr>
<td align="left">Content</td>
<td align="right">Slide Layout 2</td>
<td align="left">ContentSlideLayout</td>
<td align="left">Bulleted List: Second Shape</td>
</tr>
<tr>
<td align="left">Table</td>
<td align="right">Slide Layout 5</td>
<td align="left">TitleOnlyLayout</td>
<td align="left">Table: New Shape</td>
</tr>
<tr>
<td align="left">Tasks</td>
<td align="right">Slide Layout 2</td>
<td align="left">ContentSlideLayout</td>
<td align="left">Bulleted List: Second Shape</td>
</tr>
</tbody>
Expand All @@ -2588,4 +2616,19 @@ <h3 id="slide-template-sequence">Slide Template Sequence<a class="headerlink" hr
<li>When looking for a title md2pptx looks first for a title shape and, failing that, uses the first shape. It&rsquo;s the Template Designer&rsquo;s responsibility to size and position it sensibly.</li>
<li>&ldquo;New Shape&rdquo; means md2pptx will create a new shape with, hopefully, sensible position and size.</li>
<li>With &ldquo;Second Shape&rdquo; it&rsquo;s the Template Designer&rsquo;s responsibility to size and position it sensibly.</li>
</ol></article></body></html>
</ol>
<h3 id="template-slide-types">Template Slide Types<a class="headerlink" href="#template-slide-types" title="Permanent link"></a></h3>
<p>The following sections give a brief description of each slide type md2pptx builds a presentation from. Your template presentation should have a slide of each type.</p>
<p>The title of each section includes the metadata override for that type of template slide.</p>
<h4 id="title-slide-titleslidelayout">Title Slide - <code>TitleSlideLayout</code><a class="headerlink" href="#title-slide-titleslidelayout" title="Permanent link"></a></h4>
<p>This is for the presentation&rsquo;s overall title. It probably has a title text line half way down the slide - though other designs are possible.</p>
<p>Generally you would use a Heading Level 1 (<code>#</code>) to create such a slide.</p>
<h4 id="section-slide-sectionslidelayout">Section Slide - <code>SectionSlideLayout</code><a class="headerlink" href="#section-slide-sectionslidelayout" title="Permanent link"></a></h4>
<p>This is for a section within the presentation - and is generally simpler than the presentation title slide. It probably has a title text line half way down the slide - though other designs are possible.</p>
<p>Generally you would use a Heading Level 2 (<code>##</code>) to create such a slide.</p>
<h4 id="title-only-slide-titleonlylayout">Title Only Slide - <code>TitleOnlyLayout</code><a class="headerlink" href="#title-only-slide-titleonlylayout" title="Permanent link"></a></h4>
<p>This is used where there will be some content below a title - and md2pptx doesn&rsquo;t use any content that might already be on the slide.</p>
<h4 id="blank-slide-blanklayout">Blank Slide - <code>BlankLayout</code><a class="headerlink" href="#blank-slide-blanklayout" title="Permanent link"></a></h4>
<p>This is where md2pptx wants to create a slide without using any content from the template slide.</p>
<h4 id="content-slide-contentslidelayout">Content Slide - <code>ContentSlideLayout</code><a class="headerlink" href="#content-slide-contentslidelayout" title="Permanent link"></a></h4>
<p>This is where md2pptx wants to reuse e.g. a text area. It is expected the template slide will have a title shape.</p></article></body></html>

0 comments on commit 9971527

Please sign in to comment.