Artifact adb79aca99bb11eecb220acb0ad6cb92c2cf3115f8c1b6cbd8b6df149fd241ed:
- File tools/man2markdown-README.md — part of check-in [2d958118ec] at 2026-10-26 23:06:59 on branch tip-700 — - added handling of Tk nroff .SO macro (user: Torsten, size: 11295) [annotate] [blame] [check-ins using]
Usage of man2markdown script to convert nroff to markdown
This script parses an nroff formatted Tcl/Tk manual page, converts it into some AST (Abstract Syntax Tree) and then writes it out again as a markdown file.
When this script is called from another Tcl script (i.e. using the [source] command), you can call the procedure ::ndoc::man2markdown with a the content of a man file to be converted as an argument (the whole script and its procedures live in the '::ndoc::' namespace). If you just have the man file, you can use: ::ndoc::man2markdown [::ndoc::readFile /path/to/my/file.n].
This procedure will return the resulting markdown.
When this script is called directly from the command line using tclsh, specifying an nroff file as an argument will call the [::ndoc::man2markdown] procedure on the file content and return the markdown on stdout.
When not specifying an argument, it runs in test mode, converting a specific manual page from within the repository structure which this script is a part of. The result is written to stdout.
When run with two directory names, it will convert all nroff files in the (existing) first directory and put the result as markdown files into the second directory (which will be created if it does not exist). This should be used to produce the current status of afairs into doc/markdown/:
# (from the tools directory)
tclsh man2markdown.tcl ../doc/nroff-original ../doc/markdown/
The last invocation can be used to check what changed with respect to the last fossil commit. Any change reported by fossil (before committing) is a change that might have issues compared to the previous version, so it should be checked before the commit and amended before the commit!
Usage of Pandoc to convert generated markdown
We use Pandoc to convert the markdown sources to both nroff and HTML as long as no converter exists in Tcl which can handle this well. As the dollar sign is often used in the manual pages to mark variables and we do not need TeX math, we disable the tex_math_dollars extension in Pandoc.
Conversion to nroff
Basically, you can use this to generate nroff which renders most of what you will need.
pandoc -f markdown-tex_math_dollars -t man mypage.md -o mypage.n
For a closer representation use the markdown2nroff.tcl script.
Conversion to HTML
pandoc -f markdown-tex_math_dollars -t html mypage.md -o mypage.html
For a closer representation use the markdown2html.tcl script.
Status of conversion process for Tcl
The tcl/doc directory contains 248 manual pages which are divided as follows:
| section | number of documents | initial conversion | final conversion |
|---|---|---|---|
| 1 | 1 | 1 | 1 |
| 3 | 108 | 108 | 108 |
| n | 145 | 145 | 145 |
Final conversion of these files in the n section is currently done:
- after
- append
- apply
- array
- bgerror
- binary
- break
- buildinfo
- callback
- catch
- cd
- chan (indentation for [chan configure] is not ok -> will be dealt with when restructuring manual pages after TIP 700)
- class
- classvariable
- clock -> we may need to use '(1)' instead of '[1]' for referencing list items as this might be misinterpreted during conversion to HTML
- close
- concat
- configurable
- const
- continue
- cookiejar
- copy
- coroutine
- dde
- define
- dict
- encoding
- eof
- error
- eval
- exec (the section PORTABILITY ISSUES need manual conversion into markdown subsections)
- exit
- expr (the section OPERANDS needs manual adaptation after conversion to markdown)
- fblocked
- fconfigure
- fcopy
- file
- fileevent
- filename
- flush
- for
- foreach
- format
- fpclassify
- gets
- glob
- global
- history
- http (manual postprocessing needed: the options of some subcommands need more indentation which the script didn't catch)
- idna
- if
- incr
- info (manual postprocessing needed: some cmd names are links, others are option names etc.)
- interp (the list of safe commands needs manual formatting)
- join
- lappend
- lassign
- ledit
- library (might need manual postprocessing ...)
- lindex
- link
- linsert
- list
- llength
- lmap
- load
- lpop
- lrange
- lremove
- lrepeat
- lreplace
- lreverse
- lsearch
- lseq
- lset
- lsort
- mathfunc (list of functions needs other formatting, the math function syntax should perhaps not use {.cmd})
- mathop (list of operators needs other formatting, the math operator syntax should perhaps not use {.cmd
- memory
- msgcat (check the TIP499 marker)
- my
- namespace
- next
- object
- open
- package (the deep list in section "Requirement" needs manual adjustment)
- packagens
- pid
- pkg_mkIndex
- platform
- platform_shell
- prefix
- proc
- process (the command
process statusneeds manual reformatting) - puts
- pwd
- re_syntax (needs extensive manual formatting of brackets and backslashes)
- read
- refchan
- regexp
- registry
- regsub
- rename
- return
- safe (the links to other manual pages need manual correction here, there are just too many special cases!)
- scan
- seek
- self
- set
- singleton
- socket
- source
- split
- string
- subst
- switch
- tailcall
- tcltest
- tclvars
- tell
- throw
- time
- timerate
- tm
- trace
- transchan
- try
- unicode (check the TIP726 markers)
- unknown
- unload
- unset
- update
- uplevel
- upvar
- variable
- vwait
- while
- zipfs
- zlib (will need some manual adjustments)
New in Tcl 9.1:
- divmod
- frexp
- lfilter
- modf
- remquo
- timer
Now the 3 section:
- Access
- AddErrInfo
- Alloc
- AllowExc
- AppInit
- AssocData
- Async
- BackgdErr
- BoolObj
- ByteArrObj
- CallDel
- Cancel
- ChnlStack
- Class
- CmdCmpIt
- Concat (Concat3)
- CrtAlias
- CrtChannel
- CrtChnlHdlr
- CrtCloseHndlr
- CrtCommand
- CrtFileHndlr
- CrtInterp
- CrtObjCmd
- CrtTimerHndlr
- CrtTrace
- DString
- DetachPids
- DictObj
- DoOneEvent
- DoWhenIdle
- DoubleObj
- DumpActiveMemory
- Encoding
- Ensemble
- Environment
- Eval
- Exit
- ExprLong
- ExprLongObj
- FileSystem
- FindExec
- GetCwd
- GetHostName
- GetIndex
- GetInt
- GetOpnFl
- GetStdChan
- GetTime
- GetVersion
- Hash
- Init (perhaps the typedef line in the synopsis needs some manual formatting)
- InitStubs
- InitSubSyst
- IntObj
- Limit
- LinkVar
- ListObj
- Load3
- Method
- NRE
- Namespace
- Notifier
- Number
- OOInitStubs.md
- Object3
- ObjectType
- OpenFileChnl
- OpenTcp
- Panic
- ParseArgs
- ParseCmd
- PkgRequire
- Preserve
- PrintDbl
- RecEvalObj
- RecordEval
- RegConfig
- RegExp3
- SaveInterpState
- SetChanErr
- SetErrno
- SetRectLmt
- SetResult
- SetVar
- Signal
- Sleep
- SourceRCFile
- SplitList
- SplitPath
- StaticLibrary
- StdChannels (needs manula adjustment of the numbered list)
- StrMatch
- StringObj
- SubstObj
- TCL_MEM_DEBUG
- TclZlib
- Tcl_Main
- Thread
- ToUpper
- TraceCmd
- TraceVar
- Translate
- UniCharIsAlpha
- UnicodeNormalize
- UpVar3
- Utf
- WrongNumArgs
Now the 1 section:
- tclsh
Status of conversion process for Tk
The tk/doc directory contains 181 manual pages which are divided as follows:
| section | number of documents | initial conversion | final conversion |
|---|---|---|---|
| 1 | 1 | 0 | 0 |
| 3 | 87 | 0 | 0 |
| n | 93 | 8 | 0 |
Final conversion of these files in the n section is currently done:
...
Open issues
This section lists the shortcoming which are still present in the pages that already have an initial markdown version.
General
- handling of 'fBefIkfR' (see test script) not correct yet
- no handling of ".AS" and ".AP" macros yet
- general alignment of the wording in the manual pages to the one in the Tcl error messages emitted (e.g.
dict foruses "dictionaryValue body" in the manual page but "dictionary script" in the C code) - alignment of changed wording/presentation of Tcl syntax within the C code error messages emitted by Tcl when using wrong Tcl syntax
(example:
dict for {keyVarName valueVarName} dictionary script-->dict for varaibleList dictionary script) - use camelCase consistently for Tcl syntax arguments
- handling of the "|" character for alternatives (see
memory init on|off) is not yet good, leaves it ason=|§off - handling of links does not yet use all the exceptions defined in tools/tcltk-man2html.tcl and tools/tclsk-man2html-utils.tcl (for now only exclude_refs_map is used)
- not all instances of "TIP" infos are preserved (especially when inside a combined .RE/.PP context as in msgcat.n, so grep all uses and check manually after automatic conversion)
Specific pages
- RegConfig.3: besides the C API, this page describes Tcl-level commands that are created. These use a non-standard format in the form of ::, followed by an .arg, followed by ::, followed by a .lit – all in one word!
Implemented features in conversion script
List of nroff commands/macros currently implemented (partly not a complete implementation):
- ." (comments)
- '" (comments)
- (-> (right arrow, converted to u2192)
- \N'34' (literal double quote)
- backslash escapes "e" and "c"
- . (single dot as placeholder)
- \fB (bold text)
- \fI (italic text)
- \fR (reset font info)
- \fP (treated the same as \fB)
- \(fm (prime symbol)
- .QW (text in quotes)
- .PQ (text in quotes + paranthesis)
- .QR (text in quotes + dash between elements)
- .so (include files)
- .BS .BE (start and end of box enclosure)
- .AS (maximum sizes of arguments for setting tab stops)
- .ta (set tab stops)
- .RS .RE (relative inset, i.e. indentation)
- .nf .fi (turn off/on filling of lines, only used in SYNOPSIS and oo CLASS HIERARCHY, the effect being similar to
and
for HTML) - .TH (title heading)
- .TP (tagged paragraph)
- .IP (indented paragaph)
- .PP (paragraph)
- .SH (section header)
- .SS (subsection header)
- .VS .VE (start and end of vertical line)
- .CS .CE (start and end of code block)
- .sp (inserts vertical space) > this is treated individually (currently by mdExceptions)
- .ta (tabulator)
- .DS DE (display section)
- .MT (here used for "" display)
Manual work to be done after final conversion
After the final round of conversion from nroff to Markdown, some manual work needs to be done that is not covered by the conversion script
- subdivide certain manual pages (the nroff files only have sections and subsection, in the markdown version, also subsubsections are needed in some pages)
- find all pages where nested definition lists occur (e.g. Tcl.md) and consider using subsections instead
- look at the sections marked as '{.info DISPLAY="yes"}' as these need a proper visual representation