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

Escape text that should not be interpreted as Wiki syntax #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

th-we
Copy link

@th-we th-we commented Jan 2, 2020

This is not intended as a ready-to-merge pull request – it still needs some work and I'd like some feedback.

When I type __foo//bar%% into the WYSIWYG editor, then a JSON structure as in the new test file unformatted.json is sent. This needs to be escaped. I modified getInnerSyntax() to do just that. Ist das im Sinne des Erfinders?

This works, but it can not be tested in the same way as the other pairs of txt/json files because roundtripping will result in a different JSON structure that splits up the string into five sections, three of them marked as "unformatted".

I see several options how to make this work:

  • Write a separate test in PHP for this feature
  • Introduce files with "double extensions" .renderer.json and .jsonParser.json that are only intended for renderer.test.php or jsonParser.test.php
  • A quite radical approach: Get rid of the "unformatted" mark altogether because unformatted text will render correctly when sent like in unformatted.json with the getInnerSyntax() function from this pull request.

@splitbrain
Copy link
Member

I understand the sentiment, but the implementation will not solve the underlying problem.

In a WYSIWYG editor you would expect to be able to type and have everything treated as "normal" text unless you apply some special formatting. To do that, everything that has "special" in wiki syntax needs to be escaped when typed in the WYSIWYG editor.

Your approach is too naive to solve this. You hardcode what is "special" but in reality it is not as simple because every plugin can introduce its own syntax. The regex would need to be built from the syntax definitions of all plugins (and core syntax).

I don't think it would be impossible to do so, but it is much more complex than this. Basically we'd need a PHP component that builds a compound regex for everything that is "special" eg, the open/close/special expressions plugins register in their connectTo methods (and maybe the postConnect method, too). Basically we need to do what the Lexer class in our Parser does (it probably could be reused for that).

@th-we
Copy link
Author

th-we commented Jan 6, 2020

Here is an example why I think this needs to be addressed. Let's say a user inputs this:

grafik

What is saved is this:

Check the following files:

  * __foo.txt
  * __bar.txt

And as expected, that's parsed back to the following by the Prosemirror plugin:

grafik

But it gets a little worse because the next time this is edited with the WYSIWYG plugin, this is what's saved:

Check the following files:

  * __foo.txt   * __bar.txt

My point is: Native syntax (that the WYSIWYG plugin recognizes and parses into the proper markup) should be understood and escaped properly. Anything else should be left alone. For example, I'm not saying that something like {{tag>foo}} should be parsed or escaped in any way (though it would be great to allow plugins to make their syntax known to the editor).

Do I understand your argument correctly that you don't want to escape core syntax because plugins might use syntax that's ambiguous and in conflict with core syntax – say they use three underscores ___? Then the WYSIWYG editor will misrender and potentially mess it up when saving anyway, as can be seen above.

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.

2 participants