Skip to content

Commit

Permalink
Properly aligning inline equations on baseline, minor version bump.
Browse files Browse the repository at this point in the history
  • Loading branch information
crisluengo committed Jun 14, 2022
1 parent 75de2cf commit 2594b73
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions mdx_math_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -161,7 +161,7 @@ def save_cache(file):
""")

# version ignored by all UAs, safe to drop https://stackoverflow.com/a/18468348
_patch_dst = r"""<svg{attribs} style="width: {width:.3f}em; height: {height:.3f}em;{style}" viewBox="{viewBox}">
_patch_dst = r"""<svg{attribs} style="width: {width:.3f}em; height: {height:.3f}em; vertical-align: {offset:.3f}em; {style}" viewBox="{viewBox}">
<title>
{formula}
</title>
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2594b73

Please sign in to comment.