GithubHelp home page GithubHelp logo

fabianlauer / vs-code-xml-format Goto Github PK

View Code? Open in Web Editor NEW
7.0 7.0 5.0 2.37 MB

Simple XML formatter for Visual Studio Code.

Home Page: https://marketplace.visualstudio.com/items/fabianlauer.vs-code-xml-format

License: MIT License

TypeScript 100.00%
formatter vscode vscode-extension xml

vs-code-xml-format's People

Contributors

wade-ryan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vs-code-xml-format's Issues

Sort attributes alphabetically

Hi!

Firstly, thanks for this simple, little extension. I'm using it for an Ionic2 project where an XML gets generated when running certain commands. For some reason it's always generated a bit differently and makes a mess out of commits. The biggest difference seems to be the order of attributes. It would be nice if the formatter would consistently order these attributes the same way, so I could format the file if there are any changes and get a clearer view of what actually changed.

limit line length

I have a tag which as many attributes. Currently this is formatted to one long line where I have to scroll for reading the whole thing. It would be nice if the formatter could break the line into multiple ones.

Example

Current result after formatting:

<View controllerName="opensap.manageproducts.controller.Object" xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core" xmlns:form="sap.ui.layout.form" xmlns:semantic="sap.m.semantic">

Required result:

<View controllerName="opensap.manageproducts.controller.Object" xmlns="sap.m"  
      xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core" xmlns:form="sap.ui.layout.form" 
      xmlns:semantic="sap.m.semantic">

Maybe you can make use of a global line length value in VS code?

Thanks for your work!

cannot format long XML

Long XML files are not formatted.
Steps:

  1. Open a long XML file
  2. Set language to XML
  3. press command+shift+p / ctrl+shift+p and type 'Format Code'

The option doesn't even show. The same XML can be formatted in Sublime.

Comments are being removed

First of all, great extension! ๐Ÿ‘

If you have comments inside the XML file, they are removed. It doesn't matter if the comments are commented nodes or simply simple comments.

Thanks in advance.

"Run Build Task" does not open "OUTPUT" window

With this extension enabled, running the Build Task is no longer automatically opens the OUTPUT window in vscode. By simply disabling this extension, the OUTPUT window is opened as expected.

The instructions probably need an update

Hi Fabian !

I just installed your plugin for VS Code 1.20.1 on Windows 10 64 bits. First of all, it wasn't Ctrl+Alt+P that brought me the console but Ctrl+Shift+P, then when I typed 'Format Code', no command was found, well, because it's rather 'Format Document' (mapped to Shift+Alt+F).

You may have to change your Readme file.

No newline for values

Hello,

the 0.1.1 update seems to work pretty well and addresses some of the previous issues.
But there is one thing now that I'd like to be how it was in the previous version:

Before:
unbenannt

After:
unbenannt

So the values all get a new line which is not the usual way a xml looks like in my understanding: http://www.w3schools.com/xml/
Maybe this could even lead to reading errors? (Trailing whitespace and stuff, I don't know)
But it would come in handy to have some option to change this behaviour.

Format on save is breaking .csproj file in VS Code projects

Perhaps I can modify a setting, but in the event anyone else has an issue, when opening and adding code directly to a .NET Core .csproj file, on save the formatting breaks and during dotnet restore the following error is thrown as it adds hard returns and spaces around portions of code.

C:\Program Files\dotnet\sdk\1.0.1\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\Microsoft.NET.Sdk.Publish.targets(90,5): error MSB4184: The expression "[System.IO.Path]::GetFullPath(C:\test\obj\Debug\ [C:\test\test.csproj]
C:\Program Files\dotnet\sdk\1.0.1\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\Microsoft.NET.Sdk.Publish.targets(90,5): error MSB4184: netcoreapp1.1 [C:\test\test.csproj]
C:\Program Files\dotnet\sdk\1.0.1\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\Microsoft.NET.Sdk.Publish.targets(90,5): error MSB4184: \PubTmp)" cannot be evaluated. Illegal characters in path. Parameter name: path [C:\test\test.csproj]

Formatting is Removing Element Prefixes

If I have an XML document like this:

<?xml version="1.0" encoding="utf-8"?>
<Foo xmlns:f="http://foo.com/ns" xmlns="urn:epcglobal:epcis:xsd:1">
<Element xmlns="">
<Parent>
<f:Other>
</f:Other>
</Parent>
</Element>
</Foo>

And I then format it, it looks like this (notice the missing f: prefix on Other):

<?xml version="1.0" encoding="utf-8"?>
<Foo xmlns:f="http://foo.com/ns" xmlns="urn:epcglobal:epcis:xsd:1">
	<Element xmlns="">
		<Parent>
			<Other>
			</Other>
		</Parent>
	</Element>
</Foo>

This is obviously a contrived example, but we are dealing with an external company which embeds an element of their own namespace inside an element in a different namespace. VS 2017 handles this without issue.

Attribute ending in backslash fails formatting

An attribute like:

<absPath url="D:\Users\kgunders\Documents\MR\Projects\HyperLinkSheets"

Will cause the following error:

XML formatting failed: at line 2, column 694: namespace prefix must be followed by a tag name.

Here is more context from the problematic XML:

    <Choice Requires="x15">
        <absPath url="D:\Users\kgunders\Documents\MR\Projects\HyperLinkSheets\" xmlns:x15ac="http://schemas.microsoft.com/office/spreadsheetml/2010/11/ac" />
    </Choice>

A work around is to temporarily add a character after the backslash, format, and remove the extra character.

Use the format contribution API

Instead of adding a new commend, better add yourself as a formatter provider

vscode.languages.registerDocumentFormattingEditProvider('xml', ...)
vscode.languages.registerDocumentRangeFormattingEditProvider('xml', ...)

Yes then get invoked on the built-in Format command.

You can have a look at my css formatter extension:
https://github.com/aeschli/vscode-css-formatter/

Node containing a period fails formatting

Almost like Issue #6.

A node like

<system.webServer>
<!-- .... -->
</system.webServer>

Will cause an error and will not format the document.

XML formatting failed: at line #, column #; expected whitespace or end of opening tag.

Work around would be to simply remove the period from the nodes, format the document, then add them back.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.