2 pygments.formatters.groff
3 ~~~~~~~~~~~~~~~~~~~~~~~~~
5 Formatter for groff output.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
15__all__ = [
'GroffFormatter']
20 Format tokens with groff escapes to change their color and font style.
22 .. versionadded:: 2.11
24 Additional options accepted:
27 The style to use, can be a string or a Style subclass (default:
31 If set to true, monospace font will be used (default: ``true``).
34 If set to true, print the line numbers (default: ``false``).
37 Wrap lines to the specified number of characters. Disabled if set to 0
42 aliases = [
'groff',
'troff',
'roff']
48 self.
monospaced = get_bool_opt(options,
'monospaced',
True)
49 self.
linenos = get_bool_opt(options,
'linenos',
False)
51 self.
wrap = get_int_opt(options,
'wrap', 0)
59 regular =
'\\f[CR]' if self.
monospaced else '\\f[R]'
60 bold =
'\\f[CB]' if self.
monospaced else '\\f[B]'
61 italic =
'\\f[CI]' if self.
monospaced else '\\f[I]'
63 for ttype, ndef
in self.
style:
66 start +=
'\\m[%s]' % ndef[
'color']
75 start +=
'\\M[%s]' % ndef[
'bgcolor']
78 self.
styles[ttype] = start, end
83 for _, ndef
in self.
style:
84 if ndef[
'color']
is not None:
87 for color
in sorted(colors):
98 space =
' ' if self.
linenos else ''
101 if length > self.
wrap:
104 newline += (chunk +
'\n' + space)
105 remainder = length % self.
wrap
107 newline += line[-remainder-1:]
110 newline = (
'\n' + space) + line
121 replace(
'.',
'\\[char46]'). \
122 replace(
'\'',
'\\[u0027]'). \
123 replace(
'`',
'\\[u0060]'). \
124 replace(
'~',
'\\[u007E]')
131 .replace(
'x',
'u00') \
146 for ttype, value
in tokensource:
147 while ttype
not in self.
styles:
149 start, end = self.
styles[ttype]