- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 426
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
Inline sync plugin #695
Inline sync plugin #695
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 52efc1a. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Seemly , It will broken the editor history. |
Do you have reproducable steps of videos? |
#704 like this |
Could you make the Inline sync plugin as an option. because I have do support |
I can certiainly make it can be turned off, but in my opinion |
sorry , |
Do you mean you need |
I have done it. but maybe will bring some other bugs,not sure, runs fine right now |
Early parsing markdown break plugins that uses example import { createCmd, createCmdKey } from '@milkdown/core';
import { AtomList, createMark } from '@milkdown/utils';
import directive from 'remark-directive';
export const ModifyColorlulText = createCmdKey<string>('ModifyColorlulText');
const id = 'colorfulText';
const colorfulTextMark = createMark(() => {
return {
id,
schema: () => ({
attrs: {
hex: {},
},
inclusive: true,
parseDOM: [
{
tag: 'span',
getAttrs: (dom) => {
if (!(dom instanceof HTMLElement)) {
console.error(new Error('impossible!'));
return false;
}
let { color } = dom.style;
if (color === '') return false;
color = `#${color
.slice(4, -1)
.split(', ')
.map((v) => parseInt(v).toString(16))
.join('')}`;
return { hex: color };
},
},
],
toDOM: (mark) => {
const style = `color:${mark.attrs['hex']};`;
return ['span', { style }];
},
parseMarkdown: {
match: (node) => node.type === 'textDirective' && node['name'] === 'colorful',
runner: (state, node, markType) => {
state.openMark(markType, { hex: (node['attributes'] as { hex: string }).hex });
state.next(node.children);
state.closeMark(markType);
},
},
toMarkdown: {
match: (node) => node.type.name === id,
runner: (state, mark) => {
state.withMark(mark, 'textDirective', undefined, {
name: 'colorful',
attributes: {
hex: mark.attrs['hex'],
},
});
},
},
}),
commands: (markType) => [
createCmd(ModifyColorlulText, (hex = '') => (state, dispatch) => {
if (!dispatch) return false;
const { from, to } = state.selection;
const { tr } = state;
if (hex === '') {
dispatch(tr.removeMark(from, to, markType));
} else {
const colorMark = markType.create({ hex });
if (!colorMark) return false;
dispatch(tr.addMark(from, to, colorMark));
}
return true;
}),
],
remarkPlugins: () => [directive],
};
});
// color
export const colorfulText = AtomList.create([colorfulTextMark()]); Strictly speaking, |
@z-950 look at this @ezone-devops/milkdown-plugin-directive-fallback |
@4-1-1 It's not a perfect realization of the fallback. I try do this, but it will lost some others directive. |
@4-1-1 export function factoryName(effects, ok, nok, type) {
const self = this;
let nameCache = ''; // {1}
return start;
/** @type {State} */
function start(code) {
if (asciiAlpha(code)) {
nameCache = String.fromCharCode(code); // {2}
effects.enter(type);
effects.consume(code);
return name;
}
return nok(code);
}
/** @type {State} */
function name(code) {
if (
code === codes.dash ||
code === codes.underscore ||
asciiAlphanumeric(code)
) {
nameCache += String.fromCharCode(code); // {3}
effects.consume(code);
return name;
}
effects.exit(type);
return self.previous === codes.dash || self.previous === codes.underscore || !whitelist.includes(nameCache) //{4}
? nok(code)
: ok(code);
}
} |
I've added some options for sync plugin to make the behavior can be controled by users. |
@@ -13,6 +12,7 @@ export const strong = createMark<Keys>((utils) => { | |||
return { | |||
id, | |||
schema: () => ({ | |||
inclusive: false, |
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.
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.
It's a trade off to support inline sync. We need to provide custom toggle mark command to fix this.
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.
@Saul-Mirone Okay, I've created an issue for this. #809
Summary
There're lots of bugs caused by consistency between markdown AST and UI.
For example:
#637
#553
#622
The
inline-sync-plugin
can help to solve this issue. Instead of using inputrules to check user input, this plugin keep sync the prosemirror node between markdown AST for inline nodes (such asparagraph
andheading
).How did you test this change?
Manually test and e2e test.