o au@sBdZddlZddlmZddlmZmZdgZGdddeZdS)z pygments.formatters.groff ~~~~~~~~~~~~~~~~~~~~~~~~~ Formatter for groff output. :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. N) Formatter) get_bool_opt get_int_optGroffFormatterc@sXeZdZdZdZgdZgZddZddZdd Z d d Z d d Z ddZ ddZ dS)ra Format tokens with groff escapes to change their color and font style. .. versionadded:: 2.11 Additional options accepted: `style` The style to use, can be a string or a Style subclass (default: ``'default'``). `monospaced` If set to true, monospace font will be used (default: ``true``). `linenos` If set to true, print the line numbers (default: ``false``). `wrap` Wrap lines to the specified number of characters. Disabled if set to 0 (default: ``0``). groff)rtroffroffcKsZtj|fi|t|dd|_t|dd|_d|_t|dd|_d|_i|_ | dS)N monospacedTlinenosFrwrap) r__init__rr r _linenorr _linelenstyles _make_styles)selfoptionsr;/usr/lib/python3/dist-packages/pygments/formatters/groff.pyr -s zGroffFormatter.__init__cCs|jrdnd}|jr dnd}|jrdnd}|jD]G\}}d}}|dr0|d |d7}d |}|d r<||7}||}|d rH||7}||}|d rX|d|d 7}d|}||f|j|<qdS)Nz\f[CR]z\f[R]z\f[CB]z\f[B]z\f[CI]z\f[I]colorz\m[%s]z\m[]bolditalicbgcolorz\M[%s]z\M[])r styler)rregularrrttypendefstartendrrrr:s&zGroffFormatter._make_stylescCsXt}|jD]\}}|ddur||dq|D]}|d|d|dqdS)Nrz .defcolor z rgb # )setraddwrite)routfilecolors_rrrrr_define_colorsQs zGroffFormatter._define_colorscCs4|jd7_|d|jdkrdpd|jfdS)Nz%s% 4d r r)r r#)rr$rrr _write_lineno[s&zGroffFormatter._write_linenocCst|d}|jr dnd}d}||jkrStdt||jD]}|||j||j|j}||d|7}q ||j}|dkrQ||| dd7}||_|S|j||jkrfd||}||_|S|}|j|7_|S)Nr z rrr()lenrstripr r rangemathfloorr)rlinelengthspacenewlineichunk remainderrrr _wrap_line`s&   zGroffFormatter._wrap_linecCs|ddddddddd d }|}|D]+}t|t|krE|d d dd d}||d|d dd}q|S)N\z\[u005C].z \[char46]'z\[u0027]`z\[u0060]~z\[u007E]unicode_escaper(xu00z\[u])replacer*encodedecodeupper)rtextcopycharunirrr _escape_charsws$  zGroffFormatter._escape_charsc Cs|||d|jr|||D]]\}}|j|\}}|dD]L}|jdkr0||}|rL|rL|| d}|dkrK|d |||fn ||| d| drp|jrh||d|_ q$|dd|_ q$q|ddS)Nz .nf \f[CR] Trr rz .fi) r'r#r r)r splitlinesr r6rHr+joinendswithr) r tokensourcer$rvaluerrr/rDrrrformat_unencodeds0         zGroffFormatter.format_unencodedN)__name__ __module__ __qualname____doc__namealiases filenamesr rr'r)r6rHrNrrrrrs   ) rRr-pygments.formatterr pygments.utilrr__all__rrrrrs