Skip to content

Commit

Permalink
v1.9.5 TopHeadingLevel
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPacker committed Mar 28, 2021
1 parent fdfd72a commit 6fd16c3
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 116 deletions.
162 changes: 65 additions & 97 deletions md2pptx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ except:
have_cairosvg = False

md2pptx_level = "1.9.5"
md2pptx_date = "26 March, 2021"
md2pptx_date = "28 March, 2021"


class slideInfo:
Expand Down Expand Up @@ -3034,6 +3034,11 @@ defaultVerticalCardGap = 0.15
verticalCardGap = defaultVerticalCardGap
presVerticalCardGap = defaultVerticalCardGap

titleLevel = 1
sectionLevel = 2
contentLevel = 3
cardLevel = 4

abstractTitle = ""

taskSlides = "all"
Expand Down Expand Up @@ -3315,6 +3320,12 @@ for line in metadata_lines:
codeColumns = int(value)
presCodeColumns = int(value)

elif name == "topheadinglevel":
titleLevel = int(value)
sectionLevel = titleLevel + 1
contentLevel = sectionLevel + 1
cardLevel = contentLevel + 1


if slideTemplateFile != "":
originalSlideTemplateFile = slideTemplateFile
Expand Down Expand Up @@ -3716,112 +3727,69 @@ for line in linesAfterConcatenation:
# Invalid dynamic metadata specification
print(f"Invalid dynamic metadata key: '{metadataKey}' in '{line}'")

elif line[:4] == "####":
# Heading Level 4 - card on an existing slide
inCard = True

# If there is an outstanding href then store it
if href != "":
slideHrefs[href] = slideNumber + 1

# Get card title text and any href
cardName, href = parseTitleText(line[4:])
if (href != "") & (href in slideHrefs.keys()):
print(f"Heading Reference redefined: '{href}' for slide {slideNumber}")

# Create information about a card_title
cardBullets = []
cards.append([cardName])

elif line[:3] == "###":
# Heading Level 3 - slide
if inBlock is True:
# Create the previous slide
SI = slideInfo(slideTitle, slideSubtitle, blockType, bullets, tableRows)
slideNumber, slide = createSlide(prs, slideNumber, SI)

if href != "":
slideHrefs[href] = slideNumber

# Get slide title text and any href
slideTitle, href = parseTitleText(line[3:])
if (href != "") & (href in slideHrefs.keys()):
print(f"Heading Reference redefined: '{href}' for slide {slideNumber}")

inBlock = True
blockType = "content"
slideSubtitle = ""
bullets = []
inList = False
inTable = False
inCard = False
cards = []

if (notes_text != "") & (slide != None):
notes_slide = slide.notes_slide
text_frame = notes_slide.notes_text_frame
text_frame.text = notes_text

notes_text = ""

elif line[:2] == "##":
# Heading Level 2 - section
if inBlock is True:
SI = slideInfo(slideTitle, slideSubtitle, blockType, bullets, tableRows)
slideNumber, slide = createSlide(prs, slideNumber, SI)
elif line.startswith("#"):
if line[:cardLevel] == "#" * cardLevel:
# Card on an existing slide
inCard = True

# If there is an outstanding href then store it
if href != "":
slideHrefs[href] = slideNumber

# Get slide title text and any href
slideTitle, href = parseTitleText(line[2:])
if (href != "") & (href in slideHrefs.keys()):
print(f"Heading Reference redefined: '{href}' for slide {slideNumber}")

inBlock = True
blockType = "section"
slideSubtitle = ""
bullets = []
inList = False
inTable = False
inCard = False
slideHrefs[href] = slideNumber + 1

if (notes_text != "") & (slide != None):
notes_slide = slide.notes_slide
text_frame = notes_slide.notes_text_frame
text_frame.text = notes_text
# Get card title text and any href
cardName, href = parseTitleText(line[cardLevel:])

