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

Feature Request/Suggestion: Provide a builtin-preprocessing tag to trim textcontent #651

Closed
UncleBill opened this issue Feb 17, 2017 · 2 comments

Comments

@UncleBill
Copy link

current

<template>
    <div class='box'>
        {{content}}
    </div>
</template>

output:

return n("div", {
            staticClass: "box"
        }, [t._v("\n  " + t._s(t.content) + "\n")])

what I want

return n("div", {
            staticClass: "box"
        }, [t._v(t._s(t.content))])

Suggestion

Wrap text content with a tag like <Text></Text>. The tag will be removed at webpack's compile-time.

<template>
    <div class='box'>
        <Text>{{content}}</Text>
    </div>
</template>

loader's configuration:

{
   query: {
      // default option
      textContentTrimmingTag: 'Text'
   }
}

vuejs/vue#3934

@yyx990803
Copy link
Member

See my comment - I don't think this will be supported.

@UncleBill
Copy link
Author

UncleBill commented Feb 19, 2017

I did read it before.

It's not a suggestion for vue but for vue-loader. It's kind of preprocessing.

<Text> and </Text> are just marks of textContent's ends.

<!-- #0 -->
<!-- nowadays, produces untrimmed textContent -->
<div>
  {{text}}
  <Child />
  Plain text
</div>

<!-- #1 -->
<!-- more beautiful than #2 -->
<!-- will be transformed into #2, textContent is trimmed! -->
<div>
  <Text>{{text}}</Text>
  <Child />
  <Text> Plain text</Text>
</div>

<!-- #2 -->
<div>{{text}}<Child /> Plain Text</div>

in the sense that it could be "unsafe" - the user may want to ignore whitespaces between tags, but not necessarily trimming all plain text, e.g inside <pre>

If users want to trim text node, they can use the marks, it would be "safe".

Ignoring additional whitespace nodes has a small perf gain, but trimming text doesn't do much in that aspect.

I just want the generated code cleaner. 😆

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

2 participants