xml attributes on new line

Hi! @marijn, I have an xml document. Attributes are displayed in one line by default. Example:

<?xml version="1.0"?>
<Message>
	<TMsg SelfNumber="11" AlienNumber="10" Enterprise="ODY" GUID="{553ADDF4-CA54-4D61-AD1D-DE1F0B0A8A1C}" PreviousZvkId="0" DeviceState="dsNone" Grounding="zgGrounding" RepairReadiness="DD" TransferType="ttForAgree">
		<CreateDate>2023-08-30T13:53:00.000Z</CreateDate>
		<Notes>
			<TNoteShort Ident="SDR" EntIdent="ODY">
				<LongText>123</LongText>
				<CreateDate>2023-08-30T13:53:27.131Z</CreateDate>
			</TNoteShort>
		</Notes>
	</TMsg>
</Message>

How to make each attribute be on a new line?

<?xml version="1.0"?>
<Message>
	<TMsg 
	    SelfNumber="11" 
	    AlienNumber="10" 
	    Enterprise="ODY" 
	    GUID="{553ADDF4-CA54-4D61-AD1D-DE1F0B0A8A1C}" 
	    PreviousZvkId="0" 
	    DeviceState="dsNone" 
	    Grounding="zgGrounding"
	    RepairReadiness="DD" 
	    TransferType="ttForAgree">
		<CreateDate>2023-08-30T13:53:00.000Z</CreateDate>
		<Notes>
			<TNoteShort 
			    Ident="SDR" 
			    EntIdent="ODY">
				<LongText>123</LongText>
				<CreateDate>2023-08-30T13:53:27.131Z</CreateDate>
			</TNoteShort>
		</Notes>
	</TMsg>
</Message>

Thank you!

Reformatting is not something this library does. You’d need to find an XML formatter or write something like that yourself.

I did this

private xmlPrettyAttributes(): Extension {
        let isTurnOn = true;

        return linter(view => {

            if (isTurnOn) { // execute 1 time
                let textLineWithTabs: string; 
                const customTab = 1; 
                const changeAttributeTabs: TransactionSpec[] = [];

                syntaxTree(view.state).cursor().iterate(node => {
                    const doc = view.state.doc;

                    if (node.name === 'OpenTag') {
                        textLineWithTabs = doc.lineAt(node.from).text;
                    }

                    if (node.name === 'AttributeName') {
                        const attributeName = this.getElementAsString(doc, node.from, node.to);
                        const textLine = doc.lineAt(node.from).text.trim();
                        const getDefaultTab = textLineWithTabs.replace(/[^\t]/g, '');

                        if (attributeName && !textLine.startsWith(attributeName)) {
                            const setTab = '\t'.repeat(getDefaultTab.length + customTab);
                            changeAttributeTabs.push(
                                {
                                    changes: {from: node.from, insert: '\n'}
                                },
                                {
                                    changes: {from: node.from, insert: setTab}
                                });
                        }
                    }
                });

                if (changeAttributeTabs.length) {
                    view.dispatch(...changeAttributeTabs);
                }
            }

            isTurnOn = false;

            return [];
        });
    }

}