How to use the markdown-draft-js.markdownToDraft function in markdown-draft-js

To help you get started, we’ve selected a few markdown-draft-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github birkir / prime / packages / prime-field-string / src / ui / InputComponent.tsx View on Github external
'separator',
  'list-ul',
  'list-ol',
  'separator',
  'link',
  'emoji',
];

const markdownConfig = {
  preserveNewlines: true,
  remarkablePreset: 'full',
};

export class InputComponent extends React.PureComponent {
  public state = {
    value: BraftEditor.createEditorState(markdownToDraft(this.props.initialValue, markdownConfig)),
  };

  public setMarkdownValue = debounce(() => {
    try {
      const { form, path } = this.props;
      this.state.value.toRAW();
      form.setFieldsValue({
        [path]: draftToMarkdown(
          JSON.parse(this.state.value.toRAW().toString()),
          markdownConfig
        ).replace(/\n\n/g, '\n \n'),
      });
    } catch (err) {
      console.error('Error converting rich text to markdown'); // tslint:disable-line no-console
    }
  }, 330);
github danielmahon / gatsby-starter-procyon / src / components / EditableMarkdown.js View on Github external
client.query({ query: GET_NODES }).then(({ data: { nodes } }) => {
      const localNode = _.find(nodes, { id: node.id });
      if (localNode) {
        markdown = localNode.content;
        rawObject = markdownToDraft(markdown);
      }
      const editorState = createEditorState(rawObject);
      // If user logged in then show editor
      if (user) {
        this.setState({
          user,
          nodes,
          source: markdown,
          editorState,
          originalEditorState: editorState,
        });
      } else {
        // If user not logged in source regular text
        this.setState({ source: markdown });
      }
      // Login handlers
github danielmahon / gatsby-starter-procyon / src / components / EditableMarkdown.js View on Github external
componentDidMount() {
    const { source, client, node = {} } = this.props;
    const user = netlifyIdentity.currentUser();
    let markdown = source;
    let rawObject = markdownToDraft(markdown);
    // See if we have a locally saved node
    // Saving triggers a server rebuild so we store data locally
    // to account for the delay
    client.query({ query: GET_NODES }).then(({ data: { nodes } }) => {
      const localNode = _.find(nodes, { id: node.id });
      if (localNode) {
        markdown = localNode.content;
        rawObject = markdownToDraft(markdown);
      }
      const editorState = createEditorState(rawObject);
      // If user logged in then show editor
      if (user) {
        this.setState({
          user,
          nodes,
          source: markdown,
github charliewilco / downwrite / reducers / editor.ts View on Github external
export function initializer(initialData: { entry: Entry }): IEditorState {
  console.log("EDITOR_INITIALIZER", initialData);

  if (initialData) {
    const draft = markdownToDraft(initialData.entry.content);
    const editorState = Draft.EditorState.createWithContent(
      Draft.convertFromRaw(draft)
    );

    return {
      editorState,
      title: initialData.entry.title,
      publicStatus: initialData.entry.public,
      initialFocus: false
    };
  } else {
    return {
      editorState: null,
      title: null,
      publicStatus: null,
      initialFocus: false
github orbiting / crowdfunding-frontend / src / utils / markdown.js View on Github external
export const convertMdToDraft = md => markdownToDraft(
  md,
  {
    remarkablePlugins: [imageWrapper],
    blockTypes
  }
)
github charliewilco / downwrite / client / components / upload.tsx View on Github external
reader.onload = () => {
        let md: IMarkdown = fm(reader.result as string);

        let markdown = markdownToDraft(md.body, { preserveNewlines: true });

        return props.onParsed({
          title: md.attributes.title || "",
          editorState: Draft.EditorState.createWithContent(
            Draft.convertFromRaw(markdown)
          )
        });
      };
github withspectrum / spectrum / api / mutations / message / addMessage.js View on Github external
event: events.MESSAGE_SENT_FAILED,
      properties: {
        reason: 'non media message with file',
        message,
      },
    });
    return new UserError(
      `To send an image, please use messageType: "media" instead of "${
        message.messageType
      }".`
    );
  }

  if (message.messageType === 'text') {
    message.content.body = JSON.stringify(
      markdownToDraft(message.content.body)
    );
    message.messageType = 'draftjs';
  }

  if (message.messageType === 'draftjs') {
    let body;
    try {
      body = JSON.parse(message.content.body);
    } catch (err) {
      trackQueue.add({
        userId: user.id,
        event: events.MESSAGE_SENT_FAILED,
        properties: {
          reason: 'invalid draftjs data',
          message,
        },
github samuelmeuli / mini-diary / src / renderer / components / elements / Editor / Editor.tsx View on Github external
static getStateFromEntry(
		entries: Entries,
		date: Date,
	): { textEditorState: EditorState; titleEditorState: EditorState } {
		const indexDate = toIndexDate(date);
		const entry = entries[indexDate];
		let text = "";
		let title = "";
		if (entry) {
			({ text, title } = entry);
		}

		return {
			textEditorState: EditorState.createWithContent(convertFromRaw(markdownToDraft(text))),
			titleEditorState: EditorState.createWithContent(ContentState.createFromText(title)),
		};
	}
github birkir / prime / packages / prime-field-string / src / ui / InputComponent.tsx View on Github external
public componentWillReceiveProps(nextProps: PrimeFieldProps) {
    if (nextProps.initialValue !== this.props.initialValue) {
      this.setState({
        value: BraftEditor.createEditorState(
          markdownToDraft(nextProps.initialValue, markdownConfig)
        ),
      });
    }
  }

markdown-draft-js

Convert draftjs blocks to markdown using the marked library, and vice versa.

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis