Here are the changes that implement #2174. A new serialization option is added to control indentation of attributes. The option name and the new layout are the same as in HTML Tidy:
the name is indent-attributes, with a default value of no.
the layout that is achieved by indent-attributes=yes puts the first attribute following the element name on the same line, while every subsequent attribute starts a new line, indented to align with the first attribute.
The order of attributes is unchanged. indent-attributes is ignored when processing serialization methods other than xml, xhtml, or html. It may not make much sense to use this option without using indent=yes as well, but the implementation here does neither enforce nor require that.
The following has been changed:
the new option is added as SerializerOptions.INDENT_ATTRIBUTES for parameter indent-attributes with default value no.
a new member Printoutput.lineLength keeps track of the length of the current line in codepoints.
maintaining lineLength is an additional task for PrintOutput.print(int cp). This must be done in PrintOutput, as well as in subclasses EncoderOutput and NewlineOutput.
MarkupSerializer.startOpen now remembers the current line length, after printing the element name, in new member indAttrLength. Again, this must also be done in subclasses.
the whitespace preceding an attribute is now printed in MarkupSerializer.delimitAttribute, and any indentation whitespace is added there, if asked for by the new option, plus the remembered line length has already increased, i.e. we are working on an attribute beyond the first one.
If this PR should be accepted, the documentation must be adapted, at least in these two locations:
Here are the changes that implement #2174. A new serialization option is added to control indentation of attributes. The option name and the new layout are the same as in HTML Tidy:
indent-attributes
, with a default value ofno
.indent-attributes=yes
puts the first attribute following the element name on the same line, while every subsequent attribute starts a new line, indented to align with the first attribute.The order of attributes is unchanged.
indent-attributes
is ignored when processing serialization methods other thanxml
,xhtml
, orhtml
. It may not make much sense to use this option without usingindent=yes
as well, but the implementation here does neither enforce nor require that.The following has been changed:
SerializerOptions.INDENT_ATTRIBUTES
for parameterindent-attributes
with default valueno
.Printoutput.lineLength
keeps track of the length of the current line in codepoints.lineLength
is an additional task forPrintOutput.print(int cp)
. This must be done inPrintOutput
, as well as in subclassesEncoderOutput
andNewlineOutput
.MarkupSerializer.startOpen
now remembers the current line length, after printing the element name, in new memberindAttrLength
. Again, this must also be done in subclasses.MarkupSerializer.delimitAttribute
, and any indentation whitespace is added there, if asked for by the new option, plus the remembered line length has already increased, i.e. we are working on an attribute beyond the first one.If this PR should be accepted, the documentation must be adapted, at least in these two locations: