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

Run parser plugins for top-level unknown elements #627

Merged

Conversation

kevinansfield
Copy link
Collaborator

closes #494

  • run parser plugins for the top-level section elements
    • do not continue parsing children elements if a parser marks the top-level element as finished
  • update tests to double-check the output for top-level elements is unchanged

@bantic I'd be interested in a quick review and any pointers for any edge cases/tests you think may need adding 😄

bantic and others added 2 commits June 18, 2018 13:00
closes bustle#494
- run parser plugins for the top-level section elements
    - do not continue parsing children elements if a parser marks the top-level element as finished
- update tests to double-check the output for top-level elements is unchanged
kevinansfield added a commit to TryGhost/Admin that referenced this pull request Jun 18, 2018
…raphs

refs TryGhost/Ghost#9623
- switch to custom `mobiledoc-kit` build
  - fixes top-level elements not being run through parser plugins (bustle/mobiledoc-kit#627)
  - fixes <kbd>Alt</kbd> getting stuck and causing <kbd>Backspace</kbd> to delete whole words (bustle/mobiledoc-kit#626)
  - fixes error that can occur when a paste results in blank insert (bustle/mobiledoc-kit#620)
- add new `figureToImageCard` parser
  - replaces hacky workaround to detect an image+figcaption inside the `imgToCard` parser plugin
- remove wrapping of html in a `<div>...</div>` when pasting
  - no longer necessary now that top-level elements are parsed
  - fixes rich-text pastes where multiple paragraphs would be collapsed into a single paragraph
Copy link
Contributor

@mixonic mixonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinansfield thanks for diving in here, I left a few thoughts.

@@ -69,14 +69,18 @@ class SectionParser {

this._updateStateFromElement(element);

let childNodes = isTextNode(element) ? [element] : element.childNodes;
let finished = this.runPlugins(element);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given an element here that is a text node, wouldn't the add call here mean that text node will be passed to this.runPlugins twice? Once here and once in pardeNode.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 😄 Pushed a fix

@@ -354,7 +354,7 @@ test('editor parses HTML post using parser plugins', (assert) => {
editor = new Editor({html, parserPlugins: [parserPlugin]});
assert.ok(!!editor.post, 'editor loads post');

assert.deepEqual(seenTagNames, ['TEXTAREA', 'IMG']);
assert.deepEqual(seenTagNames, ['P', 'TEXTAREA', 'IMG']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this characterized as a bugfix or as a breaking change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would characterise it as a bugfix because the old behaviour meant elements that were expected to go through parser plugins were never seen. I suppose it may be a breaking change if a consumer has built parser plugins to work around the buggy behaviour, I haven't been able to think up an example of that yet 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about this and considered some examples. It seems like it wouldn't break any code we looked at in our quick review, so I'm going to call this a bugfix 👍

Copy link
Contributor

@mixonic mixonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kevinansfield!

@@ -354,7 +354,7 @@ test('editor parses HTML post using parser plugins', (assert) => {
editor = new Editor({html, parserPlugins: [parserPlugin]});
assert.ok(!!editor.post, 'editor loads post');

assert.deepEqual(seenTagNames, ['TEXTAREA', 'IMG']);
assert.deepEqual(seenTagNames, ['P', 'TEXTAREA', 'IMG']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about this and considered some examples. It seems like it wouldn't break any code we looked at in our quick review, so I'm going to call this a bugfix 👍

@mixonic mixonic merged commit 9b4231e into bustle:master Jun 21, 2018
@sdhull
Copy link

sdhull commented Jun 25, 2018

Looking forward to trying parserPlugins with this update, thanks @kevinansfield!!

We found that when our users pasted in <b> or <i> tags, the could not un-bold or un-italicize that text because our toolbar toggles strong and em tags. I tried to add parser plugins that would convert b and i tags to strong and em respectively however I found that my plugins were never called for these tags.

I've worked around this by using computed properties (eg toggle boldTag instead of "strong") in Ember but it's not an ideal solution imo.

@gpoitch gpoitch mentioned this pull request Aug 31, 2022
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.

parser plugins should parse top-level unknown and void elements
4 participants