tyxml icon indicating copy to clipboard operation
tyxml copied to clipboard

Avoid breaking between text nodes

Open Julow opened this issue 2 years ago • 1 comments

I've attempted a fix to https://github.com/ocsigen/tyxml/issues/288 but it isn't working in every cases, for example this example is still problematic:

      p ~a:[ a_class [ "some padding ............................" ] ] [ 
        txt "some text here"; span [ txt ". and here" ]
      ]

There's an extra space before the . when indentation is enabled. Also happens in a more common example (in Odoc):

  <p>This is a <a href="#">link</a>
  .

I don't think this can be solved on the printer side without adding metadata to node definitions, for example whether it is a "block" or "inline" element (defined for HTML only). Would this be reasonable ?

An other idea is to implicitly add txt " " nodes at the end of every block elements, which the printer could detect and decide how to break.

Julow avatar Feb 10 '22 17:02 Julow

Sorry for the very late answer.

I don't like the solution of inserting txt " " at arbitrary points.

I think the solution is indeed to have a list of "elements where white space matters" and "elements where it does not", make the printer take those list as arguments, and define the list in the respective modules. What do you think about that ?

Drup avatar Jun 21 '22 08:06 Drup