Commits

Etienne Perot committed 7e4efa4

Use link name as title in included markdown files

Comments (0)

Files changed (1)

res/process-include.py

 import os, re, markdown, filefilter
 
 rInclude = re.compile(r'<include([^<>]*)>((?:(?!</include>).)+)</include>', re.IGNORECASE)
+rLinkMatch = re.compile(r'^\[([^]\r\n]+)\]:[ \t]*(\S+)(?:[ \t]+([^\r\n]+))?', re.MULTILINE)
+
+def handleLink(match):
+	url = match.group(2)
+	if '/' not in url:
+		url = (self.resourceUrl + '/' + url).replace('//', '/')
+	title = match.group(3)
+	if not title:
+		title = '"' + match.group(1) + '"'
+	return '[' + match.group(1) + ']: ' + url + ' ' + title
 
 def processInclude(f, m):
 	toInclude = filefilter.findFile(f, m.group(2).strip())
 	content = handle.read(-1)
 	handle.close()
 	if isMarkdown:
+		content = rLinkMatch.sub(handleLink, content)
 		content = markdown.Markdown(
 			extensions=['codehilite', 'meta', 'sane_lists'],
 			extensions_configs={},