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

Preserve whitespace when evaluating {{{data}}} #1800

Closed
BenRomberg opened this issue Nov 12, 2015 · 6 comments
Closed

Preserve whitespace when evaluating {{{data}}} #1800

BenRomberg opened this issue Nov 12, 2015 · 6 comments

Comments

@BenRomberg
Copy link

I have a use-case where I show indented code with white-space: pre. As such, preserving the whitespace in the rendered document is critical. Vue seems to trim the whitespace when evaluating {{{data}}} expressions with embedded HTML tags. I wonder if this is necessary or if there's a workaround available.

For now, I'm replacing all spaces in the beginning with   which is a very ugly workaround I'd like to get rid of.

Other than that I must say I'm pretty happy with Vue so far! Good work! :-)

@yyx990803
Copy link
Member

What whitespace are you referring to? I'm not really understanding what the problem is.

@BenRomberg
Copy link
Author

Consider this minimum example:

<template>
    <pre>{{{line}}}</pre>
</template>

<script>
module.exports = {
  data: function() {
    return {
      line: '   <span>this has whitespace</span>'
    }
  }
}
</script>

Note the whitespace in front of the <span> tag, which should be rendered but isn't. If I remove the <span> tags it works. This only happens when using {{{ in combination with embedded HTML tags.

@BenRomberg BenRomberg changed the title Preserve whitespace when evaluating {{data}} Preserve whitespace when evaluating {{{data}}} Nov 13, 2015
@simplesmiler
Copy link
Member

@BenRomberg Vue does somehow trim out spaces from the {{{ expression }}}, but you probably don't need triple braces in the first place, as you most likely don't want real <span> tags inside your <pre>, but rather want encoded &lt;span&gt;, which will display as <span>. And for that you need to use {{ expression }}: https://jsfiddle.net/simplesmiler/vr0hdg1h/

@BenRomberg
Copy link
Author

@simplesmiler thanks for chiming in.

I'm aware of the implications of {{{ and my usage of it is indeed intended.

@simplesmiler
Copy link
Member

@BenRomberg I don't get then why do you need the real <span>'s inside the <pre>. Syntax highlighting?

@BenRomberg
Copy link
Author

Thanks, works like a charm!

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

No branches or pull requests

3 participants