Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4e77a7c

Browse filesBrowse files
dcposchsilverwind
authored andcommitted
doc: link to man pages
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 <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
1 parent 9894c02 commit 4e77a7c
Copy full SHA for 4e77a7c

File tree

Expand file treeCollapse file tree

2 files changed

+48
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+48
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/documentation.markdown‎

Copy file name to clipboardExpand all lines: doc/api/documentation.markdown
+16Lines changed: 16 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,19 @@ Every HTML file in the markdown has a corresponding JSON file with the
6666
same data.
6767

6868
This feature was added in Node.js v0.6.12. It is experimental.
69+
70+
## Syscalls and man pages
71+
72+
System calls like open(2) and read(2) define the interface between user programs
73+
and the underlying operating system. Node functions which simply wrap a syscall,
74+
like `fs.open()`, will document that. The docs link to the corresponding man
75+
pages (short for manual pages) which describe how the syscalls work.
76+
77+
**Caveat:** some syscalls, like lchown(2), are BSD-specific. That means, for
78+
example, that `fs.lchown()` only works on Mac OS X and other BSD-derived systems,
79+
and is not available on Linux.
80+
81+
Most Unix syscalls have Windows equivalents, but behavior may differ on Windows
82+
relative to Linux and OS X. For an example of the subtle ways in which it's
83+
sometimes impossible to replace Unix syscall semantics on Windows, see [Node
84+
issue 4760](https://github.com/nodejs/node/issues/4760).
Collapse file

‎tools/doc/html.js‎

Copy file name to clipboardExpand all lines: tools/doc/html.js
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ function render(lexed, filename, template, cb) {
7777

7878
filename = path.basename(filename, '.markdown');
7979

80+
parseText(lexed);
8081
lexed = parseLists(lexed);
8182

8283
// generate the table of contents.
@@ -105,6 +106,15 @@ function render(lexed, filename, template, cb) {
105106
});
106107
}
107108

109+
// handle general body-text replacements
110+
// for example, link man page references to the actual page
111+
function parseText(lexed) {
112+
lexed.forEach(function(tok) {
113+
if (tok.text) {
114+
tok.text = linkManPages(tok.text);
115+
}
116+
});
117+
}
108118

109119
// just update the list item text in-place.
110120
// lists that come right after a heading are what we're after.
@@ -167,11 +177,33 @@ function parseLists(input) {
167177
}
168178

169179

180+
// Syscalls which appear in the docs, but which only exist in BSD / OSX
181+
var BSD_ONLY_SYSCALLS = new Set(['lchmod']);
182+
183+
// Handle references to man pages, eg "open(2)" or "lchmod(2)"
184+
// Returns modified text, with such refs replace with HTML links, for example
185+
// '<a href="http://man7.org/linux/man-pages/man2/open.2.html">open(2)</a>'
186+
function linkManPages(text) {
187+
return text.replace(/ ([a-z]+)\((\d)\)/gm, function(match, name, number) {
188+
// name consists of lowercase letters, number is a single digit
189+
var displayAs = name + '(' + number + ')';
190+
if (BSD_ONLY_SYSCALLS.has(name)) {
191+
return ' <a href="https://www.freebsd.org/cgi/man.cgi?query=' + name +
192+
'&sektion=' + number + '">' + displayAs + '</a>';
193+
} else {
194+
return ' <a href="http://man7.org/linux/man-pages/man' + number +
195+
'/' + name + '.' + number + '.html">' + displayAs + '</a>';
196+
}
197+
});
198+
}
199+
170200
function parseListItem(text) {
171201
var parts = text.split('`');
172202
var i;
173203
var typeMatches;
174204

205+
// Handle types, for example the source Markdown might say
206+
// "This argument should be a {Number} or {String}"
175207
for (i = 0; i < parts.length; i += 2) {
176208
typeMatches = parts[i].match(/\{([^\}]+)\}/g);
177209
if (typeMatches) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.