private static string getKewords(HTMLchunk[] chunks, Menees.DiffUtils.EditScript edits) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); //get an iterator for the changes System.Collections.IEnumerator it = edits.GetEnumerator(); while (it.MoveNext()) { Menees.DiffUtils.Edit curr = (Menees.DiffUtils.Edit)it.Current; //append only new text additions to versionB if (curr.Type == EditType.Insert || curr.Type == EditType.Change) { for (int i = 0; i < curr.Length; i++) { //append only text changes if (chunks[curr.StartB + i].oType == HTMLchunkType.Text) { sb.Append(" " + chunks[curr.StartB + i].oHTML); } } } } return(sb.ToString()); }
private static string getMarkedUpHtml(HTMLchunk[] chunks, Menees.DiffUtils.EditScript edits, bool isOlderVersion) { string[] str = new string[chunks.Length]; for (int i = 0; i < str.Length; i++) { str[i] = chunks[i].oHTML; } //get an iterator for the changes System.Collections.IEnumerator it = edits.GetEnumerator(); //for now only mark up text nodes!!! this needs improvement while (it.MoveNext()) { Menees.DiffUtils.Edit curr = (Menees.DiffUtils.Edit)it.Current; int start = (isOlderVersion ? curr.StartA : curr.StartB); switch (curr.Type) { case Menees.DiffUtils.EditType.Change: for (int i = 0; i < curr.Length; i++) { if (chunks[start + i].oType == HTMLchunkType.Text) { str[start + i] = (isOlderVersion ? Tags.changeDelete : Tags.changeAdd) + str[start + i] + Tags.close; } } break; case Menees.DiffUtils.EditType.Delete: //deletes are marked in the older version if (isOlderVersion) { for (int i = 0; i < curr.Length; i++) { if (chunks[start + i].oType == HTMLchunkType.Text) { str[start + i] = Tags.delete + str[start + i] + Tags.close; } } } break; case Menees.DiffUtils.EditType.Insert: //Inserts are marked in the newer version if (!isOlderVersion) { for (int i = 0; i < curr.Length; i++) { if (chunks[start + i].oType == HTMLchunkType.Text) { str[start + i] = Tags.add + str[start + i] + Tags.close; } } } break; } } return(String.Join("", str)); }
private static string getMarkedUpSource(HTMLchunk[] chunks, Menees.DiffUtils.EditScript edits, bool isOlderVersion) { string[] str = new string[chunks.Length]; //html encode the source so it wont render for (int i = 0; i < str.Length; i++) { str[i] = System.Web.HttpUtility.HtmlEncode(chunks[i].oHTML); } //get an iterator for the changes System.Collections.IEnumerator it = edits.GetEnumerator(); while (it.MoveNext()) { Menees.DiffUtils.Edit curr = (Menees.DiffUtils.Edit)it.Current; int start = (isOlderVersion ? curr.StartA : curr.StartB); switch (curr.Type) { case Menees.DiffUtils.EditType.Change: //changes are marked as deletes in older version and adds in newer version str[start] = (isOlderVersion ? Tags.changeDelete : Tags.changeAdd) + str[start]; str[start + curr.Length] += Tags.close; break; case Menees.DiffUtils.EditType.Delete: //deletes are marked in the older version if (isOlderVersion) { str[start] = Tags.delete + str[start]; str[start + curr.Length] += Tags.close; } break; case Menees.DiffUtils.EditType.Insert: //Inserts are marked in the newer version if (!isOlderVersion) { str[start] = Tags.add + str[start]; str[start + curr.Length] += Tags.close; } break; } } return(String.Join("", str)); }