Class DOMDocTypeFormatter

java.lang.Object
org.eclipse.lemminx.services.format.DOMDocTypeFormatter

public class DOMDocTypeFormatter extends Object
Formats DOCTYPE declarations and DTD content.

Handles two contexts:

  • Inline DOCTYPE — a <!DOCTYPE ...> declaration inside an XML document. The declaration is indented relative to its parent, parameters are separated by single spaces, and quotes are enforced.
     <!DOCTYPE note SYSTEM "note.dtd">
     
  • DTD file / internal subset — DTD declarations (<!ELEMENT>, <!ENTITY>, <!ATTLIST>, <!NOTATION>) are formatted with proper indentation, single-space parameter separation, and quote enforcement.
     <!DOCTYPE person [
       <!ELEMENT person (name, age)>
       <!ENTITY AUTHOR "John Doe">
     ]>
     
Author:
Angelo ZERR
  • Constructor Details

    • DOMDocTypeFormatter

      public DOMDocTypeFormatter(XMLFormatterDocument formatterDocument)
      Creates a new DOCTYPE formatter.
      Parameters:
      formatterDocument - the parent formatter document (provides settings and edit helpers).
  • Method Details

    • formatDocType

      public void formatDocType(DOMDocumentType docType, XMLFormattingConstraints parentConstraints, int start, int end, List<org.eclipse.lsp4j.TextEdit> edits)
      Formats a DOCTYPE declaration: indentation, parameter spacing, internal subset, and closing bracket.

      For XML documents, the DOCTYPE is indented relative to its parent. For standalone DTD files, only the child declarations are formatted.

      Use case (XML with DOCTYPE):

         <!DOCTYPE  note  SYSTEM  "note.dtd" >
       →
       <!DOCTYPE note SYSTEM "note.dtd">
       

      Use case (internal subset closing):

       <!DOCTYPE person [
         <!ENTITY AUTHOR "John Doe">  ]  >
       →
       <!DOCTYPE person [
         <!ENTITY AUTHOR "John Doe">
       ]>
       
      Parameters:
      docType - the DOCTYPE node to format.
      parentConstraints - the parent's formatting constraints.
      start - the start offset of the formatting range.
      end - the end offset of the formatting range.
      edits - the list of text edits to populate.