mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-02 05:35:38 +00:00
Write RawBlock of markdown in code-cell output. #7561 makes the ipynb reader reads code-cell output with mime "text/markdown" to a RawBlock of markdown This commit makes the ipynb writer writes this RawBlock of markdown back inside a code-cell output with the same mime, preserving this information in round-trip Add tests of ipynb reader (#7561) and ipynb writer (#7563)'s ability to handle a "text/markdown" mime type in a code-cell output
4.1 KiB
4.1 KiB
In [1]:
from __future__ import annotations
from dataclasses import dataclassIn [2]:
import IPython
print(IPython.__version__)7.29.0
In [3]:
ip = get_ipython()
for mime in ip.display_formatter.formatters:
print(mime)text/plain text/html text/markdown image/svg+xml image/png application/pdf image/jpeg text/latex application/json application/javascript
In [4]:
@dataclass
class Mime:
math: str
def _repr_mimebundle_(
self,
include: Container[str] | None = None,
exclude: Container[str] | None = None,
**kwargs,
) -> dict[str, str]:
string = self.math
data = {
"text/plain": string,
"text/html": (latex := f"\\[{string}\\]"),
"text/markdown": f"$${string}$$",
# "image/svg+xml":,
# "image/png":,
# "application/pdf":,
# "image/jpeg":,
"text/latex": latex,
# "application/json":,
# "application/javascript":,
}
if include:
data = {k: v for k, v in data.items() if k in include}
if exclude:
data = {k: v for k, v in data.items() if k not in exclude}
return dataIn [5]:
mime = Mime("E = mc^2")In [6]:
mimeOut [6]:
\[E = mc^2\]