public void CodeToDesign() { if (idoc2 != null && idoc2.body != null) { //相对路径转绝对路径 string htmlCode = codeTextEditorControl.Text; string ostr = "${srs_"; while (htmlCode.IndexOf(ostr) > 0) { string mediaId = htmlCode.Substring(htmlCode.IndexOf(ostr) + 6, 32); SimpleExIndexXmlElement ele = Service.Sdsite.CurrentDocument.GetElementById(mediaId) as SimpleExIndexXmlElement; if (ele != null) { if (!ResourcesIdPaths.ContainsKey(ele.Id)) { ResourcesIdPaths.Add(ele.Id, ele.AbsoluteFilePath); } string PATH = SiteResourceService.ParseFormatId(ele.Id, true); htmlCode = htmlCode.Replace(htmlCode.Substring(htmlCode.IndexOf(ostr), 39), "file:///" + ele.AbsoluteFilePath.Replace("\\", "/")); } else { break; } } idoc2.body.innerHTML = htmlCode; } }
public void DesignToCode() { if (idoc2.body != null) { string codestr = idoc2.body.outerHTML;// GeneralMethods.tidy(); codestr = codestr.Replace(@"about:blank", "").Replace(@"about:", ""); //绝对路径转ID MatchCollection msImage = Utility.Regex.HtmlUrl.Matches(codestr); MatchCollection msMedia = Utility.Regex.HtmlMediaUrl.Matches(codestr); List <string> listFilePaths = new List <string>(); foreach (Match item in msImage) { listFilePaths.Add(item.Groups["path"].Value); } foreach (Match item in msMedia) { listFilePaths.Add(item.Groups["path"].Value); } foreach (string item in listFilePaths) { string ss = item.Replace("/", "\\").Replace("%20", " "); Debug.Assert(!string.IsNullOrEmpty(ss)); if (ResourcesIdPaths.ContainsValue(ss)) { string id = ""; foreach (KeyValuePair <string, string> idpath in ResourcesIdPaths) { if (idpath.Value == ss) { id = idpath.Key; break; } } Debug.Assert(!string.IsNullOrEmpty(id)); codestr = Utility.Regex.ReplaceAbsFileFilter(codestr, item, id); } } codestr = codestr.Replace("<BODY>", ""); codestr = codestr.Replace("</BODY>", ""); codeTextEditorControl.Text = codestr; // GeneralMethods.tidySpan(idoc2); } }
/// <summary> /// 元素绑定 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void designWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { IHTMLDocument3 pBody = ((IWebBrowser2)designWebBrowser.ActiveXInstance).Document as IHTMLDocument3; m_elemEvents.ConnectToHtmlEvents(pBody.documentElement); if (idoc2.body != null) { idoc2.body.innerHTML = _articleText; codeTextEditorControl.Text = GeneralMethods.tidy(idoc2.body.innerHTML); string htmlCode = codeTextEditorControl.Text; string ostr = "${srs_"; while (htmlCode.IndexOf(ostr) > 0) { string mediaId = htmlCode.Substring(htmlCode.IndexOf(ostr) + 6, 32); SimpleExIndexXmlElement ele = Service.Sdsite.CurrentDocument.GetElementById(mediaId) as SimpleExIndexXmlElement; if (ele != null) { if (!ResourcesIdPaths.ContainsKey(ele.Id)) { ResourcesIdPaths.Add(ele.Id, ele.AbsoluteFilePath); } string PATH = SiteResourceService.ParseFormatId(ele.Id, true); htmlCode = htmlCode.Replace(htmlCode.Substring(htmlCode.IndexOf(ostr), 39), "file:///" + ele.AbsoluteFilePath.Replace("\\", "/")); } else { break; } } } DesignToCode(); CodeToDesign(); }