Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for detail block #35

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.1
current_version = 0.4.0
commit = False
tag = False

Expand Down
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### Version 0.4.0 (2021-07-18)
* Add support for detail HTML block

### Version 0.3.1 (2021-07-13)
* Fix argparse for python3.10

Expand Down
21 changes: 21 additions & 0 deletions m2r2.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,21 @@ def block_html(self, html):

:param html: text content of the html snippet.
"""
details = re.search(
r"<details>\s*(<summary>[\s\S]*<\/summary>)([\S\s]*)<\/details>", html,
)
if details is not None:
summary, block = details.groups()
retstr = "\n\n.. raw:: html\n\n" + self._indent_block("<details>")
if summary != "":
retstr += summary
retstr += "\n\n"
retstr += "__reprocess_m2r_0__" + block + "__reprocess_m2r_1__"
retstr += (
"\n\n.. raw:: html\n\n" + self._indent_block("</details>") + "\n\n"
)
return retstr

return "\n\n.. raw:: html\n\n" + self._indent_block(html) + "\n\n"

def header(self, text, level, raw=None):
Expand Down Expand Up @@ -530,6 +545,12 @@ def __init__(

def parse(self, text):
output = super(M2R, self).parse(text)
if "__reprocess_m2r_0__" in output:
output = re.sub(
r"__reprocess_m2r_0__([\s\S]*)__reprocess_m2r_1__",
lambda g: self.parse(g.group(1)),
output,
)
return self.post_process(output)

def output_directive(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
readme = f.read()


__version__ = "0.3.1"
__version__ = "0.4.0"

install_requires = ["mistune", "docutils"]
test_requirements = ["pygments"]
Expand Down
14 changes: 14 additions & 0 deletions tests/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,17 @@ graph TD;
B-->D;
C-->D;
```

<h4>Some text before</h4>

<details><summary>Expand (CLICK ME)</summary>

Large Markdown formatted text:
- a1
- a2
- a3
- a4

</details>

Last bit of text.
28 changes: 28 additions & 0 deletions tests/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,31 @@ Also within parentheses (:math:`x^2`) and (:math:`z^3`).
A-->C;
B-->D;
C-->D;


.. raw:: html

<h4>Some text before</h4>



.. raw:: html

<details><summary>Expand (CLICK ME)</summary>


Large Markdown formatted text:


* a1
* a2
* a3
* a4


.. raw:: html

</details>


Last bit of text.