Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
serialize: ({ schema, content }) => {
const document = schema.nodeFromJSON(content);
const serializer = new ProseMirrorMarkdownSerializer(defaultMarkdownSerializer.nodes, {
...defaultMarkdownSerializer.marks,
bold: {
// creates a bold alias for the strong mark converter
...defaultMarkdownSerializer.marks.strong,
},
italic: { open: '_', close: '_', mixable: true, expelEnclosingWhitespace: true },
});
return serializer.serialize(document, {
tightLists: true,
});
},
};
import { MarkdownSerializer } from 'prosemirror-markdown';
import { generateBibTexString } from '../references/citationConversion';
// serialize to markdown and keep stack?
export const markdownSerializer = new MarkdownSerializer({
blockquote(state, node) {
state.wrapBlock('> ', null, node, () => state.renderContent(node));
},
code_block(state, node) {
if (node.attrs.params === null) {
state.wrapBlock(' ', null, node, () => state.text(node.textContent, false));
} else {
state.write('```' + node.attrs.params + '\n');
state.text(node.textContent, false);
state.ensureNewLine();
state.write('```');
state.closeBlock(node);
}
},
heading(state, node) {
state.write(state.repeat('#', node.attrs.level) + ' ');
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.markdownSerializer = undefined;
var _ref;
var _prosemirrorMarkdown = require('prosemirror-markdown');
var _citationConversion = require('../references/citationConversion');
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
// serialize to markdown and keep stack?
var markdownSerializer = exports.markdownSerializer = new _prosemirrorMarkdown.MarkdownSerializer((_ref = {
blockquote: function blockquote(state, node) {
state.wrapBlock('> ', null, node, function () {
return state.renderContent(node);
});
},
code_block: function code_block(state, node) {
if (node.attrs.params === null) {
state.wrapBlock(' ', null, node, function () {
return state.text(node.textContent, false);
});
} else {
state.write('```' + node.attrs.params + '\n');
state.text(node.textContent, false);
state.ensureNewLine();
state.write('```');
state.closeBlock(node);
export function addMentionsToMarkdownSerializer(serializer) {
return new MarkdownSerializer(
{
...serializer.nodes,
mention: markdownSerializer(),
},
serializer.marks,
);
}
[name]: toMarkdown,
}),
{},
);
const marks = editorExtensions
.filter((extension) => extension.type === 'mark')
.reduce(
(ms, { name, toMarkdown }) => ({
...ms,
[name]: toMarkdown,
}),
{},
);
export default new MarkdownSerializer(nodes, marks);
export const toMarkdown = (content: ProsemirrorNode) =>
new MarkdownSerializer(
{
blockquote(state, node) {
state.wrapBlock('> ', undefined, node, () => state.renderContent(node));
},
codeBlock(state, node) {
const language: string | undefined = node.attrs.language;
state.write(`\`\`\`${language ?? ''}\n`);
state.text(node.textContent, false);
state.ensureNewLine();
state.write('```');
state.closeBlock(node);
},
heading(state, node) {
state.write(`${state.repeat('#', node.attrs.level)} `);
state.renderInline(node);
state.closeBlock(node);