|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.scdoc |
|
4 ~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexer for scdoc, a simple man page generator. |
|
7 |
|
8 :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 import re |
|
13 |
|
14 from pygments.lexer import RegexLexer, include, bygroups, \ |
|
15 using, this |
|
16 from pygments.token import Text, Comment, Keyword, String, \ |
|
17 Generic |
|
18 |
|
19 |
|
20 __all__ = ['ScdocLexer'] |
|
21 |
|
22 |
|
23 class ScdocLexer(RegexLexer): |
|
24 """ |
|
25 `scdoc` is a simple man page generator for POSIX systems written in C99. |
|
26 https://git.sr.ht/~sircmpwn/scdoc |
|
27 |
|
28 .. versionadded:: 2.5 |
|
29 """ |
|
30 name = 'scdoc' |
|
31 aliases = ['scdoc', 'scd'] |
|
32 filenames = ['*.scd', '*.scdoc'] |
|
33 flags = re.MULTILINE |
|
34 |
|
35 tokens = { |
|
36 'root': [ |
|
37 # comment |
|
38 (r'^(;.+\n)', bygroups(Comment)), |
|
39 |
|
40 # heading with pound prefix |
|
41 (r'^(#)([^#].+\n)', bygroups(Generic.Heading, Text)), |
|
42 (r'^(#{2})(.+\n)', bygroups(Generic.Subheading, Text)), |
|
43 # bulleted lists |
|
44 (r'^(\s*)([*-])(\s)(.+\n)', |
|
45 bygroups(Text, Keyword, Text, using(this, state='inline'))), |
|
46 # numbered lists |
|
47 (r'^(\s*)(\.+\.)( .+\n)', |
|
48 bygroups(Text, Keyword, using(this, state='inline'))), |
|
49 # quote |
|
50 (r'^(\s*>\s)(.+\n)', bygroups(Keyword, Generic.Emph)), |
|
51 # text block |
|
52 (r'^(```\n)([\w\W]*?)(^```$)', bygroups(String, Text, String)), |
|
53 |
|
54 include('inline'), |
|
55 ], |
|
56 'inline': [ |
|
57 # escape |
|
58 (r'\\.', Text), |
|
59 # underlines |
|
60 (r'(\s)(_[^_]+_)(\W|\n)', bygroups(Text, Generic.Emph, Text)), |
|
61 # bold |
|
62 (r'(\s)(\*[^\*]+\*)(\W|\n)', bygroups(Text, Generic.Strong, Text)), |
|
63 # inline code |
|
64 (r'`[^`]+`', String.Backtick), |
|
65 |
|
66 # general text, must come last! |
|
67 (r'[^\\\s]+', Text), |
|
68 (r'.', Text), |
|
69 ], |
|
70 } |