Giter VIP home page Giter VIP logo

man-to-md's Introduction

man-to-md(1) - Converts nroff man pages to Markdown

Version 0.17.0, December 2020

$ man-to-md.pl [OPTIONS] <manpage.roff >output.md

Description

This program is a filter that reads man(7)-formatted nroff man pages and outputs Markdown. It can be used to automatically convert man page files to Markdown README files.

Options

  • -p, --paste-section-after SECTION:FILENAME
    Instructs the program to attach a Markdown file after the section named SECTION has been completely written to the output. SECTION must be an exact match of the input section name. If the input contains no such section, the file will be attached to the end of the output. The attached file contents will have the exact FILENAME (without the .md extension) as their top-level section title.
    This option can be supplied more than once. Multiple files for the same section will be attached in the options' order.
  • -P, --paste-section-before SECTION:FILENAME
    Like --paste-section-after, but attaches the file contents to the output just before the named section is written.
  • --paste-after SECTION:FILENAME
    Like --paste-section-after, but does not add a section title.
  • --paste-before SECTION:FILENAME
    Like --paste-section-before, but does not add a section title.
  • -c, --comment [COMMENT]
    Adds an invisible comment as first line. Without the argument, it uses this default comment:
    This file was autogenerated from the man page with 'make README.md'”.
  • --escaped-dashes
    Don't remove the backslash from escaped dashes (\-).
  • -w, --word WORD
    Adds a WORD to the list of known words not to be titlecased in section titles. (All other words will be titlecased except some known English stopwords which will be lowercased.)
    This option can be supplied more than once to add multiple known words.
  • -f, --formatted-code
    Allows simple formatting in .nf-.fi code blocks and in the Synopsis line. (Without this option, all formatting in code block and in the Synopsis line will be removed.)
  • -h, --help
    Shows program help.
  • -V, --version
    Shows version and license information.

Standards

This program understands many man(7) nroff commands and macros commonly used in man page files. For a complete list, see doc/Commands.md.

The program emits Markdown syntax that should be readable with most Markdown editors/viewers. See doc/Markdown_Output_Format.md for more information.

The program makes several assumptions about the input format that are not standardized but seem to be fairly commonplace in man pages; see doc/Input_Format.md. It does not yet understand the newer mdoc(7) format.

License

GNU GPL v3

See Also

Project homepage: https://github.com/mle86/man-to-md

Author

