-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
doc: link to man pages #5073
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ function render(lexed, filename, template, cb) { | |
|
||
filename = path.basename(filename, '.markdown'); | ||
|
||
parseText(lexed); | ||
lexed = parseLists(lexed); | ||
|
||
// generate the table of contents. | ||
|
@@ -105,6 +106,15 @@ function render(lexed, filename, template, cb) { | |
}); | ||
} | ||
|
||
// handle general body-text replacements | ||
// for example, link man page references to the actual page | ||
function parseText(lexed) { | ||
lexed.forEach(function(tok) { | ||
if (tok.text) { | ||
tok.text = linkManPages(tok.text); | ||
} | ||
}); | ||
} | ||
|
||
// just update the list item text in-place. | ||
// lists that come right after a heading are what we're after. | ||
|
@@ -167,11 +177,33 @@ function parseLists(input) { | |
} | ||
|
||
|
||
// Syscalls which appear in the docs, but which only exist in BSD / OSX | ||
var BSD_ONLY_SYSCALLS = new Set(['lchmod']); | ||
|
||
// Handle references to man pages, eg "open(2)" or "lchmod(2)" | ||
// 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NVM. Here's a place where it fails
I'll change it to require special markup to generate the link, so we don't get false positives. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
// name consists of lowercase letters, number is a single digit | ||
var displayAs = name + '(' + number + ')'; | ||
if (BSD_ONLY_SYSCALLS.has(name)) { | ||
return ' <a href="https://www.freebsd.org/cgi/man.cgi?query=' + name + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor suggestion: We can use template Strings here. |
||
'&sektion=' + number + '">' + displayAs + '</a>'; | ||
} else { | ||
return ' <a href="http://man7.org/linux/man-pages/man' + number + | ||
'/' + name + '.' + number + '.html">' + displayAs + '</a>'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. template literal? |
||
} | ||
}); | ||
} | ||
|
||
function parseListItem(text) { | ||
var parts = text.split('`'); | ||
var i; | ||
var typeMatches; | ||
|
||
// Handle types, for example the source Markdown might say | ||
// "This argument should be a {Number} or {String}" | ||
for (i = 0; i < parts.length; i += 2) { | ||
typeMatches = parts[i].match(/\{([^\}]+)\}/g); | ||
if (typeMatches) { | ||
|
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.
@estliberitas Hope you are taking care of this page as well :)
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.
@thefourtheye Np, will do soon )
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.
Thanks :)
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.
@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.
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.
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.
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.
Anyways, I'll continue my crusade on docs today and tomorrow. :)
On Sat, Feb 13, 2016, 08:59 thefourtheye notifications@github.com wrote: