scdoc.py 1.9 KB

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