-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Add support for manpages via mandoc #1196
Changes from 14 commits
2008073
d6643c3
3deeea0
f149841
f00e30c
19abce5
da73a08
11c43b4
786e531
521ccf9
a43da81
1b6203f
a190353
52b32d7
b32d9de
fb06417
333ccfc
6b078bb
cb28ead
5df53fa
2bde37d
88678cd
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module GitHub | ||
module Markup | ||
VERSION = '3.0.1' | ||
VERSION = '3.0.2' | ||
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. |
||
Version = VERSION | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# write the input to a tempfile first so we can look at it | ||
TEMPFILE="$(mktemp)" | ||
# shellcheck disable=SC2064 | ||
trap "rm -f $TEMPFILE" EXIT | ||
cat "$@" > "$TEMPFILE" | ||
|
||
# bail out if ths doesn't look like roff | ||
grep -q '^[\.'\''][ \t]*[A-Za-z]\{2\}' "$TEMPFILE" | ||
|
||
# process it, and print everything from the first <h1> to </body> | ||
mandoc -Thtml -Ofragment "$TEMPFILE" \ | ||
| xmlstarlet tr --html --omit-decl "$(dirname "$0")/man2html.xslt" - \ | ||
| awk '/<h1/{flag=1}/<\/body>/{flag=0}flag' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
<!-- // | ||
Based on the HTML output and default stylesheet of mandoc 1.14.4 | ||
YMMV with other versions of mandoc | ||
// --> | ||
|
||
<!-- Default: match anything and apply templates to it --> | ||
<xsl:template match="node()|@*"> | ||
<xsl:copy> | ||
<xsl:apply-templates select="node()|@*"/> | ||
</xsl:copy> | ||
</xsl:template> | ||
|
||
<!-- Strip all the attributes off of these --> | ||
<xsl:template match="h1"> | ||
<h1><xsl:apply-templates /></h1> | ||
</xsl:template> | ||
|
||
<!-- Turn these into paragraphs --> | ||
<xsl:template match="div[@class='Pp']"> | ||
<p><xsl:apply-templates /></p> | ||
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. This replacement is WRONG, you can't do that. In mandoc HTML output, paragraphs often contain flow content, but HTML only permits phrasing content inside <p> elements. So what you are doing here is introducing HTML syntax errors. 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. @ischwarze You aren't wrong, but mistakes like these really, really, really common in GitHub's front-end code, which is yet another giant bowl of "tag-soup" for their designers to play in. Nobody's gonna notice this syntax violation when the entire site is a scrapbook of "do whatever, as long as it looks good". :( |
||
</xsl:template> | ||
|
||
<!-- Indent these --> | ||
<xsl:template match="div[@class='Bd-indent' or @class='Bd Bd-indent']"> | ||
<ul><xsl:apply-templates /></ul> | ||
</xsl:template> | ||
|
||
<!-- Headers don't need to be linking to themselves --> | ||
<xsl:template match="a[@class='permalink']"> | ||
<xsl:apply-templates /> | ||
</xsl:template> | ||
|
||
<!-- Pull the manual-text div out --> | ||
<xsl:template match="div[@class='manual-text']"> | ||
<xsl:apply-templates /> | ||
</xsl:template> | ||
|
||
<!-- These were display: inline, so just give the content --> | ||
<xsl:template match="div[@class='Nd' or @class='Bf' or @class='Op']"> | ||
<xsl:apply-templates /> | ||
</xsl:template> | ||
|
||
<!-- These were display: italic --> | ||
<xsl:template match="span[@class='Pa' or @class='Ad']"> | ||
<em><xsl:apply-templates /></em> | ||
</xsl:template> | ||
|
||
<!-- These were font-weight: bold --> | ||
<xsl:template match="span[@class='Ms']"> | ||
<b><xsl:apply-templates /></b> | ||
</xsl:template> | ||
|
||
<xsl:template match="dl[@class='BL-diag']/dt"> | ||
<b><xsl:apply-templates /></b> | ||
</xsl:template> | ||
|
||
<xsl:template match="code[@class='Nm' or @class='Fl' or @class='Cm' or @class='Ic' or @class='In' or @class='Fd' or @class='Fn' or @class='Cd']"> | ||
<b><code><xsl:apply-templates /></code></b> | ||
</xsl:template> | ||
|
||
<!-- Remove header table --> | ||
<xsl:template match="table[@class='head']"/> | ||
|
||
<!-- Reformat footer table and pull some header stuff into it --> | ||
<xsl:template match="table[@class='foot']"> | ||
<hr/> | ||
<table> | ||
<xsl:apply-templates select="//td[text() and text() != '()' and @class='head-ltitle']"/> | ||
<xsl:apply-templates select="//td[text() and text() != '()' and @class='head-vol']"/> | ||
<xsl:apply-templates select="//td[text() and text() != '()' and @class='foot-os']"/> | ||
<xsl:apply-templates select="//td[text() and text() != '()' and @class='foot-date']"/> | ||
</table> | ||
</xsl:template> | ||
|
||
<!-- Turn head header/footer cells into rows --> | ||
<xsl:template match="td[@class='head-ltitle']"> | ||
<tr><td><em>Title:</em></td><td><xsl:apply-templates /></td></tr> | ||
</xsl:template> | ||
|
||
<xsl:template match="td[@class='head-vol']"> | ||
<tr><td><em>Volume:</em></td><td><xsl:apply-templates /></td></tr> | ||
</xsl:template> | ||
|
||
<xsl:template match="td[@class='foot-date']"> | ||
<tr><td><em>Date:</em></td><td><xsl:apply-templates /></td></tr> | ||
</xsl:template> | ||
|
||
<xsl:template match="td[@class='foot-os']"> | ||
<tr><td><em>Manual:</em></td><td><xsl:apply-templates /></td></tr> | ||
</xsl:template> | ||
</xsl:stylesheet> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.Dd $Mdocdate: March 23 1981 $ | ||
.Dt README 1 | ||
.Os GitHub | ||
.Sh README.man | ||
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. This is an mdoc(7) syntax error, which is probably not a good thing to have in an example/test file. The first section header in a manual page MUST be exactly ".Sh NAME". Your line is also invalid because it contains lower case letters. 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. And after that it should provide data for whatis(1)'s scraping; see lexgrog(1)'s WHATIS PARSING as an example.
|
||
.Nm README | ||
.Nd This is an example readme in mandoc | ||
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. This is an invalid example for a second reason. In addition to the NAME section, at least the DESCRIPTION section is also required in a manual page. So you should probably add
or something like that. 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. Ingo probably means .Sh 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. Oops, yes, of course, ".Sh DESCRIPTION", thanks for noticing. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<h1>README.man</h1> | ||
<b><code>README</code></b> — | ||
This is an example readme in mandoc | ||
|
||
<hr> | ||
<table> | ||
<tr> | ||
<td><em>Title:</em></td> | ||
<td>README(1)</td> | ||
</tr> | ||
<tr> | ||
<td><em>Volume:</em></td> | ||
<td>General Commands Manual</td> | ||
</tr> | ||
<tr> | ||
<td><em>Manual:</em></td> | ||
<td>GitHub</td> | ||
</tr> | ||
<tr> | ||
<td><em>Date:</em></td> | ||
<td>March 23, 1981</td> | ||
</tr> | ||
</table> |
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.
Looks like this suggested change has broken diff.