Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Taghelpers do not preserve whitespace around HTML attributes #563

Closed
kirthik opened this issue Oct 5, 2015 · 9 comments
Closed

Taghelpers do not preserve whitespace around HTML attributes #563

kirthik opened this issue Oct 5, 2015 · 9 comments

Comments

@kirthik
Copy link
Contributor

kirthik commented Oct 5, 2015

<div class =          "hey">

If I have a taghelper for div tag then my end output for the above razor code would be
<div class="hey">

Related to #123. Looks like tag helpers are not considering spaces surrounding equals.

@dougbu
Copy link
Contributor

dougbu commented Oct 5, 2015

@kirthik is there a parsing issue here? Or did you expect the spaces to be preserved in the generated HTML?

Put another way, did anything fail?

@kirthik
Copy link
Contributor Author

kirthik commented Oct 5, 2015

I was expecting spaces to be preserved in the generated HTML.

@Eilon
Copy link
Contributor

Eilon commented Oct 5, 2015

Does Razor attempt to do any preservation of whitespace in a tag? E.g. if I have:

<div
    foo      =                   "bar"
baz    =
      "qux"
>whatever</div>

Won't it always render

<div foo="bar" baz="qux">whatever</div>

?

@kirthik
Copy link
Contributor Author

kirthik commented Oct 5, 2015

Yes razor preserves white space in a tag now. We fixed that issue(#123) with this commit 08c8f9f

@Eilon
Copy link
Contributor

Eilon commented Oct 5, 2015

I know we now allow it, but does it actually ever get preserved in the rendering?

@kirthik
Copy link
Contributor Author

kirthik commented Oct 6, 2015

When I inspect html source for the razor code above, I see this

<div
     foo           =      "bar"
baz     =
     "qux"
>whatever</div>

not <div foo="bar" baz="qux">whatever</div>

@Eilon
Copy link
Contributor

Eilon commented Oct 6, 2015

Well <div> probably doesn't have a tag helper on it 😄

But same thing for <a href="">...</a> I think will show the whitespace is trimmed.

I talked to @dougbu and as far as he knows all whitespace is trimmed when a tag helper is used.

This would ultimately be a feature request that we could consider in a future version.

@dougbu
Copy link
Contributor

dougbu commented Oct 6, 2015

The feature would be somewhat analogous to preserving how attribute values are quoted in the .cshtml file: We'd need to extend IReadOnlyTagHelperAttribute and so on to expose information about whitespace before and after the = sign. Then RazorPage would need to do something with the extra information to generate the attribute appropriately.

Note "preserving how attribute values are quoted in the .cshtml file" is a significantly higher-value feature request we aren't even tracking at the moment. At least that one would avoid some special cases in RazorPage.

@danroth27 danroth27 changed the title Taghelpers do not correctly parse HTML attributes that have spaces surrounding the equals Taghelpers do not preserve whitespace around HTML attributes Oct 6, 2015
@danroth27 danroth27 added this to the Backlog milestone Oct 6, 2015
@rynowak
Copy link
Member

rynowak commented May 4, 2017

No plans to do this without significant feedback

@rynowak rynowak closed this as completed May 4, 2017
@rynowak rynowak removed this from the Backlog milestone Dec 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants