From 2594b731c326d5b95629427f9970fa145e00650e Mon Sep 17 00:00:00 2001 From: Cris Luengo Date: Tue, 14 Jun 2022 17:30:30 -0600 Subject: [PATCH] Properly aligning inline equations on baseline, minor version bump. --- mdx_math_svg.py | 19 ++++++++++++++----- setup.cfg | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/mdx_math_svg.py b/mdx_math_svg.py index e1bc5d3..3e278be 100644 --- a/mdx_math_svg.py +++ b/mdx_math_svg.py @@ -22,7 +22,7 @@ ``` -Copyright 2021 by Cris Luengo +Copyright 2021-2022 by Cris Luengo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -161,7 +161,7 @@ def save_cache(file): """) # version ignored by all UAs, safe to drop https://stackoverflow.com/a/18468348 -_patch_dst = r""" +_patch_dst = r""" {formula} @@ -341,11 +341,20 @@ def latex2svg(self, latex): else: style = '' def repl(match): + width = float(match.group('width')) + height = float(match.group('height')) + viewBox = match.group('viewBox') + values = viewBox.split(' ') + if len(values) == 4: + offset = -(float(values[3]) + float(values[1])) / float(values[3]) * height + else: + offset = 0 return _patch_dst.format( - width=float(match.group('width')) * pt2em, - height=float(match.group('height')) * pt2em, + width=width * pt2em, + height=height * pt2em, + offset=offset * pt2em, style=style, - viewBox=match.group('viewBox'), + viewBox=viewBox, attribs='', formula=html.escape(latex)) # There are two incompatible preambles, if the first fails try the second diff --git a/setup.cfg b/setup.cfg index 32fb9e6..d7aaa6b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = mdx_math_svg -version = 1.2.0 +version = 1.2.1 description = SVG Math extension for Python-Markdown long_description = file: README.md long_description_content_type = text/markdown