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

Make pragmas look clickable in docs #8176

Merged
merged 6 commits into from
Jul 17, 2018
Merged

Make pragmas look clickable in docs #8176

merged 6 commits into from
Jul 17, 2018

Conversation

Quelklef
Copy link
Contributor

@Quelklef Quelklef commented Jul 1, 2018

Hopefully I found the right file!

In documentation, the clickable {..} pragmas currently don't look clickable. They look like normal code and, given that it's not unreasonable to think that {..} is valid (if superfluous) code, that's what some users might think. I sure did.

@Araq
Copy link
Member

Araq commented Jul 2, 2018

Sorry, can you give us some nice before-after screenshots? :-)

@Quelklef
Copy link
Contributor Author

Quelklef commented Jul 2, 2018

It's nothing too wild...

Pragmas hidden
Pragmas shown

@Quelklef
Copy link
Contributor Author

Quelklef commented Jul 2, 2018

A small alternative is to have a line between the begin and end pragma tags:

image
image

But it doesn't look as clean when the pragmas are shown. I could try to make the open pragma also have a border when the pragmas are shown, but I'm not sure how the clicking quite works yet.

@dom96
Copy link
Contributor

dom96 commented Jul 2, 2018

Wouldn't it make more sense to add a dotted line beneath these?

@Quelklef
Copy link
Contributor Author

Quelklef commented Jul 2, 2018

That could also work:

screenshot from 2018-07-02 15-07-13
screenshot from 2018-07-02 15-07-40

This is subtler but emphasises that the clickable pragmas are still part of the code.

@Araq
Copy link
Member

Araq commented Jul 3, 2018

The line between the dots is better, but still too subtle.

@dom96
Copy link
Contributor

dom96 commented Jul 3, 2018

Maybe something like this?

screen shot 2018-07-03 at 12 52 28

Alternatives:

screen shot 2018-07-03 at 12 53 10

screen shot 2018-07-03 at 12 52 52

@Quelklef
Copy link
Contributor Author

Quelklef commented Jul 3, 2018

Or perhaps something like:
screenshot from 2018-07-03 07-59-38
screenshot from 2018-07-03 08-01-41
It's terser, but looks a little strange with ... between two .s.

A possible resolution is (with the open graphics unchanged):
screenshot from 2018-07-03 08-03-37
but then closed pragmas pragmas aren't {. and .}...

@Araq
Copy link
Member

Araq commented Jul 3, 2018

A possible resolution is (with the open graphics unchanged):

Yeah, I like this solution best.

@dom96
Copy link
Contributor

dom96 commented Jul 3, 2018

Yeah, I like this solution best.

Same.

@Quelklef
Copy link
Contributor Author

Quelklef commented Jul 3, 2018

If we're going with this, I think it's important to address one thing:

Clicking between the braces to reveal the pragmas signifies (to me at least) that one should click between the braces again to hide the pragmas. So the shown content should be clickable rather than the braces.

It would be a little weird, though, and frankly I don’t think doing it this way is a great idea. The content shown is conceptually that--content, not navigation. However, I'm not sure a great alternative. Show content on hover-on and hide it in hover-off would work, but that's also a bit janky.

@Araq
Copy link
Member

Araq commented Jul 3, 2018

If we're going with this, I think it's important to address one thing:

Clicking between the braces to reveal the pragmas signifies (to me at least) that one should click between the braces again to hide the pragmas. So the shown content should be clickable rather than the braces.

Let's just use {.+.} then and expanded {.- noSideEffect, more, stuff.} or something along these lines to give us enough visual clues.

@dom96
Copy link
Contributor

dom96 commented Jul 3, 2018

Nah, there is little need to hide the pragma after it has been shown. I say just keep the pragmas there with no option to hide them.

@Araq
Copy link
Member

Araq commented Jul 3, 2018

Or that, ok.

@Quelklef
Copy link
Contributor Author

Quelklef commented Jul 3, 2018

OK to change docgen.nim for this, or should be pure JS/CSS?

@dom96
Copy link
Contributor

dom96 commented Jul 3, 2018

We don't use JS when we can help it.

@Quelklef
Copy link
Contributor Author

Quelklef commented Jul 3, 2018

Unfortunately, because CSS is nondeterministic, I couldn't style it quite as nicely as I'd have liked, but here is the current state:

screenshot from 2018-07-03 17-28-28

@@ -1330,15 +1330,23 @@ dt pre > span.Operator ~ span.Identifier {
background-repeat: no-repeat;
background-image: url("data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA==");
margin-bottom: -5px; }
<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You committed some merge conflicts by mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, dammit. My bad. Will fix now.

}
=======
>>>>>>> Visual cues at hidden pragmas in docs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See those "<<<<<<<" and ">>>>>>>".

## Remove leading whitespace and trailing newlines from every line
result = ""
for line in html.split("\n"):
for i, c in line:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two space indent

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use splitLines and strip.

@@ -222,6 +222,10 @@ proc getPlainDocstring(n: PNode): string =
result = getPlainDocstring(n.sons[i])
if result.len > 0: return

func htmlCollapse(html: string): string =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use func, it's too new. Also it's used nowhere else in docgen.nim.

@@ -222,6 +222,10 @@ proc getPlainDocstring(n: PNode): string =
result = getPlainDocstring(n.sons[i])
if result.len > 0: return

func htmlCollapse(html: string): string =
## Strip whitespace and remove trailing newlines from every line
return html.splitLines().mapIt(strip(it)).join("")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this required anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation has terrible performance. ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote it so I could format the HTML later in the code. Since that HTML ends up inside of a <pre>, it has to be collapsed.

The poor performance is from the string concatenation, yes? I should be using result.add?

Copy link
Contributor Author

@Quelklef Quelklef Jul 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, a quick benchmark on my machine shows a ~1.6x speedup using result.add, except when in -d:release, in which case it's about the same or slower! So I'm not totally sure what optimizations you're looking for?

@Quelklef
Copy link
Contributor Author

Quelklef commented Jul 16, 2018

Ah, some styling that I thought was fixed is acting up again. Don't merge yet.

@Quelklef
Copy link
Contributor Author

Quelklef commented Jul 17, 2018

It should be good now. Unfortunately, I only have Chrome on my dev laptop so I have only tested on Chrome. I figure the changes are simple enough that it shouldn't be a problem. I can rig something up to do cross-browser testing if you'd like, though.

@Quelklef
Copy link
Contributor Author

Update: apparently I also have Firefox 58.0 installed. It looks fine.

@Araq Araq merged commit f2b6efb into nim-lang:devel Jul 17, 2018
@timotheecour timotheecour mentioned this pull request Aug 23, 2018
21 tasks
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 this pull request may close these issues.

None yet

4 participants