Skip to content

Commit

Permalink
v4.0 Funnel
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPacker committed Apr 7, 2023
1 parent 8935743 commit 262a1f5
Show file tree
Hide file tree
Showing 7 changed files with 587 additions and 81 deletions.
19 changes: 17 additions & 2 deletions funnel.py
Expand Up @@ -13,6 +13,21 @@
from pptx.enum.text import PP_ALIGN
from pptx.dml.color import RGBColor, MSO_THEME_COLOR
from colour import setColour
from symbols import resolveSymbols

def massageFunnelText(text):
fragment = ""
for c in text:
if ord(c) == 236:
fragment = fragment + "<"

elif ord(c) == 237:
fragment = fragment + ">"

else:
fragment = fragment + c

return fragment

class Funnel:
def __init__(
Expand Down Expand Up @@ -87,7 +102,7 @@ def makeFunnel(
funnelLabelsRectangle.height,
)

tb.text = label.replace("<br/>","\n")
tb.text = massageFunnelText(resolveSymbols(label.replace("<br/>","\n")))
for p in tb.text_frame.paragraphs:
p.alignment = PP_ALIGN.CENTER
if funnelTitleColour != ("None", ""):
Expand Down Expand Up @@ -128,7 +143,7 @@ def makeFunnel(
)

s = ffBuilder.convert_to_shape()
s.text = body.replace("<br/>","\n")
s.text = massageFunnelText(resolveSymbols(body.replace("<br/>","\n")))

for p in s.text_frame.paragraphs:
p.alignment = PP_ALIGN.CENTER
Expand Down
84 changes: 14 additions & 70 deletions md2pptx
Expand Up @@ -41,7 +41,7 @@ import uuid
import funnel
from rectangle import Rectangle
from colour import *

from symbols import resolveSymbols

from lxml import etree
from lxml.html import fromstring
Expand Down Expand Up @@ -79,8 +79,8 @@ except:
have_graphviz = False


md2pptx_level = "3.7+"
md2pptx_date = "2 April, 2023"
md2pptx_level = "4.0"
md2pptx_date = "7 April, 2023"

namespaceURL = {
"mc" : "http://schemas.openxmlformats.org/markup-compatibility/2006",
Expand Down Expand Up @@ -342,72 +342,6 @@ def startswithOneOf(haystack, needleList):
def sortedNumericList(string):
return sorted(list(map(int, set(string.split()))))

# Resolve symbols and unescape any numeric character references
def resolveSymbols(text):
h = html.parser.HTMLParser()

textSplit = re.split("(&\#x?[0-9a-f]{2,6};)", text, flags=re.IGNORECASE)
text2 = ""
for t in textSplit:
if t == "":
text2 = text2 + t
elif (t[0:2] == "&#") & (t[-1] == ";"):
text2 = text2 + html.unescape(t)
else:
text2 = text2 + t

# Replace certain entity references with actual characters
text2 = text2.replace("&equals;", "=")
text2 = text2.replace("&lt;", chr(236))
text2 = text2.replace("&gt;", chr(237))
text2 = text2.replace("&le;", "≤")
text2 = text2.replace("&ge;", "≥")
text2 = text2.replace("&asymp;", "≈")
text2 = text2.replace("&Delta;", "Δ")
text2 = text2.replace("&delta;", "δ")
text2 = text2.replace("&sim;", "∼")
text2 = text2.replace("&nbsp;", chr(160))
text2 = text2.replace("&semi;", ";")
text2 = text2.replace("&colon;", ":")
text2 = text2.replace("&comma;", ",")
text2 = text2.replace("&amp;", "&")
text2 = text2.replace("&larr;", "←")
text2 = text2.replace("&rarr;", "→")
text2 = text2.replace("&uarr;", "↑")
text2 = text2.replace("&darr;", "↓")
text2 = text2.replace("&harr;", "↔")
text2 = text2.replace("&varr;", "↕")
text2 = text2.replace("&nwarr;", "↖")
text2 = text2.replace("&nearr;", "↗")
text2 = text2.replace("&swarr;", "↙")
text2 = text2.replace("&searr;", "↘")
text2 = text2.replace("&lsqb;", "\[")
text2 = text2.replace("&rsqb;", "\]")
text2 = text2.replace("&infin;", "∞")
text2 = text2.replace("&auml;", "ä")
text2 = text2.replace("&Auml;", "Ä")
text2 = text2.replace("&uuml;", "ü")
text2 = text2.replace("&Uuml;", "Ü")
text2 = text2.replace("&ouml;", "ö")
text2 = text2.replace("&Ouml;", "Ö")
text2 = text2.replace("&szlig;", "ß")
text2 = text2.replace("&euro;", "€")
text2 = text2.replace("&check;", "✓")
text2 = text2.replace("&hellip;", "…")
text2 = text2.replace("&times;", "×")
text2 = text2.replace("&percnt;", "%")
text2 = text2.replace("&divide;", "÷")
text2 = text2.replace("&forall;", "∀")
text2 = text2.replace("&exist;", "∃")
text2 = text2.replace("&lambda;", "λ")
text2 = text2.replace("&mu;", "μ")
text2 = text2.replace("&nu;", "ν")
text2 = text2.replace("&pi;", "π")
text2 = text2.replace("&rho;", "ρ")
text2 = text2.replace("&dash;", "-")

return text2

def substituteFooterVariables(footerText, liveFooters):
# Decide if the footer should be a live link to the section slide
wantLiveFooter = ((prs.lastSectionSlide is not None) & (footerText.find("<section") > -1) & (liveFooters == "yes"))
Expand Down Expand Up @@ -5760,6 +5694,9 @@ for lineNumber, line in enumerate(linesAfterConcatenation):

# Vertical card gap
"verticalcardgap",

# Funnel label percentage
"funnellabelspercent",

] :
processingOptions.dynamicallySetOption(
Expand Down Expand Up @@ -5862,13 +5799,20 @@ for lineNumber, line in enumerate(linesAfterConcatenation):
"cardColour", valueArray2, ""
)

elif metadataKey in ["funnelcolours", "funnelcolours"]:
elif metadataKey in ["funnelcolours", "funnelcolors"]:
valueArray2 = [parseColour(c.strip()) for c in metadataValue.split(",")]

processingOptions.dynamicallySetOption(
"funnelColours", valueArray2, ""
)

elif metadataKey in ["funneltitlecolour", "funnelbordercolour", "funneltextcolour"]:
# Funnel single colour options
processingOptions.dynamicallySetOption(
metadataKey, metadataValue, ""
)


# Note: Actual value handling prevents using dynamicallySetOption
elif metadataKey == "contentsplit":
# Proportions for each content element on a slide
Expand Down
70 changes: 70 additions & 0 deletions symbols.py
@@ -0,0 +1,70 @@
"""
symbols
"""
import re

# Resolve symbols and unescape any numeric character references
def resolveSymbols(text):
#h = html.parser.HTMLParser()

textSplit = re.split("(&\#x?[0-9a-f]{2,6};)", text, flags=re.IGNORECASE)
text2 = ""
for t in textSplit:
if t == "":
text2 = text2 + t
elif (t[0:2] == "&#") & (t[-1] == ";"):
text2 = text2 + html.unescape(t)
else:
text2 = text2 + t

# Replace certain entity references with actual characters
text2 = text2.replace("&equals;", "=")
text2 = text2.replace("&lt;", chr(236))
text2 = text2.replace("&gt;", chr(237))
text2 = text2.replace("&le;", "≤")
text2 = text2.replace("&ge;", "≥")
text2 = text2.replace("&asymp;", "≈")
text2 = text2.replace("&Delta;", "Δ")
text2 = text2.replace("&delta;", "δ")
text2 = text2.replace("&sim;", "∼")
text2 = text2.replace("&nbsp;", chr(160))
text2 = text2.replace("&semi;", ";")
text2 = text2.replace("&colon;", ":")
text2 = text2.replace("&comma;", ",")
text2 = text2.replace("&amp;", "&")
text2 = text2.replace("&larr;", "←")
text2 = text2.replace("&rarr;", "→")
text2 = text2.replace("&uarr;", "↑")
text2 = text2.replace("&darr;", "↓")
text2 = text2.replace("&harr;", "↔")
text2 = text2.replace("&varr;", "↕")
text2 = text2.replace("&nwarr;", "↖")
text2 = text2.replace("&nearr;", "↗")
text2 = text2.replace("&swarr;", "↙")
text2 = text2.replace("&searr;", "↘")
text2 = text2.replace("&lsqb;", "\[")
text2 = text2.replace("&rsqb;", "\]")
text2 = text2.replace("&infin;", "∞")
text2 = text2.replace("&auml;", "ä")
text2 = text2.replace("&Auml;", "Ä")
text2 = text2.replace("&uuml;", "ü")
text2 = text2.replace("&Uuml;", "Ü")
text2 = text2.replace("&ouml;", "ö")
text2 = text2.replace("&Ouml;", "Ö")
text2 = text2.replace("&szlig;", "ß")
text2 = text2.replace("&euro;", "€")
text2 = text2.replace("&check;", "✓")
text2 = text2.replace("&hellip;", "…")
text2 = text2.replace("&times;", "×")
text2 = text2.replace("&percnt;", "%")
text2 = text2.replace("&divide;", "÷")
text2 = text2.replace("&forall;", "∀")
text2 = text2.replace("&exist;", "∃")
text2 = text2.replace("&lambda;", "λ")
text2 = text2.replace("&mu;", "μ")
text2 = text2.replace("&nu;", "ν")
text2 = text2.replace("&pi;", "π")
text2 = text2.replace("&rho;", "ρ")
text2 = text2.replace("&dash;", "-")

return text2

0 comments on commit 262a1f5

Please sign in to comment.