Rizin
unix-like reverse engineering framework and cli tools
manpage.py
Go to the documentation of this file.
1 # encoding: utf-8
2 
3 #
4 # Copyright (c) 2013 Dariusz Dwornikowski. All rights reserved.
5 #
6 # Adapted from https://github.com/tdi/sphinxcontrib-manpage
7 # License: Apache 2
8 #
9 
10 
11 import re
12 
13 from docutils import nodes, utils
14 from docutils.parsers.rst.roles import set_classes
15 from string import Template
16 
17 
18 def make_link_node(rawtext, app, name, manpage_num, options):
19  ref = app.config.man_url_regex
20  if not ref:
21  ref = "https://man7.org/linux/man-pages/man%s/%s.%s.html" %(manpage_num, name, manpage_num)
22  else:
23  s = Template(ref)
24  ref = s.substitute(num=manpage_num, topic=name)
25  set_classes(options)
26  node = nodes.reference(rawtext, "%s(%s)" % (name, manpage_num), refuri=ref, **options)
27  return node
28 
29 
30 def man_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
31  app = inliner.document.settings.env.app
32  p = re.compile("([a-zA-Z0-9_\.-_]+)\‍((\d)\‍)")
33  m = p.match(text)
34 
35  manpage_num = m.group(2)
36  name = m.group(1)
37  node = make_link_node(rawtext, app, name, manpage_num, options)
38  return [node], []
39 
40 
41 def setup(app):
42  app.add_role('man', man_role)
43  app.add_config_value('man_url_regex', None, 'env')
44  return
45 
def make_link_node(rawtext, app, name, manpage_num, options)
Definition: manpage.py:18
def man_role(name, rawtext, text, lineno, inliner, options={}, content=[])
Definition: manpage.py:30
def setup(app)
Definition: manpage.py:41