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

Some idea to allow extending MarkupNode with own cases? #3

Open
saltwat5r opened this issue Aug 1, 2017 · 7 comments
Open

Some idea to allow extending MarkupNode with own cases? #3

saltwat5r opened this issue Aug 1, 2017 · 7 comments
Labels

Comments

@saltwat5r
Copy link

As in the title 😄

@gonzalezreal
Copy link
Owner

That depends on what you want to add 😄. Could you please be more specific?

@saltwat5r
Copy link
Author

I.e. add case superscript([MarkupNode]) and many more.

@gonzalezreal
Copy link
Owner

Ok, so you want to add more delimiters. Implementing the superscript would involve the following:

  1. Add the character ^ in MarkupTokenizer
  2. Add a superscript([MarkupNode]) case to MarkupNode
  3. Customize the MarkupNode constructor to handle the ^ delimiter.
  4. Customize the MarkupRenderer to handle superscript nodes appropriately.
  5. Add the corresponding tests here and here.

After completing those steps you should be able to take text like Hello^*world*^ and obtain Helloworld.

@saltwat5r
Copy link
Author

I've done it in the same way, but I was wondering how to do it more flexible without modifying your code and add more cases by i.e. extensions for your classes :)

@gonzalezreal
Copy link
Owner

To be honest, I did not think about a generic way to extend the parser or renderer. Doing so will probably mean not using an enum for the nodes, as swift enums cannot be extended with additional cases. In any case, it is out of the scope and was not my intention when I published this library.

If you find an elegant and generic way to extend it, please do let me know. It is an interesting exercise.

@Kurt57
Copy link

Kurt57 commented Oct 29, 2018

@gonzalezreal how can I add an rule which looks like "TEXT" where "**" is the new delimiter. The focus on this question is that I use two characters as delimiter.

@gonzalezreal
Copy link
Owner

Hi @Kurt57,

That would involve substantial changes in MarkupTokenizer.

  • Refactor the delimiters constant into an array of strings (currently is a CharacterSet)
  • Refactor all the code relying in that constant.

Also it would require changing MarkupToken to accept strings as associated values instead of UnicodeScalar.

Finally, refactor all the code that depends on the MarkupToken (mainly the parser).

As you can see, a lot of work 😅

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

No branches or pull requests

3 participants