def __call__(self, match): url = match.groups()[0] scheme, netloc, path, query, query, fragment = urlparse(url) if (scheme or netloc or not utils.is_markdown_file(path)): # Ignore URLs unless they are a relative link to a markdown file. return 'a href="%s"' % url if self.nav: # If the site navigation has been provided, then validate # the internal hyperlink, making sure the target actually exists. target_file = self.nav.file_context.make_absolute(path) if target_file not in self.nav.source_files: source_file = self.nav.file_context.current_file msg = ( 'The page "%s" contained a hyperlink to "%s" which ' 'is not listed in the "pages" configuration.' ) assert False, msg % (source_file, target_file) path = utils.get_url_path(target_file) path = self.nav.url_context.make_relative(path) else: path = utils.get_url_path(path).lstrip('/') # Convert the .md hyperlink to a relative hyperlink to the HTML page. url = urlunparse((scheme, netloc, path, query, query, fragment)) return 'a href="%s"' % url
def __call__(self, match): url = match.groups()[0] scheme, netloc, path, query, query, fragment = urlparse(url) if scheme or netloc: # Ignore URLs unless they are a relative link to a markdown file. return self.template % url if self.nav and not utils.is_markdown_file(path): path = utils.create_media_urls(self.nav, [path])[0] elif self.nav: # If the site navigation has been provided, then validate # the internal hyperlink, making sure the target actually exists. target_file = self.nav.file_context.make_absolute(path) if target_file not in self.nav.source_files: source_file = self.nav.file_context.current_file msg = ('The page "%s" contained a hyperlink to "%s" which ' 'is not listed in the "pages" configuration.') assert False, msg % (source_file, target_file) path = utils.get_url_path(target_file, self.nav.use_directory_urls) path = self.nav.url_context.make_relative(path) else: path = utils.get_url_path(path).lstrip('/') # Convert the .md hyperlink to a relative hyperlink to the HTML page. url = urlunparse((scheme, netloc, path, query, query, fragment)) return self.template % url
def path_to_url(url, nav): scheme, netloc, path, query, query, fragment = urlparse(url) if scheme or netloc or not path: # Ignore URLs unless they are a relative link to a markdown file. return url if nav and not utils.is_markdown_file(path): path = utils.create_media_urls(nav, [path])[0] elif nav: # If the site navigation has been provided, then validate # the internal hyperlink, making sure the target actually exists. target_file = nav.file_context.make_absolute(path) if target_file not in nav.source_files: source_file = nav.file_context.current_file msg = ( 'The page "%s" contained a hyperlink to "%s" which ' 'is not listed in the "pages" configuration.' ) assert False, msg % (source_file, target_file) path = utils.get_url_path(target_file, nav.use_directory_urls) path = nav.url_context.make_relative(path) else: path = utils.get_url_path(path).lstrip('/') # Convert the .md hyperlink to a relative hyperlink to the HTML page. url = urlunparse((scheme, netloc, path, query, query, fragment)) return url
def path_to_url(url, nav, strict): scheme, netloc, path, query, query, fragment = urlparse(url) if scheme or netloc or not path: # Ignore URLs unless they are a relative link to a markdown file. return url if nav and not utils.is_markdown_file(path): path = utils.create_relative_media_url(nav, path) elif nav: # If the site navigation has been provided, then validate # the internal hyperlink, making sure the target actually exists. target_file = nav.file_context.make_absolute(path) if target_file not in nav.source_files: source_file = nav.file_context.current_file msg = ( 'The page "%s" contained a hyperlink to "%s" which ' 'is not listed in the "pages" configuration.' ) % (source_file, target_file) # In strict mode raise an error at this point. if strict: raise MarkdownNotFound(msg) # Otherwise, when strict mode isn't enabled, print out a warning # to the user and leave the URL as it is. #print(msg) #return url path = utils.get_url_path(target_file, nav.use_directory_urls) path = nav.url_context.make_relative(path) else: path = utils.get_url_path(path).lstrip('/') # Convert the .md hyperlink to a relative hyperlink to the HTML page. url = urlunparse((scheme, netloc, path, query, query, fragment)) return url
def do_GET(self): """ The SimpleHTTPRequestHandler isn't designed to work with query strings. Everything we do with the query string is handle on the client-side, so throw it away here. """ scheme, netloc, path, query, query, fragment = urlparse(self.path) if query is not '': self.path = urlunparse((scheme, netloc, path, '', '', fragment)) return httpserver.SimpleHTTPRequestHandler.do_GET(self)