def path_to_url(self, url): scheme, netloc, path, params, query, fragment = urlparse(url) if (scheme or netloc or not path or url.startswith('/') or AMP_SUBSTITUTE in url or '.' not in os.path.split(path)[-1]): # Ignore URLs unless they are a relative link to a source file. # AMP_SUBSTITUTE is used internally by Markdown only for email. # No '.' in the last part of a path indicates path does not point to a file. return url # Determine the filepath of the target. target_path = os.path.join(os.path.dirname(self.file.src_path), urlunquote(path)) target_path = os.path.normpath(target_path).lstrip(os.sep) # Validate that the target exists in files collection. if target_path not in self.files: log.warning( "Documentation file '{}' contains a link to '{}' which is not found " "in the documentation files.".format(self.file.src_path, target_path) ) return url target_file = self.files.get_file_from_path(target_path) path = target_file.url_relative_to(self.file) components = (scheme, netloc, path, params, query, fragment) return urlunparse(components)
def path_to_url(self, url): scheme, netloc, path, params, query, fragment = urlparse(url) if scheme or netloc or not path or AMP_SUBSTITUTE in url or '.' not in os.path.split( path)[-1]: # Ignore URLs unless they are a relative link to a source file. # AMP_SUBSTITUTE is used internally by Markdown only for email. # No '.' in the last part of a path indicates path does not point to a file. return url # Determine the filepath of the target. target_path = os.path.join(os.path.dirname(self.file.src_path), path) target_path = os.path.normpath(target_path).lstrip(os.sep) # Validate that the target exists in files collection. if target_path not in self.files: msg = ( "Documentation file '{}' contains a link to '{}' which does not exist " "in the documentation directory.".format( self.file.src_path, target_path)) # In strict mode raise an error at this point. if self.strict: raise MarkdownNotFound(msg) # Otherwise, when strict mode isn't enabled, log a warning # to the user and leave the URL as it is. log.warning(msg) return url target_file = self.files.get_file_from_path(target_path) path = target_file.url_relative_to(self.file) components = (scheme, netloc, path, params, query, fragment) return urlunparse(components)
def munge(url): scheme, netloc, path, params, query, fragment = (utils.urlparse(url)) if scheme or netloc or not path: # Ignore URLs unless they are a relative link to a markdown file. return url if not path.endswith(".md"): return url else: path = path.replace(".md", ".html") # Convert the .md hyperlink to a relative hyperlink to the HTML page. fragments = (scheme, netloc, path, params, query, fragment) url = utils.urlunparse(fragments) return url
def munge(url): scheme, netloc, path, params, query, fragment = ( utils.urlparse(url)) if scheme or netloc or not path: # Ignore URLs unless they are a relative link to a markdown file. return url if not path.endswith(".md"): return url else: path = path.replace(".md",".html"); # Convert the .md hyperlink to a relative hyperlink to the HTML page. fragments = (scheme, netloc, path, params, query, fragment) url = utils.urlunparse(fragments) return url
def path_to_url(url, nav, strict): scheme, netloc, path, params, query, fragment = ( utils.urlparse(url)) if scheme or netloc or not path or AMP_SUBSTITUTE in url: # Ignore URLs unless they are a relative link to a markdown file. # AMP_SUBSTITUTE is used internally by Markdown only for email,which is # not a relative link. As urlparse errors on them, skip explicitly 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.startswith(os.path.sep): target_file = target_file[1:] 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, log a warning # to the user and leave the URL as it is. log.warning(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. fragments = (scheme, netloc, path, params, query, fragment) url = utils.urlunparse(fragments) return url
def path_to_url(url, nav, strict): scheme, netloc, path, params, query, fragment = (utils.urlparse(url)) if scheme or netloc or not path or AMP_SUBSTITUTE in url: # Ignore URLs unless they are a relative link to a markdown file. # AMP_SUBSTITUTE is used internally by Markdown only for email,which is # not a relative link. As urlparse errors on them, skip explicitly 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.startswith(os.path.sep): target_file = target_file[1:] 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, log a warning # to the user and leave the URL as it is. # suppress the Warning # log.warning(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. fragments = (scheme, netloc, path, params, query, fragment) url = utils.urlunparse(fragments) return url