From daf5cfe989f1a6bac588c1dfe1f784c6bf3759ee Mon Sep 17 00:00:00 2001 From: Muspi Merol Date: Thu, 1 Aug 2024 18:14:19 +0800 Subject: [PATCH] support more markdown features (#19) * feat: support markdown tables * chore: update `README.md` * feat: support `blockquote` --------- Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- README.md | 12 +++++- package.json | 4 +- src/lib/components/markdown/Router.svelte | 16 ++++++-- src/lib/components/markdown/Table.svelte | 37 +++++++++++++++++++ .../components/reusable/WithMarkdown.svelte | 6 +-- src/lib/md.css | 24 ++++++++++++ 6 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 src/lib/components/markdown/Table.svelte diff --git a/README.md b/README.md index 5c198a2..33b4791 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,15 @@ With Pythonline, you can easily share your Python snippets with others, without >>> math.pi ``` -How about `math.e`? try hovering this! 👉 `math.pi / math.e` +If you hover over the code block above, you will see a button to run the code. +After that, you can inspect these values by hovering over them 👇 + +| Kind | Examples | +| -------------- | --------------------------------------------- | +| Global Names | `_`, `__name__`, `int`, `Exception` | +| Literal Values | `[{}]`, `1,2`, `1+2j`, `.0`, `0b10` | +| Expressions | `math.pi / 2` | +| Assignments | `one = -(math.e ** complex(0, math.pi)).real` | ## Main Features @@ -64,7 +72,7 @@ async def f(url): await gather(*(f(".") for _ in range(10))) ``` -This project is still work in progress for now, so feel free to [get in touch](https://github.com/promplate/pyth-on-line/discussions) if you have any feedback or suggestions! +> This project is still work in progress for now, so feel free to [get in touch](https://github.com/promplate/pyth-on-line/discussions) if you have any feedback or suggestions! ## Acknowledgements diff --git a/package.json b/package.json index 4a5b3ec..c0272cc 100644 --- a/package.json +++ b/package.json @@ -34,14 +34,14 @@ "paneforge": "^0.0.5", "pyodide": "0.26.2", "rehype-stringify": "^10.0.0", - "remark-parse": "^11.0.0", + "remark": "^15.0.1", + "remark-gfm": "^4.0.0", "remark-rehype": "^11.1.0", "rollup-plugin-flatten-dir": "^1.0.1", "shiki": "^1.12.0", "svelte": "^4.2.18", "svelte-portal": "^2.2.1", "svelte-sonner": "0.3.27", - "unified": "^11.0.5", "unocss": "^0.61.6", "vite": "^5.3.5" }, diff --git a/src/lib/components/markdown/Router.svelte b/src/lib/components/markdown/Router.svelte index ee6a127..b34c662 100644 --- a/src/lib/components/markdown/Router.svelte +++ b/src/lib/components/markdown/Router.svelte @@ -6,6 +6,7 @@ import InlineCode from "./InlineCode.svelte"; import Link from "./Link.svelte"; import Code from "./Pre.svelte"; + import Table from "./Table.svelte"; export let node: Node; @@ -13,7 +14,7 @@ export let codeProps: Record = {}; export let inlineCodeProps: Record = {}; - function getTagName(node: Node): string { + function getTagName(node: Node) { switch (node.type) { case "heading": return `h${(node as Heading).depth}`; @@ -33,9 +34,12 @@ case "paragraph": return "p"; + case "blockquote": + return "blockquote"; + default: console.error(node); - return "div"; + return null; } } @@ -65,7 +69,13 @@ {/each} -{:else if "children" in node} +{:else if node.type === "table"} + + + +
+ +{:else if "children" in node && getTagName(node)} {#each children as child} diff --git a/src/lib/components/markdown/Table.svelte b/src/lib/components/markdown/Table.svelte new file mode 100644 index 0000000..c89a9c7 --- /dev/null +++ b/src/lib/components/markdown/Table.svelte @@ -0,0 +1,37 @@ + + + + + + + {#each table.children[0].children as cell} + + {/each} + + + + + {#each table.children.slice(1) as row} + + {#each row.children as cell} + + {/each} + + {/each} + + +
+ {#each cell.children as child} + + {/each} +
+ {#each cell.children as child} + + {/each} +
diff --git a/src/lib/components/reusable/WithMarkdown.svelte b/src/lib/components/reusable/WithMarkdown.svelte index b49e3cf..2b66aa6 100644 --- a/src/lib/components/reusable/WithMarkdown.svelte +++ b/src/lib/components/reusable/WithMarkdown.svelte @@ -1,10 +1,10 @@ diff --git a/src/lib/md.css b/src/lib/md.css index 88acd85..71c74fd 100644 --- a/src/lib/md.css +++ b/src/lib/md.css @@ -27,3 +27,27 @@ .prose a:hover code { @apply text-white underline-op-60; } + +.prose table { + @apply w-fit b-1 b-white/6 rounded-md text-left; +} + +.prose thead { + @apply bg-white/2 font-bold op-90; +} + +.prose tr { + @apply b-b-1 b-white/6; +} + +.prose tbody tr { + @apply transition-background-color last:b-b-none even:bg-white/2; +} + +.prose tbody:hover tr { + @apply even:bg-white/1 hover:bg-white/4; +} + +.prose blockquote { + @apply b-(l-0.2em white/10 solid) pl-1em not-italic; +}