Skip to content

Commit cfe9a67

Browse files
committed
Add note block parser, fixes #1
1 parent 1fe2fe3 commit cfe9a67

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

docstring_to_markdown/rst.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,17 @@ def initiate_parsing(self, line: str, current_language: str):
281281
return IBlockBeginning(remainder='')
282282

283283

284+
class NoteBlockParser(IndentedBlockParser):
285+
enclosure = '\n---'
286+
287+
def can_parse(self, line: str):
288+
return line.strip() == '.. note::'
289+
290+
def initiate_parsing(self, line: str, current_language: str):
291+
self._start_block('\n**Note**\n')
292+
return IBlockBeginning(remainder='')
293+
294+
284295
class ExplicitCodeBlockParser(IndentedBlockParser):
285296
def can_parse(self, line: str) -> bool:
286297
return re.match(CODE_BLOCK_PATTERN, line) is not None
@@ -293,6 +304,7 @@ def initiate_parsing(self, line: str, current_language: str) -> IBlockBeginning:
293304

294305
BLOCK_PARSERS = [
295306
PythonPromptCodeBlockParser(),
307+
NoteBlockParser(),
296308
MathBlockParser(),
297309
ExplicitCodeBlockParser(),
298310
DoubleColonBlockParser()

setup.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ python_requires = >=3.6
2525

2626
[tool:pytest]
2727
addopts =
28-
--pyargs docstring_to_markdown
28+
--pyargs tests
2929
--cov docstring_to_markdown
30-
--cov-fail-under=40
30+
--cov-fail-under=92
3131
--cov-report term-missing:skip-covered
3232
-p no:warnings
3333
--flake8
34+
-vv
3435

3536
[flake8]
3637
max-line-length = 120

tests/test_rst.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
RST_LINK_EXAMPLE = """To learn more about the frequency strings, please see `this link
7373
<https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`__."""
7474
RST_LINK_EXAMPLE_MARKDOWN = (
75-
"To learn more about the frequency strings, please see"
75+
"To learn more about the frequency strings, please see "
7676
"[this link](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases)."
7777
)
7878
RST_REF_EXAMPLE = """See :ref:`here <timeseries.offset_aliases>` for a list of frequency aliases."""
@@ -225,6 +225,31 @@ def func(): pass
225225
```
226226
"""
227227

228+
NUMPY_NOTE = """
229+
operations and methods.
230+
231+
.. note::
232+
The `chararray` class exists for backwards compatibility with
233+
Numarray, it is not recommended for new development.
234+
235+
Some methods will only be available if the corresponding string method is
236+
"""
237+
238+
NUMPY_NOTE_MARKDOWN = """
239+
operations and methods.
240+
241+
242+
---
243+
**Note**
244+
245+
The `chararray` class exists for backwards compatibility with
246+
Numarray, it is not recommended for new development.
247+
248+
---
249+
250+
Some methods will only be available if the corresponding string method is
251+
"""
252+
228253
RST_MATH_EXAMPLE = """
229254
In two dimensions, the DFT is defined as
230255
@@ -341,5 +366,7 @@ def test_rst_to_markdown_prompt_continuation():
341366
assert (
342367
rst_to_markdown('Discrete Fourier Transform (:mod:`numpy.fft`)') == 'Discrete Fourier Transform (`numpy.fft`)'
343368
)
369+
370+
assert rst_to_markdown(NUMPY_NOTE) == NUMPY_NOTE_MARKDOWN
344371

345372

0 commit comments

Comments
 (0)