notes_text = ""
# Create information about a card_title
cardBullets = []
cards.append([cardName])

elif line[:1] == "#":
# Heading Level 1 - slide title
if inBlock is True:
SI = slideInfo(slideTitle, slideSubtitle, blockType, bullets, tableRows)
slideNumber, slide = createSlide(prs, slideNumber, SI)
else:
# One of Content, Section, or Title slide
if inBlock is True:
# Create the previous slide
SI = slideInfo(slideTitle, slideSubtitle, blockType, bullets, tableRows)
slideNumber, slide = createSlide(prs, slideNumber, SI)

# Register the previous slide's href - if there was one
if href != "":
slideHrefs[href] = slideNumber

if line[:contentLevel] == "#" * contentLevel:
# Heading Level 3 - slide
thisLevel = contentLevel
blockType = "content"

elif line[:sectionLevel] == "#" * sectionLevel:
# Heading Level 2 - section
thisLevel = sectionLevel
blockType = "section"

elif line[:titleLevel] == "#" * titleLevel:
# Heading Level 1 - slide title
thisLevel = titleLevel
blockType = "title"

# Get slide title text and any href
slideTitle, href = parseTitleText(line[thisLevel:])

cards = []
inBlock = True
inList = False
inTable = False
inCard = False
notes_text = ""
slideSubtitle = ""
bullets = []

if href != "":
slideHrefs[href] = slideNumber
if (notes_text != "") & (slide != None):
notes_slide = slide.notes_slide
text_frame = notes_slide.notes_text_frame
text_frame.text = notes_text

# Get slide title text and any href
slideTitle, href = parseTitleText(line[1:])
# Check whether any heading reference is a duplicate
if (href != "") & (href in slideHrefs.keys()):
print(f"Heading Reference redefined: '{href}' for slide {slideNumber}")

inBlock = True
blockType = "title"
slideSubtitle = ""
bullets = []
inList = False
inTable = False
inCard = False

if (notes_text != "") & (slide != None):
notes_slide = slide.notes_slide
text_frame = notes_slide.notes_text_frame
text_frame.text = notes_text

notes_text = ""

