|
435 | 435 | " <html>\n", |
436 | 436 | " <head>\n", |
437 | 437 | " <title>FastHTML page</title>\n", |
438 | | - " <link rel="canonical" href="https://testserver/_FIrFOM6hRHCEq0FrNABhvQ">\n", |
| 438 | + " <link rel="canonical" href="https://testserver/_NKnZ-GS6RtyPadI25_q7IA">\n", |
439 | 439 | " <meta charset="utf-8">\n", |
440 | 440 | " <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">\n", |
441 | 441 | "<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.js"></script><script src="https://cdn.jsdelivr.net/gh/answerdotai/fasthtml-js@1.0.12/fasthtml.js"></script><script src="https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js"></script><script src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/franken-ui@2.0.0/dist/css/core.min.css">\n", |
|
1275 | 1275 | " <html>\n", |
1276 | 1276 | " <head>\n", |
1277 | 1277 | " <title>FastHTML page</title>\n", |
1278 | | - " <link rel="canonical" href="https://testserver/_FJsQQbXfR6qu_-71hvQJZA">\n", |
| 1278 | + " <link rel="canonical" href="https://testserver/_EB62jdyYTHSdQ_qkcuUWwQ">\n", |
1279 | 1279 | " <meta charset="utf-8">\n", |
1280 | 1280 | " <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">\n", |
1281 | 1281 | "<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.js"></script><script src="https://cdn.jsdelivr.net/gh/answerdotai/fasthtml-js@1.0.12/fasthtml.js"></script><script src="https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js"></script><script src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/franken-ui@2.0.0/dist/css/core.min.css">\n", |
|
1816 | 1816 | " <html>\n", |
1817 | 1817 | " <head>\n", |
1818 | 1818 | " <title>FastHTML page</title>\n", |
1819 | | - " <link rel="canonical" href="https://testserver/_UJcdoQ15T_6M0ot2y0os3w">\n", |
| 1819 | + " <link rel="canonical" href="https://testserver/_l_oTxiTjRc6kVpia161iFA">\n", |
1820 | 1820 | " <meta charset="utf-8">\n", |
1821 | 1821 | " <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">\n", |
1822 | 1822 | "<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.js"></script><script src="https://cdn.jsdelivr.net/gh/answerdotai/fasthtml-js@1.0.12/fasthtml.js"></script><script src="https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js"></script><script src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/franken-ui@2.0.0/dist/css/core.min.css">\n", |
|
2190 | 2190 | " <html>\n", |
2191 | 2191 | " <head>\n", |
2192 | 2192 | " <title>FastHTML page</title>\n", |
2193 | | - " <link rel="canonical" href="https://testserver/_mYITJQxrR3iCL3vRt3CHLQ">\n", |
| 2193 | + " <link rel="canonical" href="https://testserver/_GQ2tHsBpTLWB4G3vmOuXtA">\n", |
2194 | 2194 | " <meta charset="utf-8">\n", |
2195 | 2195 | " <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">\n", |
2196 | 2196 | "<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.js"></script><script src="https://cdn.jsdelivr.net/gh/answerdotai/fasthtml-js@1.0.12/fasthtml.js"></script><script src="https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js"></script><script src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/franken-ui@2.0.0/dist/css/core.min.css">\n", |
|
3379 | 3379 | " <html>\n", |
3380 | 3380 | " <head>\n", |
3381 | 3381 | " <title>FastHTML page</title>\n", |
3382 | | - " <link rel="canonical" href="https://testserver/_nHZV7WcbRSmArmvQPuNmMQ">\n", |
| 3382 | + " <link rel="canonical" href="https://testserver/_gMK1k5rZQEa-kanCWhz21A">\n", |
3383 | 3383 | " <meta charset="utf-8">\n", |
3384 | 3384 | " <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">\n", |
3385 | 3385 | "<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.js"></script><script src="https://cdn.jsdelivr.net/gh/answerdotai/fasthtml-js@1.0.12/fasthtml.js"></script><script src="https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js"></script><script src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/franken-ui@2.0.0/dist/css/core.min.css">\n", |
|
3646 | 3646 | { |
3647 | 3647 | "cell_type": "code", |
3648 | 3648 | "execution_count": null, |
3649 | | - "id": "b31876df", |
| 3649 | + "id": "1213ae59", |
3650 | 3650 | "metadata": {}, |
3651 | 3651 | "outputs": [], |
3652 | 3652 | "source": [ |
3653 | 3653 | "#| export\n", |
| 3654 | + "from bs4 import BeautifulSoup" |
| 3655 | + ] |
| 3656 | + }, |
| 3657 | + { |
| 3658 | + "cell_type": "code", |
| 3659 | + "execution_count": null, |
| 3660 | + "id": "cc4d2c00", |
| 3661 | + "metadata": {}, |
| 3662 | + "outputs": [], |
| 3663 | + "source": [ |
| 3664 | + "#| export\n", |
| 3665 | + "def normalize_html(s): return BeautifulSoup(s, 'lxml').body.decode_contents(formatter='html')\n", |
| 3666 | + "\n", |
3654 | 3667 | "def render_md(md_content:str, # Markdown content\n", |
3655 | 3668 | " class_map=None, # Class map\n", |
3656 | 3669 | " class_map_mods=None, # Additional class map\n", |
|
3662 | 3675 | " html_content = mistletoe.markdown(md_content, partial(renderer, img_dir=img_dir))\n", |
3663 | 3676 | " if (class_map or class_map is None) or class_map_mods:\n", |
3664 | 3677 | " html_content = apply_classes(html_content, class_map, class_map_mods)\n", |
| 3678 | + " else: html_content = normalize_html(html_content)\n", |
3665 | 3679 | " return NotStr(html_content)" |
3666 | 3680 | ] |
3667 | 3681 | }, |
| 3682 | + { |
| 3683 | + "cell_type": "code", |
| 3684 | + "execution_count": null, |
| 3685 | + "id": "cf157286", |
| 3686 | + "metadata": {}, |
| 3687 | + "outputs": [ |
| 3688 | + { |
| 3689 | + "name": "stdout", |
| 3690 | + "output_type": "stream", |
| 3691 | + "text": [ |
| 3692 | + "<p>This is a </p><div> in <code>my</code> content\n", |
| 3693 | + "</div>\n" |
| 3694 | + ] |
| 3695 | + } |
| 3696 | + ], |
| 3697 | + "source": [ |
| 3698 | + "print(render_md('This is a <div> in `my` content', class_map={}))" |
| 3699 | + ] |
| 3700 | + }, |
3668 | 3701 | { |
3669 | 3702 | "cell_type": "code", |
3670 | 3703 | "execution_count": null, |
|
4374 | 4407 | ] |
4375 | 4408 | } |
4376 | 4409 | ], |
4377 | | - "metadata": { |
4378 | | - "kernelspec": { |
4379 | | - "display_name": "python3", |
4380 | | - "language": "python", |
4381 | | - "name": "python3" |
4382 | | - } |
4383 | | - }, |
| 4410 | + "metadata": {}, |
4384 | 4411 | "nbformat": 4, |
4385 | 4412 | "nbformat_minor": 5 |
4386 | 4413 | } |
0 commit comments