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

Can this be used to convert a JSON String+Points to HTML? #4

Open
thure opened this issue Jun 8, 2017 · 2 comments
Open

Can this be used to convert a JSON String+Points to HTML? #4

thure opened this issue Jun 8, 2017 · 2 comments

Comments

@thure
Copy link
Contributor

thure commented Jun 8, 2017

It would help us immensely to be able to convert HTML to a String+Points and back. This would enable us to perform Sememe link interpolation and text range formatting in a platform-independent way, i.e. it can become both HTML and an NSAttributedString (and also whatever it is Android uses, which is apparently equivalent).

Essentially, we want:

<ul>
  <li>
    <a href="/squirrels">Squirrels</a>
  </li>
  <li>…and other things.</li>
</ul>

to become:

{
  "text": "Squirrels…and other things.",
  "points": {
    "starts": [0, 0, 0, 9],
    "ends": [9, 9, 27, 27],
    "data": ["ul", "li", "a:href=\"/squirrels\"", "li"]
  }

…and back again, i.e. stacking order is preserved.

@thure
Copy link
Contributor Author

thure commented Jun 8, 2017

@andreashaese, this would interest you.

@thure
Copy link
Contributor Author

thure commented Jun 8, 2017

We can then define a number of filters:

  • Block-level HTML nodes should be applied first, since these should not begin or end any differently than from when they were derived.
  • Sememe matches and links should be applied next since if they point to the same resource they should remain intact except if they cross between block-level nodes.
  • Formatting can be applied last, since it's okay to break these up.

This means that we should resolve any links with Sememe matches in advance. If a Sememe match overlaps with a link, we'll probably want to drop the link unless the same match has already occurred earlier in the string.

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