Thank you very much marijn for taking time for an answer ☆
I don’t understand what you mean by recursive structure
By recursive structure, I mean that the innerHTML of <ruby>
is fundamentally a recursion of text
followed by its <rt></rt>
annotation tags like:
text1<rt>annotation1</rt>text2<rt>annotation2</rt> ... etc. ... etc. ... infinite
recursive here means “it is possibly infinite” but following the same structure.
You could try making <rt>
its own node
I did!
I have succeeded in making what I wanted as a node.
But I think it is not appropriate for semantical also for verbosity reasons:
<rt>
are annotations as they are mostly indications of prononciation.
[in japanese, as in other ideographic languages, readers might not know how to pronounce complex characters, therefore annotations are welcome]
[also when writers litterally transcribe the pronunciation of a uncommon word from another language into japanese, readers might not figure out its original spelling so that annotations helps disambiguation about the original terms that it refers to]. [that the present example]
As so, it is not part of the text itself, the same way a link is to an anchor.
If I am not mistaken, in Prosemirror, links are treated are marks, aren’t they?
That is why I choosed to move from a node implementation to a marks implementation.
I ignore <rt>
tags [see: ignore: true
]:
I want them to be attributes
, as link addresses for anchors.
From a size point of view, in a text that may have lots of <ruby>
tags like this one, marks are smaller and easier to read.
They can also be coupled nicely with links or other marks.
To give an more precise idea, may be <ruby>
tags can be described as structured as kind of tables
.
As a solution, one may think of <ruby>
tag as a recursion of 3 <ruby>
tags:
<ruby lang="ja">ルネ<rt rtlang="fr">René</rt></ruby>
<ruby lang="ja">=<rt rtlang="fr">-</rt></ruby>
<ruby lang="ja">アントワーヌ<rt rtlang="fr">Antoine</rt></ruby>
that would have omitted middle </ruby><ruby lang="ja>
redundancy.
A <ruby>
tag would have to output as shown in previous post [see below]:
{
"type": "text",
"marks": [
{
"type": "rubylang",
"attrs": {
"lang": "ja",
"rt": "René",
"rtlang": "fr"
}
}
],
"text": "ルネ"
},
{
"type": "text",
"marks": [
{
"type": "rubylang",
"attrs": {
"lang": "ja",
"rt": "-",
"rtlang": "fr"
}
}
],
"text": "="
},
{
"type": "text",
"marks": [
{
"type": "rubylang",
"attrs": {
"lang": "ja",
"rt": "Antoine",
"rtlang": "fr"
}
}
],
"text": "アントワーヌ"
},
What I tried to do:
I looked foward to trim the text of the innerHTML <ruby>
tag before the first <rt>
tag to have [text1, annotation1], return it, then recurse on [text2, annotation2] … etc. … etc. … .
Problem being that I have to recurse on <ruby>
which is not possible.
Therefore, I should probably:
- call the marks
rubylang
but
- target
<rt>
tags,
- set the parsed text as a
node attrs
called rt
,
- find the immediate parent text before the
<rt>
tag after the previous immediate <ruby>
or <rt>
tag,
- take this text and set it as text of reference for the operation.
What about that?
I don’t really see how I can do that right now that is why I asked help.
The solution must be somewhere in between the parent child relation ship of <ruby>
and <rt>
.
I have trouble in figuring what can be the node syntax for toDOM
in the docs; it would be clearer with examples that would not be arrays but strings and DOM object [I could not find any].
About Editing, I am thinking of an implementation similar to what exists for links.