I'm using the jinja2
templating engine to create both HTML emails and their plaintext alternative that I then send out using Sendgrid
. Unfortunately for my lazy self, this entails me writing and maintaining two separate templates with essentially the same content, the .html
file and the .txt
file. The .txt
file is identical to the HTML file other than containing no HTML tags.
Is there any way to simply have the HTML template and then somehow dynamically generate the txt
version, essentially just stripping the HTML tags? I know a regex could achieve this, but I also know that implementing a regex to deal with HTML tags is notoriously gotcha-ridden.