-
Notifications
You must be signed in to change notification settings - Fork 16
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
[Question] Could it be used with Tiptap (prosemirror based editor)? #4
Comments
It should be possible to use with tiptap, I would love to document this for other people as well with your help! This shouldn't be an You need access to the EditorState const state = editor.state;
// Need some way to pass the buffer into the word serializer (e.g. base64 conversion)
const opts = {
getImageBuffer(src: string) {
return anImageBuffer;
},
};
const wordDocument = defaultDocxSerializer.serialize(state.doc, opts); I think that should be it? You could also console.log the schema.nodes and marks, which you will need if you are doing anything non-standard or named differently than the standard prosemirror world. I think the errors should guide you there. You can extend that: import { DocxSerializer, defaultNodes, defaultMarks } from 'prosemirror-docx';
const nodeSerializer = {
...defaultNodes,
my_paragraph(state, node) {
state.renderInline(node);
state.closeBlock(node);
},
};
export const myDocxSerializer = new DocxSerializer(nodeSerializer, defaultMarks); Where you have your paragraph etc. as custom nodes, these would need to match what ever customizations that you do in tiptap. Let me know if that gives some hints on approach -- excited to document this in the readme, and would love your help with that! |
OK, thanks! I'll try my best! |
@rowanc1 const opts = {
getImageBuffer(src: string) {
return anImageBuffer;
},
}; Can't render image. I think that const opts = {
async getImageBuffer(src: string) {
const imgBuffer = await fetchImageBuffer(src);
return imgBuffer;
}
} Other than that, awesome work! 👍 |
Do you think you would be willing to write a paragraph in the readme under a heading like Agree on the promise -- I went that way because |
I just followed your instructions. 🙂 import { Editor } from "@tiptap/react";
import { writeDocx, DocxSerializer, defaultNodes, defaultMarks } from 'prosemirror-docx';
// tiptap has these camelCased
const nodeSerializer = {
...defaultNodes,
hardBreak: defaultNodes.hard_break,
codeBlock: defaultNodes.code_block,
orderedList: defaultNodes.ordered_list,
listItem: defaultNodes.list_item,
bulletList: defaultNodes.bullet_list,
horizontalRule: defaultNodes.horizontal_rule,
image(state, node) {
// no image
state.renderInline(node);
state.closeBlock(node);
}
};
const myDocxSerializer = new DocxSerializer(nodeSerializer, defaultMarks);
// somewhere in the app
const editor = new Editor({
// options
});
export const ButtonExportDOCX = (props) => {
return (
<button onClick={async () => {
const opts = {
getImageBuffer(src: string) {
return Buffer.from("real buffer here");
},
};
const wordDocument = myDocxSerializer.serialize(editor.state.doc, opts);
await writeDocx(wordDocument, (buffer) => {
// use buffer
});
}}>
export to docx
</button>
)
} |
@devgeni Hello, I would like to ask how to use the custom node export |
|
Adds tip tap default bold and italic marks
Hey!
This plugin looks nice and I would like to use it with Tiptap editor.
There is a page on how to use prosemirror plugins with Tiptap. But I can't figure out how should I set up your plugin in a similar way.
Could you please help me out with this? Thanks!
The text was updated successfully, but these errors were encountered: