Skip to content

Commit

Permalink
feat: inline katex
Browse files Browse the repository at this point in the history
  • Loading branch information
hunghg255 committed Oct 23, 2024
1 parent d6ea4c2 commit 7a87f03
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion playground/.env.exmaple
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GIPHY_API_KEY=
VITE_GIPHY_API_KEY=
6 changes: 3 additions & 3 deletions playground/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ const extensions = [
return Promise.resolve(f)
},
}),
// ImageGif.configure({
// GIPHY_API_KEY: '',
// }),
ImageGif.configure({
GIPHY_API_KEY: import.meta.env.VITE_GIPHY_API_KEY as string,
}),
Blockquote,
SlashCommand,
HorizontalRule,
Expand Down
6 changes: 6 additions & 0 deletions playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,11 @@ export default defineConfig(({ mode }) => {
esbuild: {
sourcemap: isDev,
},
server: {
port: 8000,
},
preview: {
port: 8000,
},
}
})
2 changes: 1 addition & 1 deletion src/extensions/BaseKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const BaseKit = Extension.create<BaseKitOptions>({
extensions.push(
Placeholder.configure({
placeholder: ({ node, pos, editor }) => {
if (node?.type?.name === 'columns') {
if (node?.type?.name === 'columns' || node?.content?.size !== 0) {
return ''
}

Expand Down
9 changes: 5 additions & 4 deletions src/extensions/Katex/Katex.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Node, mergeAttributes, nodeInputRule } from '@tiptap/core'
import { ReactNodeViewRenderer } from '@tiptap/react'
import { KatexWrapper } from '@/extensions/Katex/components/KatexWrapper'
import KatexActiveButton from '@/extensions/Katex/components/KatexActiveButton'
import { KatexWrapper } from '@/extensions/Katex/components/KatexWrapper'

export interface IKatexAttrs {
text?: string
Expand All @@ -28,10 +28,11 @@ declare module '@tiptap/core' {

export const Katex = Node.create<IKatexOptions>({
name: 'katex',
group: 'block',
selectable: true,
atom: true,
group: 'inline',
inline: true,
defining: true,
draggable: true,
selectable: true,

addOptions() {
return {
Expand Down
5 changes: 3 additions & 2 deletions src/extensions/Katex/components/KatexWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ export function KatexWrapper({ node }: any) {

return (
<NodeViewWrapper
className="render-wrapper"
style={{
display: 'inline-block',
backgroundColor,
}}
as="span"
>
<div className="richtext-flex richtext-px-[4px] richtext-py-4 richtext-text-[1em] richtext-text-[#000] richtext-cursor-pointer richtext-justify-center">{content}</div>
{content}
</NodeViewWrapper>
)
}

0 comments on commit 7a87f03

Please sign in to comment.