Last active
December 9, 2020 04:41
-
-
Save agyeiarcher/1d62485e891a32884fd38e534bab887e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# creates a Markdown table in Python using a designspace file, outlining instance names and corresponding axis values | |
import markdown | |
from fontTools.designspaceLib import DesignSpaceDocument | |
instanceNameString = "| Instance Name |" | |
filePath = "file_name_here.designspace" | |
def carpenter(designSpaceFile): | |
headerString = "" | |
columnSetup = "| :------- |" | |
tableString = "" | |
doc = DesignSpaceDocument() | |
doc.read(designSpaceFile) | |
doc.axes | |
doc.sources | |
doc.instances | |
for axisNames in doc.axes: | |
headerString+= " "+axisNames.name+" |" | |
tableHeading = instanceNameString+headerString | |
for additionalColumns in range(len(doc.axes)): | |
columnSetup += " -------: |" | |
for instances in doc.instances: | |
valueString = "| " | |
for axisLocationValue in instances.location.values(): | |
valueString+= str(axisLocationValue) + " |" | |
finalString = instances.styleName + "" + valueString +"\n" | |
tableString+= finalString | |
finalTable = tableHeading + "\n" + columnSetup + "\n" + tableString | |
return finalTable | |
instancesReport = markdown.markdown(carpenter(filePath), extensions=['tables']) | |
with open("testfile.md", "w", encoding="utf-8", errors="xmlcharrefreplace") as output_file: | |
output_file.write(instancesReport) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment