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

htmlTemplate not respecting indentation #57

Closed
ramnathv opened this issue Apr 15, 2016 · 3 comments · Fixed by #154
Closed

htmlTemplate not respecting indentation #57

ramnathv opened this issue Apr 15, 2016 · 3 comments · Fixed by #154

Comments

@ramnathv
Copy link
Contributor

Consider the following example.

library(htmltools)
template <- "
<div>
  <span>Hello</span>
  <span>{{ user }}</span>
</div>
"
htmlTemplate(text_ = template, user = 'Jane Doe')

It renders as shown below

<div>
  <span>Hello</span>
  <span>
Jane Doe
</span>
</div>

I would have expected htmlTemplate to respect the indentation and instead render

<div>
  <span>Hello</span>
  <span>Jane Doe</span>
</div>
@wch
Copy link
Collaborator

wch commented Apr 15, 2016

Hm, that was a design choice to add whitespace around the returned values from R code blocks, although I can see why you'd want it to not do that. Now that I think about it, I'm not sure why we decided to add whitespace, since it doesn't seem advantageous in any situations I can think of.

@wch
Copy link
Collaborator

wch commented Apr 15, 2016

Now that I look at the code again, it's a little more clear why: it returns a tagList where the pieces alternate between raw HTML and the returned values from the code blocks. For example:

> user <- "Jane Doe"
> template <- "<span>{{ user }}</span>"
> str(htmlTemplate(text_ = template, user = 'Jane Doe'))
List of 1
 $ :List of 3
  ..$ <span> :Classes 'html', 'character'  atomic [1:1] <span>
  .. .. ..- attr(*, "html")= logi TRUE
  ..$  user  : chr "Jane Doe"
  ..$ </span>:Classes 'html', 'character'  atomic [1:1] </span>
  .. .. ..- attr(*, "html")= logi TRUE
 - attr(*, "class")= chr [1:2] "shiny.tag.list" "list"

So the rendering behavior for tagLists would need to be changed.

@jcheng5
Copy link
Member

jcheng5 commented Apr 15, 2016

When we revisit the excess-whitespace issue in general I bet a nice fix for this issue will fall out as well. I think we will need the ability for tag objects to "eat" the whitespace to either side, we can have all the HTML() blocks in this case eat both sides.

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 a pull request may close this issue.

3 participants