Problem
I am defining a document that describes a template, so I have a data structure similar to this simplified version:
type Node
= Text Styles String
| FirstNameHole
I parse this with a textWith declaration that looks like this simplified version:
Mark.textWith
{ view = Text
, replacements = Mark.commonReplacements
, inlines = [ Mark.annotation "firstName" (\children -> FirstNameHole) ]
}
100% of uses look like Hello, []{firstName}—the FirstNameHole node gets filled in by manipulating the document tree later. This means that children in the receiving function to Mark.annotation is an empty list!
Therefore, if I want to make the templated name bold, like Hello, *[]{firstName}*, my function never receives the styles. There is no content, so the list is empty. (Note that the FirstNameHole constructor does not receive Styles because I do not have the opportunity to receive this value in this case, but it is my intent for it to grow that field as soon as it can!)
Possible Solutions
We talked on Slack about this, and you came up with two ideas:
- changing the signature of
Mark.annotation to annotation : String -> (Styles -> List ( Styles, String ) -> result) -> Record result, where you guarantee that the styles "stack" from outer to inner. (I think this is logical implication but am not sure.)
- changing the calls of the mapping function to receive
[ ( outerStyles, "" ) ] when the children are empty.
I personally like the first method, but it does mean that you'd have to release 4.0.0 earlier than you maybe want!
Problem
I am defining a document that describes a template, so I have a data structure similar to this simplified version:
I parse this with a
textWithdeclaration that looks like this simplified version:100% of uses look like
Hello, []{firstName}—theFirstNameHolenode gets filled in by manipulating the document tree later. This means thatchildrenin the receiving function toMark.annotationis an empty list!Therefore, if I want to make the templated name bold, like
Hello, *[]{firstName}*, my function never receives the styles. There is no content, so the list is empty. (Note that theFirstNameHoleconstructor does not receiveStylesbecause I do not have the opportunity to receive this value in this case, but it is my intent for it to grow that field as soon as it can!)Possible Solutions
We talked on Slack about this, and you came up with two ideas:
Mark.annotationtoannotation : String -> (Styles -> List ( Styles, String ) -> result) -> Record result, where you guarantee that the styles "stack" from outer to inner. (I think this is logical implication but am not sure.)[ ( outerStyles, "" ) ]when the children are empty.I personally like the first method, but it does mean that you'd have to release 4.0.0 earlier than you maybe want!