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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problems with overlapping formats #130

Merged
merged 3 commits into from
Jul 10, 2020

Conversation

jfschwarz
Copy link
Contributor

@jfschwarz jfschwarz commented Jul 10, 2020

Hello @Rosey 馃憢 ! Thank you for this handy library. It works quite well for me, except for a little issue with the way overlapping ranges of inline styles and entity ranges are handled.

The conversion breaks for the following example Draft.js input:
foo bar baz

Raw state:

{
  blocks: [
    {
      key: '5rq8m',
      text: 'foo bar baz',
      type: 'unstyled',
      depth: 0,
      inlineStyleRanges: [{ offset: 4, length: 7, style: 'BOLD' }],
      entityRanges: [{ offset: 0, length: 7, key: 0 }],
      data: {}
    }
  ],
  entityMap: {
    '0': {
      type: 'LINK',
      mutability: 'MUTABLE',
      data: {
        url: 'http://localhost:8000',
      }
    }
  }
}

markdown-draft-js maps it to:

[foo **bar](http://localhost:3000/g/statics/jm/journeys/ckcexvump0004wv6ze8ujmo9w) baz**

鈿狅笍 This is invalid markdown.

This PR adjust the implementation so that ranges are split up, keeping the nesting order sane. The new result for the example is:

[foo **bar**](http://localhost:8000) **baz**

- added 2 failing tests
- changed one spec to optimize complex value handling (tags closing fist should open last)
I have refactored the current implementation to keep track of correct tag nesting using a stack data structure. Also I fixed some of the code duplication using the `openTag`, `closeTag` helper functions.
@Rosey
Copy link
Owner

Rosey commented Jul 10, 2020

馃檶馃檶 wow that's quite the bug, thanks for the catch and fix

@Rosey Rosey merged commit 4110d25 into Rosey:main Jul 10, 2020
@Rosey
Copy link
Owner

Rosey commented Jul 10, 2020

Yay very nice, thanks again 鉂わ笍

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

Successfully merging this pull request may close these issues.

None yet

2 participants