ocsigen / tyxml

Build valid HTML and SVG documents
https://ocsigen.org/tyxml/
Other
163 stars 57 forks source link

Avoid breaking between text nodes #300

Open Julow opened 2 years ago

Julow commented 2 years ago

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.

Drup commented 2 years ago

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 ?