elif (match := bulletRegex.match(line)) :
# Bulleted inList
bulletLine = match.group(3).lstrip()
Expand Down
88 changes: 76 additions & 12 deletions user-guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ <h3 id="table-of-contents">Table Of Contents<a class="headerlink" href="#table-o
<li><a href="#background-colour-codebackground">Background Colour - <code>CodeBackground</code></a></li>
</ul>
</li>
<li><a href="#slide-heading-levels-topheadinglevel">Slide Heading Levels - <code>TopHeadingLevel</code></a></li>
</ul>
</li>
<li><a href="#dynamic-metadata">Dynamic Metadata</a><ul>
Expand Down Expand Up @@ -1241,8 +1242,8 @@ <h2 id="change-log">Change Log<a class="headerlink" href="#change-log" title="Pe
<tbody>
<tr>
<td align="left">1.9.5</td>
<td align="right">26&nbsp;March&nbsp;2021</td>
<td align="left">Added <code>&amp;hellip;</code>. Allow specification of gaps between cards.</td>
<td align="right">28&nbsp;March&nbsp;2021</td>
<td align="left">Added <code>&amp;hellip;</code>. Allow specification of gaps between cards. Allow specification of heading level for title slide.</td>
</tr>
<tr>
<td align="left">1.9.4</td>
Expand Down Expand Up @@ -1485,11 +1486,13 @@ <h3 id="presentation-title-slides">Presentation Title Slides<a class="headerlink
<pre><code># This Is the Presentation Title Slide
</code></pre>
<p>If you type anything in subsequent lines - before a blank line - the text will appear as extra lines in the presentation title. You might use this, for example, to add the presentation authors&rsquo; details.</p>
<p>(You can adjust the Markdown heading level for this type of slide with <a href="#slide-heading-levels-topheadinglevel"><code>TopHeadingLevel</code></a>.)</p>
<h3 id="presentation-section-slides">Presentation Section Slides<a class="headerlink" href="#presentation-section-slides" title="Permanent link"></a></h3>
<p>You code a presentation section slide with a Markdown Heading Level 2:</p>
<pre><code>## This Is A Section
</code></pre>
<p>You can code multiple lines, as with <a href="#presentation-title-slides">Presentation Title slides</a>.</p>
<p>(You can adjust the Markdown heading level for this type of slide with <a href="#slide-heading-levels-topheadinglevel"><code>TopHeadingLevel</code></a>.)</p>
<h3 id="bullet-slides">Bullet Slides<a class="headerlink" href="#bullet-slides" title="Permanent link"></a></h3>
<p><a id="bullet-slides"></a></p>
<p>Bullet slides use Markdown bulleted lists, which can be nested. This example shows two levels of nesting.</p>
Expand Down Expand Up @@ -2490,6 +2493,67 @@ <h5 id="background-colour-codebackground">Background Colour - <code>CodeBackgrou
<pre><code>codeBackground: 000000
</code></pre>
<p>You can override this on a slide-by-slide basis with <a href="#dynamic-codebackground">Dynamic codeBackground</a>.</p>
<p><a id="slide-heading-levels-topheadinglevel"></a></p>
<h4 id="slide-heading-levels-topheadinglevel">Slide Heading Levels - <code>TopHeadingLevel</code><a class="headerlink" href="#slide-heading-levels-topheadinglevel" title="Permanent link"></a></h4>
<p>The usual heading levels for different types of slides are as follows:</p>
<table>
<thead>
<tr>
<th align="right">Level</th>
<th align="left">Slide type</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right">1</td>
<td align="left">Presentation title</td>
</tr>
<tr>
<td align="right">2</td>
<td align="left">Section title</td>
</tr>
<tr>
<td align="right">3</td>
<td align="left">Content</td>
</tr>
<tr>
<td align="right">4</td>
<td align="left">Card</td>
</tr>
</tbody>
</table>
<p>However, you might need to &ldquo;demote&rdquo; all these slide types to, say:</p>
<table>
<thead>
<tr>
<th align="right">Level</th>
<th align="left">Slide type</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right">2</td>
<td align="left">Presentation title</td>
</tr>
<tr>
<td align="right">3</td>
<td align="left">Section title</td>
</tr>
<tr>
<td align="right">4</td>
<td align="left">Content</td>
</tr>
<tr>
<td align="right">5</td>
<td align="left">Card</td>
</tr>
</tbody>
</table>
<p>This might be, for example, because the same Markdown is destined for a formal publication, where the top level heading is reserved for the publication&rsquo;s title. To achieve this demotion you only need to specify the top level in the slide hierarchy:</p>
<pre><code>TopHeadingLevel: 2
</code></pre>
<p>The other heading levels will be adjusted accordingly.</p>
<p><strong>Note:</strong> You obviously need to code the Title Slide at Heading Level 2, for example.</p>
<p><a id="dynamic-metadata"></a></p>
<h3 id="dynamic-metadata">Dynamic Metadata<a class="headerlink" href="#dynamic-metadata" title="Permanent link"></a></h3>
<p>md2pptx can alter some in-effect settings, starting at a particular slide. Straight after the heading code a special form of comment like so:</p>
Expand Down Expand Up @@ -2604,63 +2668,63 @@ <h3 id="slide-template-sequence">Slide Template Sequence<a class="headerlink" hr
<thead>
<tr>
<th align="left">Slide Type</th>
<th align="right">Origin</th>
<th align="left">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">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">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">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">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">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">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">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">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">Slide Layout 2</td>
<td align="left">ContentSlideLayout</td>
<td align="left">Bulleted List: Second Shape</td>
</tr>
Expand Down

0 comments on commit 6fd16c3

Please sign in to comment.