Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YousefED committed May 16, 2024
1 parent f22e086 commit a08ae97
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 45 deletions.
187 changes: 144 additions & 43 deletions packages/editor/src/integrations/markdown/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import {
BlockNoteEditor,
BlockNoteSchema,
createInternalBlockSpec,
defaultBlockSpecs,
} from "@blocknote/core";
import { MonacoCodeBlock, MonacoInlineCode } from "@typecell-org/frame";
/* eslint-disable @typescript-eslint/no-explicit-any */
import { createStronglyTypedTiptapNode } from "@blocknote/core";
import { mergeAttributes } from "@tiptap/core";
// import styles from "../../Block.module.css";

import * as parsers from "@typecell-org/parsers";
import { uniqueId } from "@typecell-org/util";
import * as Y from "yjs";
Expand Down Expand Up @@ -91,45 +96,141 @@ export async function markdownToYDoc(markdown: string, title?: string) {
}

// hacky
// export const MonacoBlockContent = createTipTapBlock({
// name: "codeblock",
// content: "inline*",
// editable: true,
// selectable: true,
// whitespace: "pre",
// code: true,

// addAttributes() {
// return {
// language: {
// default: "typescript",
// parseHTML: (element) => element.getAttribute("data-language"),
// renderHTML: (attributes) => {
// return {
// "data-language": attributes.language,
// };
// },
// },
// };
// },

// parseHTML() {
// return [
// {
// tag: "code",
// priority: 200,
// node: "codeblock",
// },
// ];
// },

// renderHTML({ HTMLAttributes }) {
// return [
// "code",
// mergeAttributes(HTMLAttributes, {
// // class: styles.blockContent,
// "data-content-type": this.name,
// }),
// ];
// },
// });
const node = createStronglyTypedTiptapNode({
name: "codeblock",
content: "inline*",
editable: true,
group: "blockContent",

selectable: true,
whitespace: "pre",
code: true,

addAttributes() {
return {
language: {
default: "typescript",
parseHTML: (element) => element.getAttribute("data-language"),
renderHTML: (attributes) => {
return {
"data-language": attributes.language,
};
},
},
storage: {
default: {},
parseHTML: (_element) => ({}),
renderHTML: (attributes) => {
return {
// "data-language": attributes.language,
};
},
},
};
},

parseHTML() {
return [
{
tag: "code",
priority: 200,
node: "codeblock",
},
];
},

renderHTML({ HTMLAttributes }) {
return [
"code",
mergeAttributes(HTMLAttributes, {
// class: styles.blockContent,
"data-content-type": this.name,
}),
];
},

// addNodeView: MonacoNodeView(false),
// addProseMirrorPlugins() {
// return [arrowHandlers];
// },
});

export const MonacoCodeBlock = createInternalBlockSpec(
{
type: "codeblock",
content: "inline",

propSchema: {
language: {
type: "string",
default: "typescript",
},
storage: {
type: "string",
default: "",
},
},
},
{
node,
toExternalHTML: undefined as any, // TODO
toInternalHTML: undefined as any,
},
);

const nodeInline = createStronglyTypedTiptapNode({
name: "inlineCode",
inline: true,
group: "inline",
content: "inline*",
editable: true,
selectable: false,
parseHTML() {
return [
{
tag: "inlineCode",
priority: 200,
node: "inlineCode",
},
];
},

renderHTML({ HTMLAttributes }) {
return [
"inlineCode",
mergeAttributes(HTMLAttributes, {
// class: styles.blockContent,
"data-content-type": this.name,
}),
0,
];
},

// addNodeView: MonacoNodeView(true),
// addProseMirrorPlugins() {
// return [arrowHandlers] as any;
// },
});

// TODO: clean up listeners
export const MonacoInlineCode = createInternalBlockSpec(
{
content: "inline",
type: "inlineCode",
propSchema: {
language: {
type: "string",
default: "typescript",
},
storage: {
type: "string",
default: "",
},
},
},
{
node: nodeInline,
toExternalHTML: undefined as any,
toInternalHTML: undefined as any,
},
);
2 changes: 0 additions & 2 deletions packages/frame/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * from "./Frame";
export * from "./codeblocks/MonacoCodeBlock";
export * from "./codeblocks/MonacoInlineCode";

0 comments on commit a08ae97

Please sign in to comment.