Skip to content
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: Text aligin - how to convert HTML tags into raw with markdownToDraft? #166

Open
Pawelh133 opened this issue Nov 25, 2021 · 0 comments

Comments

@Pawelh133
Copy link

Thanks a lot for wonderful library!
Am I doing something wrong and Im not sure Im misunderstand something?

As I know text-align is not available in markdowns, so I created just html styles and added it as option into draftDataToMarkdown method. Here is example of this configuration:

const draftToMarkdownOptions = (): DraftToMarkdownOptions => ({
  styleItems: {
    center: {
      open() {
        return '<p style="text-align: center;">';
      },
      close() {
        return '</p>';
      },
    },
    left: {
      open() {
        return '<p style="text-align: left;">';
      },
      close() {
        return '</p>';
      },
    },
    right: {
      open() {
        return '<p style="text-align: right;">';
      },
      close() {
        return '</p>';
      },
    },
  },
});

It works fine on online editor. But when I editing document i have to do the reverse operation. I mean I have those tags change into center, left, right elements of RawDraftContentState. I was trying (for center):

const markdownToDraftOptions = (): MarkdownToDraftOptions => ({
  blockTypes: {
    center: item => {
      return {
        type: 'p',
        mutability: 'IMMUTABLE',
        text: 'style="text-align: center;"',
        data: {
          tag: 'style="text-align: center;"',
        },
      }
    },
  },
});

What am I doing wrong? Or there is no possiblity to do this for now? Thanks in advice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant