-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add argument to suppress whitespace #131
Conversation
Use the `.noWS` attribute to strip whitespace from: - `before` the tag - `after` the tag - `after-begin` of the tag (no whitespace between begin tag and the first child) - `before-end` of the tag (no whitespace between last child and the beginning of the end tag) The .noWS attribute is valid on all tags and is a space-separated string containing any combination of the above four directives. Open issues/tasks: - Needs unit tests - API is gross - Need to decide on default behavior (automatic based on block/inline?) - savePosition() maybe should be done implicitly (every write() calls savePosition(), every writeWS() does not?)
Separated the logic of bookmarking/suppressing, and how those features are invoked, into two distinct R6 classes that are each easy to reason about independently. Also, the API surface area that the (already complicated) tagWrite function needs to worry about has been greatly decreased. Now, tagWrite just needs to call write() or writeWS(), and call eatWS() to eat all recent/upcoming whitespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly notes to myself but a few actual questions and opining about the API.
I did some quick performance tests and it looks like this slows things down quite a bit. I haven't profiled to see where the time is going, but I'm seeing 60-100% extra time taken relative to master:
|
c323515
to
7c0d985
Compare
7c0d985
to
9ddda7e
Compare
After a bit of Travis thrashing followed by a force-push-fest to clean up the commit mess... ready for rereview, @jcheng5! The one outstanding concern for me is the performance issue described in the comment above. I'm wondering if we should hold this PR back until we take on some of the C++ performance improvements. I think I could start on that work whether or not this is on master so long as we're not anticipating any serious conflicts to emerge in the coming couple of weeks. |
Runtime w/o .noWS specified improves ~15% Runtime w/ .noWS specified improves ~9% Still <= 70% slower than the original implementation w/o whitespace considerations.
I'm doing some experimentation on performance here. Raw performance notes from running this code:
By the end, it looks like we have an approach that will get us back to parity with master if we clean up that branch. master
binary connection-based
buffer-based instead of connection (b09ee)
buffer-based with periodic string collection (345eff0)
buffer-based with string collection and double-assign to avoid copies
Same with portable=FALSE (aa8c3ad)
Same after eliminating TextConnection and just using WS directly (de64260)
after removing R6 and using a closure directly (5e5bab0)
|
R/tags.R
Outdated
@@ -356,7 +366,8 @@ tag <- function(`_tag_name`, varArgs) { | |||
structure( | |||
list(name = `_tag_name`, | |||
attribs = attribs, | |||
children = children), | |||
children = children, | |||
.noWS = .noWS), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try omitting the .noWS
totally if NULL and see if that hashes in the test revert so we don't change everything.
@amrrs Oh, that's a good point. I think we'd actually need to add this feature to
renders like:
There's not currently a way AFAIK to remove the whitespace between |
What about space around |
@jcubic That's what I was referring to in my previous comment, sorry it wasn't clear. |
This PR adds a
.noWS
option to thetag()
function and to all the predefinedtags
. This parameter can be used to suppress whitespace around a particular tag. One such example:Note all the extra newlines and whitespace that got inserted around these tag elements. This would adversely affect how the tags get displayed in the browser. As of this PR, you can now do:
to render everything on one line. Note that the option is not inherited by child tags -- it only impacts the tag for which it's specified.
Valid
.noWS
options include:before
- before the opening tagafter
- after the closing tagafter-begin
- after the opening tagbefore-end
- before the closing tagoutside
- before the opening tag AND after the closing tagTODOs
.noWS
a formal argument instead of an undocumented attributeTesting Notes
(Note that testing of this PR and #132 should be done at once -- no need for separate validation.)
Create tags or reference existing tags with the
.noWS
option specified and watch the whitespace get removed!Try out all of the available
.noWS
options listed above to confirm that the behavior is as described.Printing out code like
tags$span("Click my '", tags$a(href="https://rstudio.com", "link", .noWS="outside"), "'.",
on the R command line is sufficient to confirm that the whitespace is properly getting suppressed as it should.