Skip to content

styling outside an annotation is not passed to the annotation function if there is no annotation content #32

Description

@BrianHicks

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:

  1. 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.)
  2. 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions