Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shiny nesting a link within a paragraph has unwanted whitespace

I'm building a Shiny app with some dynamically generated HTML which includes a link in mid-sentence. Unfortunately if I use the tags functions to do this, every element has a space around it whether I want it or not.

For example, if I wanted to write

This is my favorite link ever!

One might think you could do this

p('This is my ', a(href = 'https://stackoverflow.com/', 'favorite link ever'), '!')

But this results in each element being on a separate line, which by the HTML spec means there will be a space rendered between each.

<p>
  This is my 
  <a href="https://stackoverflow.com/">favorite link ever</a>
  !
</p>

Which looks like this (note the space before the exclamation mark)

This is my favorite link ever !

Do I have to resort to using HTML(paste0(...)) to construct my HTML, or is there some technique to using the tags functions that I'm missing?

Thanks..

like image 271
Brian Stamper Avatar asked Aug 24 '16 20:08

Brian Stamper


1 Answers

This has been resolved by a new feature, a parameter called .noWS. Quoting Carson Sievert:

you can now do:

p('This is my ', a(href = 'https://stackoverflow.com/', 'favorite link ever', .noWS = "outside"), '!', .noWS = c("after-begin", "before-end")) 

which yields

<p>This is my <a href="https://stackoverflow.com/">favorite link ever</a>!</p>

More information on the .noWS parameter can be found at the pull request.

like image 74
Brian Stamper Avatar answered Oct 04 '22 03:10

Brian Stamper