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

Unicode normalization of content #895

Open
nichtich opened this issue Apr 27, 2021 · 1 comment
Open

Unicode normalization of content #895

nichtich opened this issue Apr 27, 2021 · 1 comment

Comments

@nichtich
Copy link

What are the results of this discussion?

The character position within a Unicode string depends on whether the string is normalized and which Unicode normalization form is used. atjson should specify to normalize content strings to avoid character position mismatch and to ensure same content results in same character sequence.

When are two content strings assumed to be equivalent? Does atjson recommend or require Unicode normalization form and which?
I recommend NFC (Normalization Form Canonical Composition).

@blaine
Copy link
Contributor

blaine commented Apr 28, 2021

atjson currently uses UTF-16 code points per the ecmascript String type, so unicode-equivalent texts that use different unicode normalization (or unnormalized texts) are treated as entirely separate documents.

There are a couple of different possible ways to address this, but in practice, as long as text editors or tools using atjson do not normalize the content (or do so only using the insertText and deleteText methods), the system is internally consistent and specifying behaviour for this is unnecessary.

For an interchange format where the underlying text might be subject to modification independently from the annotations, or environments where it's necessary or desirable to normalize the unicode content string without using the atjson interface (I'm not sure I can think of a realistic example, but happy for suggestions!), one possible approach would be to add a new contentMimeType document attribute (or similar). This could be used to specify the mime-type of the content (and give a path to automatic handling of normalization, string offset behaviours, etc). One challenge with this approach is that while it's possible to specify a charset in addition to text/plain (e.g. "text/plain; charset=UTF-16") per RFC2231, I'm not aware of any standardized way to specify unicode normalization in a content type (my understanding is that charset in mime types must be one of the IANA registered types, none of which include normalization approaches)

That all said, so long as software that modifies an atjson document ensures that (1) the offsets align to UTF-16 code points per the ecmascript definition of strings and (2) any changes, e.g. unicode normalization, correctly update the offsets to account for any added or removed code points, then any other software operating on an atjson document would be able to correctly interpret and modify that document itself.

In practical terms, the insertion or removal of a single code point via a normalization process would simply increase or reduce by one all annotation offsets greater than the insertion offset.

The more complex case of normalization of a document with annotations that refer to code points within a composed character (i.e., grapheme) that is modified by normalization is an edge case that might warrant consideration, though we haven't yet encountered that use-case. My hunch is that any annotations that have start/end offsets within a unicode grapheme (i.e., not aligned to the start or end of the grapheme) would be unicode-specific annotations and as such could use the custom text insertion/deletion behaviours in order to implement the correct behaviour.

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

2 participants