|
21 | 21 | from ultimate_notion.blocks import BulletedItem as UnoBulletedItem |
22 | 22 | from ultimate_notion.blocks import Callout as UnoCallout |
23 | 23 | from ultimate_notion.blocks import Code as UnoCode |
| 24 | +from ultimate_notion.blocks import Equation as UnoEquation |
24 | 25 | from ultimate_notion.blocks import ( |
25 | 26 | Heading1 as UnoHeading1, |
26 | 27 | ) |
|
49 | 50 | from ultimate_notion.blocks import Video as UnoVideo |
50 | 51 | from ultimate_notion.file import ExternalFile |
51 | 52 | from ultimate_notion.obj_api.enums import BGColor, CodeLang, Color |
52 | | -from ultimate_notion.rich_text import Text, text |
| 53 | +from ultimate_notion.rich_text import Text, math, text |
53 | 54 |
|
54 | 55 |
|
55 | 56 | @beartype |
@@ -2823,3 +2824,61 @@ def setup(app): |
2823 | 2824 | tmp_path=tmp_path, |
2824 | 2825 | conf_py_content=conf_py_content, |
2825 | 2826 | ) |
| 2827 | + |
| 2828 | + |
| 2829 | +def test_inline_equation( |
| 2830 | + *, |
| 2831 | + make_app: Callable[..., SphinxTestApp], |
| 2832 | + tmp_path: Path, |
| 2833 | +) -> None: |
| 2834 | + """ |
| 2835 | + Inline equations become Notion math rich text. |
| 2836 | + """ |
| 2837 | + rst_content = """ |
| 2838 | + This is an inline equation :math:`E = mc^2` in a paragraph. |
| 2839 | + """ |
| 2840 | + |
| 2841 | + normal_text1 = text(text="This is an inline equation ") |
| 2842 | + equation_text = math(expression="E = mc^2") |
| 2843 | + normal_text2 = text(text=" in a paragraph.") |
| 2844 | + |
| 2845 | + combined_text = normal_text1 + equation_text + normal_text2 |
| 2846 | + |
| 2847 | + expected_paragraph = UnoParagraph(text=combined_text) |
| 2848 | + |
| 2849 | + expected_objects: list[Block] = [expected_paragraph] |
| 2850 | + |
| 2851 | + _assert_rst_converts_to_notion_objects( |
| 2852 | + rst_content=rst_content, |
| 2853 | + expected_objects=expected_objects, |
| 2854 | + make_app=make_app, |
| 2855 | + tmp_path=tmp_path, |
| 2856 | + extensions=("sphinx_notion", "sphinx.ext.mathjax"), |
| 2857 | + ) |
| 2858 | + |
| 2859 | + |
| 2860 | +def test_block_equation( |
| 2861 | + *, |
| 2862 | + make_app: Callable[..., SphinxTestApp], |
| 2863 | + tmp_path: Path, |
| 2864 | +) -> None: |
| 2865 | + """ |
| 2866 | + Block equations become Notion Equation blocks. |
| 2867 | + """ |
| 2868 | + rst_content = """ |
| 2869 | + .. math:: |
| 2870 | +
|
| 2871 | + E = mc^2 |
| 2872 | + """ |
| 2873 | + |
| 2874 | + expected_objects: list[Block] = [ |
| 2875 | + UnoEquation(latex="E = mc^2"), |
| 2876 | + ] |
| 2877 | + |
| 2878 | + _assert_rst_converts_to_notion_objects( |
| 2879 | + rst_content=rst_content, |
| 2880 | + expected_objects=expected_objects, |
| 2881 | + make_app=make_app, |
| 2882 | + tmp_path=tmp_path, |
| 2883 | + extensions=("sphinx_notion", "sphinx.ext.mathjax"), |
| 2884 | + ) |
0 commit comments