-
Notifications
You must be signed in to change notification settings - Fork 780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/export html #3930
Merged
Merged
Fix/export html #3930
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,10 @@ import { BaseKbdPlugin } from '@udecode/plate-kbd'; | |
import { BaseColumnItemPlugin, BaseColumnPlugin } from '@udecode/plate-layout'; | ||
import { BaseLineHeightPlugin } from '@udecode/plate-line-height'; | ||
import { BaseLinkPlugin } from '@udecode/plate-link'; | ||
import { | ||
BaseEquationPlugin, | ||
BaseInlineEquationPlugin, | ||
} from '@udecode/plate-math'; | ||
import { | ||
BaseAudioPlugin, | ||
BaseFilePlugin, | ||
|
@@ -100,6 +104,7 @@ import { ColumnGroupElementStatic } from '@/registry/default/plate-ui/column-gro | |
import { CommentLeafStatic } from '@/registry/default/plate-ui/comment-leaf-static'; | ||
import { DateElementStatic } from '@/registry/default/plate-ui/date-element-static'; | ||
import { EditorStatic } from '@/registry/default/plate-ui/editor-static'; | ||
import { EquationElementStatic } from '@/registry/default/plate-ui/equation-element-static'; | ||
import { HeadingElementStatic } from '@/registry/default/plate-ui/heading-element-static'; | ||
import { HighlightLeafStatic } from '@/registry/default/plate-ui/highlight-leaf-static'; | ||
import { HrElementStatic } from '@/registry/default/plate-ui/hr-element-static'; | ||
|
@@ -112,6 +117,7 @@ import { | |
TodoLiStatic, | ||
TodoMarkerStatic, | ||
} from '@/registry/default/plate-ui/indent-todo-marker-static'; | ||
import { InlineEquationElementStatic } from '@/registry/default/plate-ui/inline-equation-element-static'; | ||
import { KbdLeafStatic } from '@/registry/default/plate-ui/kbd-leaf-static'; | ||
import { LinkElementStatic } from '@/registry/default/plate-ui/link-element-static'; | ||
import { MediaAudioElementStatic } from '@/registry/default/plate-ui/media-audio-element-static'; | ||
|
@@ -159,10 +165,12 @@ export default async function SlateToHtmlBlock() { | |
[BaseColumnPlugin.key]: ColumnGroupElementStatic, | ||
[BaseCommentsPlugin.key]: CommentLeafStatic, | ||
[BaseDatePlugin.key]: DateElementStatic, | ||
[BaseEquationPlugin.key]: EquationElementStatic, | ||
[BaseFilePlugin.key]: MediaFileElementStatic, | ||
[BaseHighlightPlugin.key]: HighlightLeafStatic, | ||
[BaseHorizontalRulePlugin.key]: HrElementStatic, | ||
[BaseImagePlugin.key]: ImageElementStatic, | ||
[BaseInlineEquationPlugin.key]: InlineEquationElementStatic, | ||
[BaseItalicPlugin.key]: withProps(SlateLeaf, { as: 'em' }), | ||
[BaseKbdPlugin.key]: KbdLeafStatic, | ||
[BaseLinkPlugin.key]: LinkElementStatic, | ||
|
@@ -212,6 +220,8 @@ export default async function SlateToHtmlBlock() { | |
|
||
const editor = createSlateEditor({ | ||
plugins: [ | ||
BaseEquationPlugin, | ||
BaseInlineEquationPlugin, | ||
BaseColumnPlugin, | ||
BaseColumnItemPlugin, | ||
BaseTocPlugin, | ||
|
@@ -300,6 +310,8 @@ export default async function SlateToHtmlBlock() { | |
|
||
const tailwindCss = await getCachedTailwindCss(); | ||
const prismCss = await getCachedPrismCss(); | ||
const katexCDN = `<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.css" integrity="sha384-9PvLvaiSKCPkFKB1ZsEoTjgnJn+O3KvEwtsz37/XrkYft3DTk2gHdYvd9oWgW3tV" crossorigin="anonymous">`; | ||
|
||
// const cookieStore = await cookies(); | ||
// const theme = cookieStore.get('theme')?.value; | ||
const theme = 'light'; | ||
|
@@ -314,6 +326,7 @@ export default async function SlateToHtmlBlock() { | |
// Create the full HTML document | ||
const html = createHtmlDocument({ | ||
editorHtml, | ||
katexCDN, | ||
prismCss, | ||
tailwindCss, | ||
theme, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,10 @@ import { BaseKbdPlugin } from '@udecode/plate-kbd'; | |
import { BaseColumnItemPlugin, BaseColumnPlugin } from '@udecode/plate-layout'; | ||
import { BaseLineHeightPlugin } from '@udecode/plate-line-height'; | ||
import { BaseLinkPlugin } from '@udecode/plate-link'; | ||
import { | ||
BaseEquationPlugin, | ||
BaseInlineEquationPlugin, | ||
} from '@udecode/plate-math'; | ||
import { | ||
BaseAudioPlugin, | ||
BaseFilePlugin, | ||
|
@@ -100,6 +104,7 @@ import { ColumnGroupElementStatic } from '@/registry/default/plate-ui/column-gro | |
import { CommentLeafStatic } from '@/registry/default/plate-ui/comment-leaf-static'; | ||
import { DateElementStatic } from '@/registry/default/plate-ui/date-element-static'; | ||
import { EditorStatic } from '@/registry/default/plate-ui/editor-static'; | ||
import { EquationElementStatic } from '@/registry/default/plate-ui/equation-element-static'; | ||
import { HeadingElementStatic } from '@/registry/default/plate-ui/heading-element-static'; | ||
import { HighlightLeafStatic } from '@/registry/default/plate-ui/highlight-leaf-static'; | ||
import { HrElementStatic } from '@/registry/default/plate-ui/hr-element-static'; | ||
|
@@ -112,6 +117,7 @@ import { | |
TodoLiStatic, | ||
TodoMarkerStatic, | ||
} from '@/registry/default/plate-ui/indent-todo-marker-static'; | ||
import { InlineEquationElementStatic } from '@/registry/default/plate-ui/inline-equation-element-static'; | ||
import { KbdLeafStatic } from '@/registry/default/plate-ui/kbd-leaf-static'; | ||
import { LinkElementStatic } from '@/registry/default/plate-ui/link-element-static'; | ||
import { MediaAudioElementStatic } from '@/registry/default/plate-ui/media-audio-element-static'; | ||
|
@@ -128,6 +134,8 @@ import { TableRowElementStatic } from '@/registry/default/plate-ui/table-row-ele | |
import { TocElementStatic } from '@/registry/default/plate-ui/toc-element-static'; | ||
import { ToggleElementStatic } from '@/registry/default/plate-ui/toggle-element-static'; | ||
|
||
import { equationValue } from '../../example/values/equation-value'; | ||
|
||
export const description = 'Slate to HTML'; | ||
|
||
export const iframeHeight = '800px'; | ||
|
@@ -159,10 +167,12 @@ export default async function SlateToHtmlBlock() { | |
[BaseColumnPlugin.key]: ColumnGroupElementStatic, | ||
[BaseCommentsPlugin.key]: CommentLeafStatic, | ||
[BaseDatePlugin.key]: DateElementStatic, | ||
[BaseEquationPlugin.key]: EquationElementStatic, | ||
[BaseFilePlugin.key]: MediaFileElementStatic, | ||
[BaseHighlightPlugin.key]: HighlightLeafStatic, | ||
[BaseHorizontalRulePlugin.key]: HrElementStatic, | ||
[BaseImagePlugin.key]: ImageElementStatic, | ||
[BaseInlineEquationPlugin.key]: InlineEquationElementStatic, | ||
[BaseItalicPlugin.key]: withProps(SlateLeaf, { as: 'em' }), | ||
[BaseKbdPlugin.key]: KbdLeafStatic, | ||
[BaseLinkPlugin.key]: LinkElementStatic, | ||
|
@@ -196,7 +206,7 @@ export default async function SlateToHtmlBlock() { | |
...linkValue, | ||
...horizontalRuleValue, | ||
...tableValue, | ||
...mediaValue, | ||
...equationValue, | ||
...columnValue, | ||
...mentionValue, | ||
...dateValue, | ||
|
@@ -208,10 +218,13 @@ export default async function SlateToHtmlBlock() { | |
...lineHeightValue, | ||
...indentValue, | ||
...indentListValue, | ||
...mediaValue, | ||
]; | ||
|
||
const editor = createSlateEditor({ | ||
plugins: [ | ||
BaseEquationPlugin, | ||
BaseInlineEquationPlugin, | ||
BaseColumnPlugin, | ||
BaseColumnItemPlugin, | ||
BaseTocPlugin, | ||
|
@@ -300,6 +313,8 @@ export default async function SlateToHtmlBlock() { | |
|
||
const tailwindCss = await getCachedTailwindCss(); | ||
const prismCss = await getCachedPrismCss(); | ||
const katexCDN = `<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.css" integrity="sha384-9PvLvaiSKCPkFKB1ZsEoTjgnJn+O3KvEwtsz37/XrkYft3DTk2gHdYvd9oWgW3tV" crossorigin="anonymous">`; | ||
|
||
// const cookieStore = await cookies(); | ||
// const theme = cookieStore.get('theme')?.value; | ||
const theme = 'light'; | ||
|
@@ -314,6 +329,7 @@ export default async function SlateToHtmlBlock() { | |
// Create the full HTML document | ||
const html = createHtmlDocument({ | ||
editorHtml, | ||
katexCDN, | ||
prismCss, | ||
tailwindCss, | ||
theme, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
apps/www/src/registry/default/plate-ui/equation-element-static.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
|
||
import type { TEquationElement } from '@udecode/plate-math'; | ||
|
||
import { cn } from '@udecode/cn'; | ||
import { type SlateElementProps, SlateElement } from '@udecode/plate-common'; | ||
import { getEquationHtml } from '@udecode/plate-math'; | ||
|
||
export function EquationElementStatic({ | ||
children, | ||
className, | ||
...props | ||
}: SlateElementProps) { | ||
const element = props.element as TEquationElement; | ||
|
||
const html = getEquationHtml({ | ||
element, | ||
options: { | ||
displayMode: true, | ||
errorColor: '#cc0000', | ||
fleqn: false, | ||
leqno: false, | ||
macros: { '\\f': '#1f(#2)' }, | ||
output: 'htmlAndMathml', | ||
strict: 'warn', | ||
throwOnError: false, | ||
trust: false, | ||
}, | ||
}); | ||
|
||
return ( | ||
<SlateElement className={cn('relative my-1', className)} {...props}> | ||
<div | ||
className={cn( | ||
'flex select-none items-center justify-center rounded-sm', | ||
element.texExpression.length === 0 ? 'bg-muted p-3' : 'px-2 py-1' | ||
)} | ||
> | ||
<span | ||
dangerouslySetInnerHTML={{ | ||
__html: html, | ||
}} | ||
/> | ||
</div> | ||
{children} | ||
</SlateElement> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,10 @@ import { BaseKbdPlugin } from '@udecode/plate-kbd'; | |
import { BaseColumnItemPlugin, BaseColumnPlugin } from '@udecode/plate-layout'; | ||
import { BaseLineHeightPlugin } from '@udecode/plate-line-height'; | ||
import { BaseLinkPlugin } from '@udecode/plate-link'; | ||
import { | ||
BaseEquationPlugin, | ||
BaseInlineEquationPlugin, | ||
} from '@udecode/plate-math'; | ||
import { | ||
BaseAudioPlugin, | ||
BaseFilePlugin, | ||
|
@@ -113,6 +117,8 @@ import { | |
useOpenState, | ||
} from './dropdown-menu'; | ||
import { EditorStatic } from './editor-static'; | ||
import { EquationElementStatic } from './equation-element-static'; | ||
import { InlineEquationElementStatic } from './inline-equation-element-static'; | ||
import { ToolbarButton } from './toolbar'; | ||
|
||
const siteUrl = 'https://platejs.org'; | ||
|
@@ -197,10 +203,12 @@ export function ExportToolbarButton({ children, ...props }: DropdownMenuProps) { | |
[BaseColumnPlugin.key]: ColumnGroupElementStatic, | ||
[BaseCommentsPlugin.key]: CommentLeafStatic, | ||
[BaseDatePlugin.key]: DateElementStatic, | ||
[BaseEquationPlugin.key]: EquationElementStatic, | ||
[BaseFilePlugin.key]: MediaFileElementStatic, | ||
[BaseHighlightPlugin.key]: HighlightLeafStatic, | ||
[BaseHorizontalRulePlugin.key]: HrElementStatic, | ||
[BaseImagePlugin.key]: ImageElementStatic, | ||
[BaseInlineEquationPlugin.key]: InlineEquationElementStatic, | ||
[BaseItalicPlugin.key]: withProps(SlateLeaf, { as: 'em' }), | ||
[BaseKbdPlugin.key]: KbdLeafStatic, | ||
[BaseLinkPlugin.key]: LinkElementStatic, | ||
|
@@ -245,6 +253,8 @@ export function ExportToolbarButton({ children, ...props }: DropdownMenuProps) { | |
BaseUnderlinePlugin, | ||
BaseBlockquotePlugin, | ||
BaseDatePlugin, | ||
BaseEquationPlugin, | ||
BaseInlineEquationPlugin, | ||
BaseCodeBlockPlugin.configure({ | ||
options: { | ||
prism: Prism, | ||
|
@@ -322,6 +332,7 @@ export function ExportToolbarButton({ children, ...props }: DropdownMenuProps) { | |
|
||
const prismCss = `<link rel="stylesheet" href="${siteUrl}/prism.css">`; | ||
const tailwindCss = `<link rel="stylesheet" href="${siteUrl}/tailwind.css">`; | ||
const katexCss = `<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.css" integrity="sha384-9PvLvaiSKCPkFKB1ZsEoTjgnJn+O3KvEwtsz37/XrkYft3DTk2gHdYvd9oWgW3tV" crossorigin="anonymous">`; | ||
|
||
const html = `<!DOCTYPE html> | ||
<html lang="en"> | ||
|
@@ -337,6 +348,7 @@ export function ExportToolbarButton({ children, ...props }: DropdownMenuProps) { | |
/> | ||
${tailwindCss} | ||
${prismCss} | ||
${katexCss} | ||
<style> | ||
:root { | ||
--font-sans: 'Inter', 'Inter Fallback'; | ||
|
61 changes: 61 additions & 0 deletions
61
apps/www/src/registry/default/plate-ui/inline-equation-element-static.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
|
||
import type { TEquationElement } from '@udecode/plate-math'; | ||
|
||
import { cn } from '@udecode/cn'; | ||
import { type SlateElementProps, SlateElement } from '@udecode/plate-common'; | ||
import { getEquationHtml } from '@udecode/plate-math'; | ||
|
||
export function InlineEquationElementStatic({ | ||
children, | ||
className, | ||
...props | ||
}: SlateElementProps) { | ||
const element = props.element as TEquationElement; | ||
|
||
const html = getEquationHtml({ | ||
element, | ||
options: { | ||
displayMode: true, | ||
errorColor: '#cc0000', | ||
fleqn: false, | ||
leqno: false, | ||
macros: { '\\f': '#1f(#2)' }, | ||
output: 'htmlAndMathml', | ||
strict: 'warn', | ||
throwOnError: false, | ||
trust: false, | ||
}, | ||
}); | ||
|
||
return ( | ||
<SlateElement | ||
className={cn( | ||
'inline-block select-none rounded-sm [&_.katex-display]:my-0', | ||
className | ||
)} | ||
{...props} | ||
> | ||
<div | ||
className={cn( | ||
'after:absolute after:inset-0 after:-left-1 after:-top-0.5 after:z-[1] after:h-[calc(100%)+4px] after:w-[calc(100%+8px)] after:rounded-sm after:content-[""]', | ||
'h-6', | ||
element.texExpression.length === 0 && | ||
'text-muted-foreground after:bg-neutral-500/10', | ||
className | ||
)} | ||
> | ||
<span | ||
className={cn( | ||
element.texExpression.length === 0 && 'hidden', | ||
'font-mono leading-none' | ||
)} | ||
dangerouslySetInnerHTML={{ | ||
__html: html, | ||
}} | ||
/> | ||
</div> | ||
{children} | ||
</SlateElement> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Path typo