public void TestUriUtility(string input, string path, string queryString, string fragment, string queryStringAndFragment, string nonFragment) { Assert.Equal(path, UriUtility.GetPath(input)); Assert.Equal(queryString, UriUtility.GetQueryString(input)); Assert.Equal(fragment, UriUtility.GetFragment(input)); Assert.Equal(queryStringAndFragment, UriUtility.GetQueryStringAndFragment(input)); Assert.Equal(nonFragment, UriUtility.GetNonFragment(input)); }
private void UpdateHref(HtmlNode link, string attribute, IDocumentBuildContext context, string sourceFilePath, string destFilePath) { var originalHref = link.GetAttributeValue(attribute, null); var anchor = link.GetAttributeValue("anchor", null); link.Attributes.Remove("anchor"); var originalPath = UriUtility.GetPath(originalHref); var path = RelativePath.TryParse(originalPath); if (path == null) { if (!string.IsNullOrEmpty(anchor)) { link.SetAttributeValue(attribute, originalHref + anchor); } return; } var fli = new FileLinkInfo { FromFileInSource = sourceFilePath, FromFileInDest = destFilePath, }; if (path.IsFromWorkingFolder()) { var targetInSource = path.UrlDecode(); fli.ToFileInSource = targetInSource.RemoveWorkingFolder(); fli.ToFileInDest = RelativePath.GetPathWithoutWorkingFolderChar(context.GetFilePath(targetInSource)); fli.FileLinkInSource = targetInSource - (RelativePath)sourceFilePath; if (fli.ToFileInDest != null) { var resolved = (RelativePath)fli.ToFileInDest - (RelativePath)destFilePath; fli.FileLinkInDest = resolved; fli.Href = resolved.UrlEncode(); } else { fli.Href = (targetInSource.RemoveWorkingFolder() - ((RelativePath)sourceFilePath).RemoveWorkingFolder()).UrlEncode(); } } else { fli.FileLinkInSource = path.UrlDecode(); fli.ToFileInSource = ((RelativePath)sourceFilePath + path).RemoveWorkingFolder(); fli.FileLinkInDest = fli.FileLinkInSource; fli.Href = originalPath; } var href = _settings.HrefGenerator?.GenerateHref(fli) ?? fli.Href; link.SetAttributeValue(attribute, href + UriUtility.GetQueryString(originalHref) + (anchor ?? UriUtility.GetFragment(originalHref))); }
private async Task <List <XRefSpec> > HandleCoreAsync(Task <List <XRefSpec> > task, string name, string value) { var list = await task; foreach (var item in list) { if (string.IsNullOrEmpty(item.Href)) { continue; } var mvc = HttpUtility.ParseQueryString(UriUtility.GetQueryString(item.Href)); mvc[name] = value; item.Href = UriUtility.GetPath(item.Href) + "?" + mvc.ToString() + UriUtility.GetFragment(item.Href); } return(list); }
private void UpdateHref(HtmlNode link, string attribute, IDocumentBuildContext context, string sourceFilePath, string destFilePath) { var originalHref = link.GetAttributeValue(attribute, null); var anchor = link.GetAttributeValue("anchor", null); link.Attributes.Remove("anchor"); var originalPath = UriUtility.GetPath(originalHref); var path = RelativePath.TryParse(originalPath); if (path == null) { if (!string.IsNullOrEmpty(anchor)) { link.SetAttributeValue(attribute, originalHref + anchor); } return; } var fli = FileLinkInfo.Create(sourceFilePath, destFilePath, originalPath, context); var href = _settings.HrefGenerator?.GenerateHref(fli) ?? fli.Href; link.SetAttributeValue(attribute, href + UriUtility.GetQueryString(originalHref) + (anchor ?? UriUtility.GetFragment(originalHref))); }