llvm.org GIT mirror llvm / a3ca2fa
[docs] Add support for Markdown documentation when creating man pages rL358749 added a documentation page in the Markdown format. Currently, such pages are ignored in the configuration script for manual pages. This patch fixes that. Differential Revision: https://reviews.llvm.org/D60964 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359860 91177308-0d34-0410-b5e6-96231b3b80d8 Igor Kudrin 1 year, 5 months ago
1 changed file(s) with 33 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
1010 # serve to show the default.
1111 from __future__ import print_function
1212
13 import sys, os
13 import sys, os, re
1414 from datetime import date
1515
1616 # If extensions (or modules to document with autodoc) are in another directory,
222222 man_page_authors = "Maintained by the LLVM Team (https://llvm.org/)."
223223 command_guide_subpath = 'CommandGuide'
224224 command_guide_path = os.path.join(basedir, command_guide_subpath)
225 for name in os.listdir(command_guide_path):
226 # Ignore non-ReST files and the index page.
227 if not name.endswith('.rst') or name in ('index.rst',):
228 continue
229
230 # Otherwise, automatically extract the description.
225
226
227 def process_md(name):
228 file_subpath = os.path.join(command_guide_subpath, name)
229 with open(os.path.join(command_guide_path, name)) as f:
230 title = f.readline().rstrip('\n')
231
232 m = re.match(r'^# (\S+) - (.+)$', title)
233 if m is None:
234 print("error: invalid title in %r "
235 "(expected '# - ')" % file_subpath,
236 file=sys.stderr)
237 else:
238 man_pages.append((file_subpath.replace('.md',''), m.group(1),
239 m.group(2), man_page_authors, 1))
240
241
242 def process_rst(name):
231243 file_subpath = os.path.join(command_guide_subpath, name)
232244 with open(os.path.join(command_guide_path, name)) as f:
233245 title = f.readline().rstrip('\n')
234246 header = f.readline().rstrip('\n')
235247
236248 if len(header) != len(title):
237 print((
238 "error: invalid header in %r (does not match title)" % (
239 file_subpath,)), file=sys.stderr)
249 print('error: invalid header in %r (does not match title)' %
250 file_subpath, file=sys.stderr)
240251 if ' - ' not in title:
241 print((
242 ("error: invalid title in %r "
243 "(expected ' - ')") % (
244 file_subpath,)), file=sys.stderr)
245
252 print("error: invalid title in %r "
253 "(expected ' - ')" % file_subpath,
254 file=sys.stderr)
246255 # Split the name out of the title.
247256 name,description = title.split(' - ', 1)
248257 man_pages.append((file_subpath.replace('.rst',''), name,
249258 description, man_page_authors, 1))
250259
260
261 for name in os.listdir(command_guide_path):
262 # Process Markdown files
263 if name.endswith('.md'):
264 process_md(name)
265 # Process ReST files apart from the index page.
266 elif name.endswith('.rst') and name != 'index.rst':
267 process_rst(name)
268
251269 # If true, show URL addresses after external links.
252270 #man_show_urls = False
253271