Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix processing instruction with attributes in formatting #331

Merged
merged 1 commit into from
Apr 3, 2019

Conversation

NikolasKomonen
Copy link
Contributor

@NikolasKomonen NikolasKomonen commented Mar 18, 2019

Fixes redhat-developer/vscode-xml#115

Also fixes an issue with the Prolog removing unknown attributes on format.

Signed-off-by: Nikolas [email protected]

@fbricon
Copy link
Contributor

fbricon commented Mar 18, 2019

why do you need to treat xml-stylesheet differently than any other PI?

@NikolasKomonen
Copy link
Contributor Author

NikolasKomonen commented Mar 18, 2019

@fbricon

Based off the wiki it looks like xml-stylesheet is a common processing instruction that is defined to have attributes. Other processing instructions have text content in them (<?mvn aaa bbb ccc ?>).

It helps in the parsing since we know how to parse after a certain PI name.

@fbricon
Copy link
Contributor

fbricon commented Mar 18, 2019

In http://www.sagehill.net/docbookxsl/ProcessingInstructions.html (linked from the wiki), you can see

Processing instructions
A processing instruction is a means of passing hints to the XSLT processor about how to handle something. XML permits the placement of processing instructions just about anywhere in a document. A processing instruction (sometimes referred to as a PI) uses a special syntax, , to indicate that it is not an element, comment, or text. For example:

<?dbfo bgcolor="#EEEEEE" ?>
The first word in a PI is the name. In this example, the name of the processing instruction is dbfo and the content is bgcolor="#EEEEEE". This style of PI content could be called a “pseudo attribute”, because it provides a name-value pair similar to a real attribute (which only elements can have). You can put several such pseudo attributes in one PI, or you can put each of them in their own PI.

So xml-stylesheet should not be a special case

@NikolasKomonen
Copy link
Contributor Author

@fbricon I know this is the case, but the regex in the xml specification considers the PI content as text.

What pr does is allow common PI declarations to be defined to be parsed with their attributes considered. If not then it defaults to saving all the content as a single string.

@fbricon
Copy link
Contributor

fbricon commented Mar 18, 2019

can't you split content by whitespace and then check if you have key/value patterns in each group?

@NikolasKomonen
Copy link
Contributor Author

NikolasKomonen commented Mar 19, 2019

@fbricon something like this wouldn't work in that case:

<?aaa b =   "123" c  ="234 ?>

To get around this it would require some backtracking in the parser, but we haven't done this yet for anything else.

@fbricon
Copy link
Contributor

fbricon commented Mar 20, 2019

Mar-20-2019 02-07-07

Should be the same behavior for all PIs

@NikolasKomonen
Copy link
Contributor Author

NikolasKomonen commented Mar 21, 2019

@fbricon What if there exists a PI's that looks like

<?whatever foo   bar  = hello ?>
<?whatever this    should not be   formatted ?>
<?whatever This thing = no formatting ?>

at what point should it decide to format the content inside?

@fbricon
Copy link
Contributor

fbricon commented Mar 28, 2019

any = sign you find indicates this is the middle of a key/value pair

@fbricon
Copy link
Contributor

fbricon commented Mar 28, 2019

I still think all PIs should be treated like xml-stylesheet. If somehow we got a complaint, we can revisit, but that seems the most sensible, logical behavior.

Fixes redhat-developer/vscode-xml/115

Signed-off-by: Nikolas <[email protected]>
@NikolasKomonen
Copy link
Contributor Author

@fbricon Updated, all PI's are formatted the same (not touched)

@fbricon fbricon added this to the v0.5.0 milestone Apr 3, 2019
@fbricon fbricon merged commit 6063992 into eclipse:master Apr 3, 2019
@NikolasKomonen NikolasKomonen deleted the styleSheetFormatting branch April 5, 2019 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatting removes xml-stylesheet processing instruction attributes
2 participants