| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9894c02 commit 4e77a7c
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,3 +66,19 @@ Every HTML file in the markdown has a corresponding JSON file with the | |||
| 66 | 66 | same data. | |
| 67 | 67 | ||
| 68 | 68 | 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). | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,6 +77,7 @@ function render(lexed, filename, template, cb) { | |||
| 77 | 77 | ||
| 78 | 78 | filename = path.basename(filename, '.markdown'); | |
| 79 | 79 | ||
| 80 | + parseText(lexed); | ||
| 80 | 81 | lexed = parseLists(lexed); | |
| 81 | 82 | ||
| 82 | 83 | // generate the table of contents. | |
@@ -105,6 +106,15 @@ function render(lexed, filename, template, cb) { | |||
| 105 | 106 | }); | |
| 106 | 107 | } | |
| 107 | 108 | ||
| 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 | + } | ||
| 108 | 118 | ||
| 109 | 119 | // just update the list item text in-place. | |
| 110 | 120 | // lists that come right after a heading are what we're after. | |
@@ -167,11 +177,33 @@ function parseLists(input) { | |||
| 167 | 177 | } | |
| 168 | 178 | ||
| 169 | 179 | ||
| 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 | + | ||
| 170 | 200 | function parseListItem(text) { | |
| 171 | 201 | var parts = text.split('`'); | |
| 172 | 202 | var i; | |
| 173 | 203 | var typeMatches; | |
| 174 | 204 | ||
| 205 | + // Handle types, for example the source Markdown might say | ||
| 206 | + // "This argument should be a {Number} or {String}" | ||
| 175 | 207 | for (i = 0; i < parts.length; i += 2) { | |
| 176 | 208 | typeMatches = parts[i].match(/\{([^\}]+)\}/g); | |
| 177 | 209 | if (typeMatches) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments