Comments (12)
Works for React like that. Thanks @Saul-Mirone but this example miss me in docs
import { Slice } from "prosemirror-model";
const MilkdownEditor: React.FC = () => {
const editorRef = useRef<EditorRef | null>(null);
const [isContentLoaded, setContentLoaded] = useState<boolean>(false);
const editor = useEditor(
(root) => {
return new Editor()
.config((ctx) => {
ctx.set(rootCtx, root);
ctx.set(defaultValueCtx, "Default value");
})
.use(commonmark)
.use(clipboard)
.use(listener)
.use(history);
},
[],
);
useEffect(() => {
if (editorRef.current) {
const editor = editorRef.current.get();
if (editor) {
editor.action((ctx: Ctx) => {
const view = ctx.get(editorViewCtx);
const parser = ctx.get(parserCtx);
const doc = parser('Content changed !!!');
if (!doc) return;
const state = view.state;
view.dispatch(
state.tr.replace(
0,
state.doc.content.size,
new Slice(doc.content, 0, 0)
)
);
});
}
}
},[isContentLoaded])
return <ReactEditor ref={editorRef} editor={editor} />;
};
export default MilkdownEditor;
from milkdown.
You can use the action feature, you can find example here, and here for a very simple vue example.
Unfortunately these links don't work anymore, is it possible for them to be updated?
For anyone else coming across this and trying to extract and set the state for react:
import { replaceAll, getMarkdown } from '@milkdown/utils';
const { get } = useEditor(...);
let editor = get();
editor?.action(replaceAll('# The markdown I am replacing it with'));
let myContent = editor?.action(getMarkdown());
Also this is useful:
https://milkdown.dev/docs/api/utils#macros
from milkdown.
You can use the action feature, you can find example here, and here for a very simple vue example.
from milkdown.
Let me add this in doc.
from milkdown.
I found a problem with this method. It doesn't preserve new lines like
\n\n\n\n\n
. I think remark removes them.Is there a known solution?
That's how markdown syntax works and handled by remark, if you want to change this behavior, you need to write a remark plugin to do this.
from milkdown.
I found a problem with this method. It doesn't preserve new lines like \n\n\n\n\n
. I think remark removes them.
Is there a known solution?
from milkdown.
@danieldaeschle its not a perfect solution (extra <div>
is added) but you can try to create custom component for node: https://github.com/Saul-Mirone/milkdown/blob/main/gh-pages/pages/integrations/react/index.md#custom-component-for-node
with plugin is more complicated.. I have try to change onClick in link with a plugin without success: https://github.com/tagspaces/tagspaces-extensions/blob/Migrate-to-md-editor-extension-to-use-react/md-editor/src/App.tsx#L289
The problem is that plugin receive prosemirror nodes param and dont have access to DOM
from milkdown.
Is there an example of vue?
from milkdown.
Is there an example of vue?
Sure, here it is
https://codesandbox.io/s/milkdown-vue-update-ti4zb
from milkdown.
@sytolk in your example above where are editorViewCtx
and parserCtx
defined?
edit, oh:
import { editorViewCtx, parserCtx, serializerCtx } from '@milkdown/core';
from milkdown.
#288 Link for track
from milkdown.
Is there an example of angular?
from milkdown.
Related Issues (20)
- Can't click within headings and other blocks to edit once focus is lost HOT 3
- Wrong katex rendering HOT 1
- bold display wrong HOT 4
- [Bug] Email link's `href` is wrong
- bullet-list and ordered-list odd behavior HOT 1
- [Bug]`prevMarkdown` and `prevDoc` are `null` after setting defaultValue
- [Bug] incorrect converting with typing shift-enter then bullet list HOT 2
- [Bug] plugin-emoji fails when trying to use with Angular due to missing / broken TwemojiOptions reference HOT 2
- [Feature] I want set the button status to "active" when the cursor is over bold content. How to obtain this status
- [Bug] Pasting text from Google Docs results in bold text HOT 1
- [Bug] GapCursor plugin does not work with mouse clicks HOT 1
- [Bug] npm fails to install @milkdown/components HOT 2
- [Bug] Context "schema" not found, do you forget to inject it? HOT 4
- [Bug] blockView is not exported from @milkdown/plugin-block HOT 1
- [Bug]Cannot find name 'TwemojiOptions'
- [Bug] Checkbox cannot be switched in Mozilla Firefox
- [Feature] Limited support for commonly used HTML tags and entities in Markdown HOT 1
- [Bug] hybrid mode not working although #819 is closed
- [Bug] Heading Id not set in editor readonly mode
- [Bug]Selecting the editor causes the iframe to disappear
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from milkdown.