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

doc: link to man pages #5073

Closed
wants to merge 1 commit into from
Closed

doc: link to man pages #5073

wants to merge 1 commit into from

Conversation

dcposch
Copy link
Contributor

@dcposch dcposch commented Feb 4, 2016

This changes the doc generator to automatically link references such as
open(2) to a man page on man7.org or freebsd.org

Fixes #4375

@dcposch
Copy link
Contributor Author

dcposch commented Feb 4, 2016

Before
image

After
image

@dcposch
Copy link
Contributor Author

dcposch commented Feb 4, 2016

// '<a href="http://man7.org/linux/man-pages/man2/open.2.html">open(2)</a>'
function getManLink(text) {
// It's safe to concatenate into HTML like this because `text` matches
var found = text.match(/([a-z]+)\(([0-9])\)/);
Copy link
Contributor

Choose a reason for hiding this comment

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

Only one digit inside the parenthesis? There could be more than one. Also, use \d

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 think man pages only go 1-8 actually

http://unix.stackexchange.com/questions/3586/what-do-the-numbers-in-a-man-page-mean

Changed it to use \d

@dcposch
Copy link
Contributor Author

dcposch commented Feb 4, 2016

@Fishrock123

// Handle references to man pages, eg "open(2)" or "lchmod(2)"
// Returns modified text, with such refs replace with HTML links
function linkManPages(text) {
return text.replace(/ [a-z]+\([0-9]\)/, getManLink);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of matching again in getManLink, grouping can be done here itself, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also what if there is more than one reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah good call, i changed it to /g

i did the grouping there to make it clear that name and number are safe to concat into an HTML string, but i'll just combine the two methods to keep things simple

@evanlucas
Copy link
Contributor

/cc @nodejs/documentation

@thefourtheye thefourtheye added the doc Issues and PRs related to the documentations. label Feb 4, 2016
@dcposch dcposch force-pushed the manpages branch 2 times, most recently from 7bc5a9d to 445a1e4 Compare February 4, 2016 13:05
@estliberitas
Copy link
Contributor

Would also be good to handle cases when POSIX call is wrapped in backquotes.

For, example in #5075 I did this with a sed and your solution is much better. 😉

@@ -165,10 +175,32 @@ function parseLists(input) {
}


// Syscalls which appear in the docs, but which only exist in BSD / OSX
var BSD_ONLY_SYSCALLS = ['lchmod'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: Now that we have Sets in core, we may be able to speed up this lookup.

Choose a reason for hiding this comment

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

Yeah, I would think that utilizing a Set or even an object would be faster here (assuming we get more items added to here as well.

var BSD_ONLY_SYSCALLS = new Set(['lchmod']);

...
if (BSD_ONLY_SYSCALLS.has(name)( {
  ...
} else {
...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@Fishrock123
Copy link
Contributor

I think every link should also have a [?] (<sup>[?]</sup>) link pointing towards some sort of doc on what a man page is. I.e. how to do man N thing and what that means in terms of different operating systems.

'&sektion=' + number + '">' + displayAs + '</a>';
} else {
return ' <a href="http://man7.org/linux/man-pages/man' + number + '/' +
name + '.' + number + '.html">' + displayAs + '</a>';
Copy link
Contributor

Choose a reason for hiding this comment

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

cc @bnoordhuis what so you think about these sources for generic man docs?

Choose a reason for hiding this comment

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

I was curious about that as well. I went through some digging on Man pages, so that particular set of docs is linked to from kernel.org as well. There's a bunch more sources for the Linux docs but I can't really find any official source. die.net for example.

Copy link
Member

Choose a reason for hiding this comment

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

freebsd.org and man7.org are the official man pages so +1 from me. For freebsd.org, consider linking to the https:// site.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@dcposch
Copy link
Contributor Author

dcposch commented Feb 4, 2016

@Fishrock123 dunno, some parts of the docs, like here, have a lot of man page links. I think it would look distracting for each of those to have a superscript.

@Fishrock123
Copy link
Contributor

Hmmm, then we should probably add a thing to "about these docs" at the very least.

// Returns modified text, with such refs replace with HTML links, for example
// '<a href="http://man7.org/linux/man-pages/man2/open.2.html">open(2)</a>'
function linkManPages(text) {
return text.replace(/ ([a-z]+)\((\d)\)/gm, function(match, name, number) {
Copy link
Member

Choose a reason for hiding this comment

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

Would the regex match if the markdown had a code snippet with, say, foo(1) in it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bnoordhuis yes

everything it matches currently is a syscall: #4375 (comment)

but i agree it's jank

Copy link
Contributor Author

Choose a reason for hiding this comment

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

NVM. Here's a place where it fails

doc/api/modules.markdown:var mySquare = square(2);

I'll change it to require special markup to generate the link, so we don't get false positives.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bnoordhuis actually it might be fine!

I just generated the docs and it seems that JS passes through the HTML syntax highlighter before it gets to linkManPages. The square(2) above doesn't turn into a link.

@dcposch
Copy link
Contributor Author

dcposch commented Feb 6, 2016

@Fishrock123 done


**Caveat:** some syscalls, like lchown(2), are BSD-specific. That means, for example, that `fs.lchown()` only works on Mac OSX and other BSD-derived systems, and is not available on Linux.

Most Unix syscalls have Windows equivalents, but behavior may differ on Windows relative to Linux and OSX. For an example of the subtle ways in which it's sometimes impossible to replace Unix syscall semantics on Windows, see [Node issue 4760](https://github.com/nodejs/node/issues/4760).
Copy link
Member

Choose a reason for hiding this comment

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

Can you wrap lines at 80 columns in this file?

@bnoordhuis
Copy link
Member

LGTM with style nits.

@jasnell
Copy link
Member

jasnell commented Feb 7, 2016

LGTM with @bnoordhuis' nits addressed

@dcposch
Copy link
Contributor Author

dcposch commented Feb 8, 2016

@bnoordhuis @jasnell fixed

LMK if you want me to squash this PR to a single commit

@DavidTPate
Copy link

LGTM

@@ -66,3 +66,19 @@ Every HTML file in the markdown has a corresponding JSON file with the
same data.
Copy link
Contributor

Choose a reason for hiding this comment

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

@estliberitas Hope you are taking care of this page as well :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@thefourtheye Np, will do soon )

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@thefourtheye Hi, I'm a bit out of context. I'll do the usual stuff I do for API pages. Also, once I structure what's on my mind, I'll add maybe a section to this page on how things should be formatted, etc. If it's not added yet, hah.

Sounds OK? Or I do not get what should be done, coz the only thing to be added here would be something like a cool guide on formatting the stuff. But I'm not sure if this page is appropriate for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah my bad. I just saw few linkable text on this page and reached out for your help. Perhaps we can leave this page as nothing much is needed here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Anyways, I'll continue my crusade on docs today and tomorrow. :)

On Sat, Feb 13, 2016, 08:59 thefourtheye [email protected] wrote:

In doc/api/documentation.markdown
#5073 (comment):

@@ -66,3 +66,19 @@ Every HTML file in the markdown has a corresponding JSON file with the
same data.

Ah my bad. I just saw few linkable text on this page and reached out for
your help. Perhaps we can leave this page as nothing much is needed here.


Reply to this email directly or view it on GitHub
https://github.com/nodejs/node/pull/5073/files#r52824032.

Sincerely,
Alexander Makarenko

@thefourtheye
Copy link
Contributor

LGTM

@silverwind
Copy link
Contributor

@dcposch please rebase you branch.

@a0viedo
Copy link
Member

a0viedo commented Feb 9, 2016

@dcposch if you could use a hand squashing your commits into one, please let me know

@dcposch
Copy link
Contributor Author

dcposch commented Feb 10, 2016

@a0viedo @silverwind done

@silverwind
Copy link
Contributor

Regarding the section Syscalls and man pages: I'd suggest moving it near the top of the fs page. I'm not sure the place below the stability index is really the right one for it, it feels out of place there.

pages (short for manual pages) which describe how the syscalls work.

**Caveat:** some syscalls, like lchown(2), are BSD-specific. That means, for
example, that `fs.lchown()` only works on Mac OSX and other BSD-derived systems,
Copy link
Member

Choose a reason for hiding this comment

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

Tiny nit: we write Mac OS X (space before X) almost everywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bnoordhuis fixed

@bnoordhuis
Copy link
Member

Changes LGTM sans nit. If other collaborators agree, please land it.

This changes the doc generator to automatically link references such as
`open(2)` to a man page on man7.org or freebsd.org
@dcposch
Copy link
Contributor Author

dcposch commented Feb 11, 2016

@silverwind dunno, syscalls are used elsewhere to (not just in fs) and @Fishrock123 wanted the explanation under About These Docs

@jasnell
Copy link
Member

jasnell commented Feb 15, 2016

Still LGTM

silverwind pushed a commit that referenced this pull request Feb 17, 2016
Fix missing links. Fix styling of printf() - once #5073 lands,
link to man page will be auto-generated. Fix several typos.

PR-URL: #5225
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@silverwind
Copy link
Contributor

@dcposch hmm, alright then. LGTM.

rvagg pushed a commit that referenced this pull request Feb 18, 2016
Fix missing links. Fix styling of printf() - once #5073 lands,
link to man page will be auto-generated. Fix several typos.

PR-URL: #5225
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: James M Snell <[email protected]>
'&sektion=' + number + '">' + displayAs + '</a>';
} else {
return ' <a href="http://man7.org/linux/man-pages/man' + number +
'/' + name + '.' + number + '.html">' + displayAs + '</a>';
Copy link
Contributor

Choose a reason for hiding this comment

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

template literal?

MylesBorins pushed a commit that referenced this pull request Feb 22, 2016
Fix missing links. Fix styling of printf() - once #5073 lands,
link to man page will be auto-generated. Fix several typos.

PR-URL: #5225
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Feb 22, 2016
Fix missing links. Fix styling of printf() - once #5073 lands,
link to man page will be auto-generated. Fix several typos.

PR-URL: #5225
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@silverwind
Copy link
Contributor

Thanks! Landed in 4e77a7c.

@silverwind silverwind closed this Feb 27, 2016
silverwind pushed a commit that referenced this pull request Feb 27, 2016
This changes the doc generator to automatically link references such as
`open(2)` to a man page on man7.org or freebsd.org

PR-URL: #5073
Reviewed-By: Ben Noorhduis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
rvagg pushed a commit that referenced this pull request Feb 28, 2016
This changes the doc generator to automatically link references such as
`open(2)` to a man page on man7.org or freebsd.org

PR-URL: #5073
Reviewed-By: Ben Noorhduis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
@Fishrock123 Fishrock123 mentioned this pull request Mar 1, 2016
5 tasks
MylesBorins pushed a commit that referenced this pull request Mar 1, 2016
This changes the doc generator to automatically link references such as
`open(2)` to a man page on man7.org or freebsd.org

PR-URL: #5073
Reviewed-By: Ben Noorhduis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 1, 2016
This changes the doc generator to automatically link references such as
`open(2)` to a man page on man7.org or freebsd.org

PR-URL: #5073
Reviewed-By: Ben Noorhduis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 2, 2016
Fix missing links. Fix styling of printf() - once #5073 lands,
link to man page will be auto-generated. Fix several typos.

PR-URL: #5225
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 2, 2016
This changes the doc generator to automatically link references such as
`open(2)` to a man page on man7.org or freebsd.org

PR-URL: #5073
Reviewed-By: Ben Noorhduis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.