Skip to content

Commit 96cd29d

Browse files
committed
Implement inline-block math parsing
1 parent c7ef123 commit 96cd29d

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

docstring_to_markdown/rst.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ def __init__(self, pattern: str, replacement: str, name: Union[str, None] = None
5050
),
5151
Directive(
5252
pattern=r':math:`(?P<latex>[^`]+?)`',
53-
# this will give $latex$, the second dollar is an escape character
5453
replacement=r'$\g<latex>$'
5554
),
55+
Directive(
56+
pattern=r'\.\. math:: (?P<latex>[^`]+?)(?P<end>$|\n)',
57+
replacement=r'$$\g<latex>$$\g<end>'
58+
),
5659
Directive(
5760
pattern=r'\.\. highlight:: (?P<language>.+)(?P<end>$|\n)',
5861
replacement=r'',

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ docstring-to-markdown = py.typed
3535
addopts =
3636
--pyargs tests
3737
--cov docstring_to_markdown
38-
--cov-fail-under=97
38+
--cov-fail-under=97.5
3939
--cov-report term-missing:skip-covered
4040
-p no:warnings
4141
--flake8

tests/test_rst.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,22 @@ def func(): pass
275275
which extends in the obvious way to higher dimensions, and the inverses
276276
"""
277277

278+
MATH_INLINE_BLOCK = """
279+
covariance matrix, `C`, is
280+
281+
.. math:: R_{ij} = \\frac{ C_{ij} } { \\sqrt{ C_{ii} * C_{jj} } }
282+
283+
The values of `R` are between -1 and 1, inclusive.
284+
"""
285+
286+
MATH_INLINE_BLOCK_MARKDOWN = """
287+
covariance matrix, `C`, is
288+
289+
$$R_{ij} = \\frac{ C_{ij} } { \\sqrt{ C_{ii} * C_{jj} } }$$
290+
291+
The values of `R` are between -1 and 1, inclusive.
292+
"""
293+
278294
KWARGS_PARAMETERS = """
279295
Parameters
280296
----------
@@ -451,6 +467,10 @@ def func(): pass
451467
'rst': RST_MATH_EXAMPLE,
452468
'md': RST_MATH_EXAMPLE_MARKDOWN
453469
},
470+
'converts inline-block math': {
471+
'rst': MATH_INLINE_BLOCK,
472+
'md': MATH_INLINE_BLOCK_MARKDOWN
473+
},
454474
'converts references': {
455475
'rst': RST_REF_EXAMPLE,
456476
'md': RST_REF_MARKDOWN
@@ -499,7 +519,7 @@ def func(): pass
499519
'rst': WARNING_BLOCK,
500520
'md': WARNING_BLOCK_MARKDOWN
501521
},
502-
'converts single-line warnings': {
522+
'converts inline-block warnings': {
503523
'rst': LINE_WARNING,
504524
'md': LINE_WARNING_MARKDOWN
505525
},

0 commit comments

Comments
 (0)