Maximilian Eul <[email protected]> (https://github.com/mle86)

man-to-md's People

Contributors

mle86 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

man-to-md's Issues

could not parse first line when date is on top

Hi!
I'm receiving the following error when trying to convert nvim man page to markdown.

perl man-to-md.pl < $(man --where --all nvim) > nvim.md
could not parse first line at man-to-md.pl line 575, <> line 1.

These are thef first lines of Nvim man page.

.Dd December 17, 2017
.Dt NVIM 1
.Os
.Sh NAME
.Nm nvim
.Nd edit text
.Sh SYNOPSIS
.Nm
.Op Ar options
.Op Ar file ...

don't work on standard manuals

I gave a try to man-to-md, while I can successfully use it on the samples from test/samples/
directory, when trying to convert any standard man page from my linux system (like man.1 or ls.1) give an error:

 could not parse first line at man-to-md/man-to-md.pl line 413, <> line 1.

What is wrong with the roff format of standard manuals?

It also fails on a simple example like foo.1 from the Linux Man Page Howto.

Releases newer than 0.14.1

The latest release of this project is 0.14.1 but newer versions up to 0.17.0 have been tagged. Should releases be created for those newer tags, or are versions after 0.14.1 not considered to be usable releases?

.nf/.fi are not handled well

the .nf and .fi macros are used to force newlines to be retained. it's quite handy for creating a flat list, or for code snippets.
https://www.gnu.org/software/groff/manual/html_node/Manipulating-Filling-and-Adjusting.html

the perl script oddly indents the code instead. i guess it's going for automatic code mode or something ?

example input:

.nf
One item.
Another item.
.fi

a reasonable md rendering would be to just add <br> to the end of each line i think:

One item.<br>
Another item.<br>

could not parse first line at . . .

λ man2md ls
/usr/share/man/man1/ls.1
could not parse first line at /Users/storm/bin/man2md.pl line 626, <> line 38.

λ man2md which
/usr/share/man/man1/which.1
could not parse first line at /Users/storm/bin/man2md.pl line 626, <> line 32.

λ man2md systemsetup
/usr/share/man/man8/systemsetup.8
could not parse first line at /Users/storm/bin/man2md.pl line 626, <> line 18.

λ uname -a
Darwin 10core.local 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar  4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64

I was so happy when I found this project.
Using it to pass its output to Cobertos/md2notion project, to archive man-pages and then edit them, then to recall I use the wrjlewis/notion-search-alfred-workflow project to search Notion for the edited man-page. But, most of the manual pages I wanted to archive, throws an error as the above. Is this related to #5 perhaps? Since it errors out on most everything I wanted to convert perhaps this is something different? I do not know perl that well, nor the *roff formats, how would we proceed to get this fixed?

Bold/italic blocks may be ended by \fP

Bold and italic blocks started with \fB or \fI may be ended with \fP as well (not just \fR).
I did the following patch:

381,382c381,382
<       s/\\fB([^\*_]|.{2,}?)\\fR/**$1**/g;
<       s/\\fI([^\*_]|.{2,}?)\\fR/_$1_/g;
---
>       s/\\fB([^\*_]|.{2,}?)\\f[RP]/**$1**/g;
>       s/\\fI([^\*_]|.{2,}?)\\f[RP]/_$1_/g;
399,400c399,400
<       s#\\fB(\*|_)\\fR#<b>\\$1</b>#g;
<       s#\\fI(\*|_)\\fR#<i>\\$1</i>#g;
---
>       s#\\fB(\*|_)\\f[RP]#<b>\\$1</b>#g;
>       s#\\fI(\*|_)\\f[RP]#<i>\\$1</i>#g;
465,466c465,466
<       s#\\fB(.+?)\\fR#<b>$1</b>#g;
<       s#\\fI(.+?)\\fR#<i>$1</i>#g;
---
>       s#\\fB(.+?)\\f[RP]#<b>$1</b>#g;
>       s#\\fI(.+?)\\f[RP]#<i>$1</i>#g;

Copyright sign

Thank you for this very useful project. Converting one of my man pages, I noticed that a \(co which man displays as ©, stays an escaped sequence. I think man-to-md should also do the conversion.

\- are not escaped in output

unescaped - run the risk of being automatically converted to other characters in outputs depending on what follows it. -- is commonly converted to an – (U+2013 endash). this is undesirable for code documentation like command line options as they no longer can be copied & pasted. that's why man pages will often write \-\-foo for the --foo command line option.

depending on the renderer, markdown has this feature as well -- it creates endashes whenever it sees --. this def happens on github pages for example.

the current man-to-md script will strip away the \ from something like \-\-foo yielding --foo which turns into –foo which is not good :).

i think just leaving \- as \- should be fine for most markdown renderers ?

GitHub Flavored Markdown

I tried converting one of my system's manpages with man-to-md and it looked fine in a standalone markdown viewer:

When strip is used with no options on an executable file, it checks that file to see if it uses the dynamic link editor. If it does, the effect of the strip command is the same as using the -u and -r options. If the file does not use the dynamic link editor, the effect of strip without any options is the same as using the -s option of ld(1). The options -S, -x, and -X have the same effect as the ld(1) options. The options to strip(1) can be combined to trim the symbol table to just what is desired.

But when I pasted the generated markdown into a GitHub issue, there were a lot of unnecessary extra linebreaks:

When
strip
is used with no options on an executable file, it checks that file to see if it uses the dynamic link editor.
If it does, the effect of the
strip
command is the same as using the
-u
and
-r
options. If the file does not use the dynamic link editor, the effect of
strip
without any options is the same as using the
-s
option of
ld(1).
The options
-S,
-x,
and
-X
have the same effect as the
ld(1)
options.
The options to
strip(1)
can be combined to trim the symbol table to just what is desired.

Could man-to-md better support GitHub Flavored Markdown?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.