Exemple #1
0
        public void DiffHTML()
        {
            WikiDiff d = new WikiDiff();

            string diffResult = d.GetDiff(@"A1
A2", @"A1
A2", 2);

            Assert.AreEqual(@"", diffResult, "No HTML when no change");

            diffResult = d.GetDiff(@"A1
A2", @"A1X
A2", 2).Replace(System.Environment.NewLine, " ");

            diffResult = Regex.Replace(diffResult, @"\s+", " ");

            Assert.AreEqual(@"<tr onclick='window.external.GoTo(0)'> <td colspan='2' class='diff-lineno'>Line 1:</td> <td colspan='2' class='diff-lineno'>Line 1:</td> </tr><tr onclick='window.external.GoTo(0)' ondblclick='window.external.UndoChange(0,0)'> <td>-</td> <td class='diff-deletedline'><span class='diffchange'>A1</span> </td> <td>+</td> <td class='diff-addedline'><span class='diffchange'>A1X</span> </td> </tr><tr onclick='window.external.GoTo(1);'> <td class='diff-marker'> </td> <td class='diff-context'>A2</td> <td class='diff-marker'> </td> <td class='diff-context'>A2</td> </tr>", diffResult, "Standard case: first line changed");

            diffResult = d.GetDiff(@"A1
A2", @"A1X
A2X", 2).Replace(System.Environment.NewLine, " ");

            diffResult = Regex.Replace(diffResult, @"\s+", " ");

            Assert.AreEqual(@"<tr onclick='window.external.GoTo(0)'> <td colspan='2' class='diff-lineno'>Line 1:</td> <td colspan='2' class='diff-lineno'>Line 1:</td> </tr><tr onclick='window.external.GoTo(0)' ondblclick='window.external.UndoChange(0,0)'> <td>-</td> <td class='diff-deletedline'><span class='diffchange'>A1</span> </td> <td>+</td> <td class='diff-addedline'><span class='diffchange'>A1X</span> </td> </tr><tr onclick='window.external.GoTo(1)' ondblclick='window.external.UndoChange(1,1)'> <td>-</td> <td class='diff-deletedline'><span class='diffchange'>A2</span> </td> <td>+</td> <td class='diff-addedline'><span class='diffchange'>A2X</span> </td> </tr>", diffResult, "Standard case: two lines changed");

            diffResult = d.GetDiff(@"A1
A2", @"A1", 2).Replace(System.Environment.NewLine, " ");

            diffResult = Regex.Replace(diffResult, @"\s+", " ");

            Assert.AreEqual(@"<tr onclick='window.external.GoTo(0);'> <td class='diff-marker'> </td> <td class='diff-context'>A1</td> <td class='diff-marker'> </td> <td class='diff-context'>A1</td> </tr><tr> <td>-</td> <td class='diff-deletedline' onclick='window.external.GoTo(1)' ondblclick='window.external.UndoDeletion(1, 1)'>A2 </td> <td> </td> <td> </td> </tr>", diffResult, "Standard case: second line deleted");
        }
        public void C_OnArticleCacheReady(ArticleCache articleCache)
        {
            string text =
                ("<!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
                 + "<html><head>" +
                 WikiDiff.DiffHead() + @"</head><body>"
                 + WikiDiff.TableHeader +
                 Diff.GetDiff(articleCache.Article_WikiContent, articleCache.TranslatedArticle_Content, 2) +
                 "</table></body></html>");



            try
            {
                if (InvokeMyWebBrowserEvent != null)
                {
                    this.Invoke(InvokeMyWebBrowserEvent, text);
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.Handle(ex);
            }



            //GetDifferences(articleCache.Article_WikiContent, articleCache.TranslatedArticle_Content);
        }
Exemple #3
0
        public static void GenerateAndSaveDiff(string beforeContent, string afterContent, string title, long id, string directory, string folderName)
        {
            beforeContent = beforeContent.Replace("\n", "\r\n");
            afterContent  = afterContent.Replace("\n", "\r\n");
            var    wikiDiff = new WikiDiff();
            string diff     = $"{WikiDiff.DiffHead()}</head><body>{WikiDiff.TableHeader}{wikiDiff.GetDiff(beforeContent, afterContent, 1)}</table></body></html>";
            string filename = "Diff-" + id + "-" + title + ".txt"; //Set filename for this page

            filename = SanitizeFilename(filename, '_');

            string filePath = Path.Combine(directory, folderName, filename);

            File.WriteAllText(filePath, diff);
        }
Exemple #4
0
        public void GetDifferences(string originalText, string changedText)
        {
            try
            {
                webBrowser.BringToFront();
                if (webBrowser.Document == null)
                {
                    return;
                }

                webBrowser.Document.OpenNew(false);
                if (changedText == originalText)
                {
                    webBrowser.Document.Write(
                        @"<h2 style='padding-top: .5em;
padding-bottom: .17em;
border-bottom: 1px solid #aaa;
font-size: 150%;'>No changes</h2><p>Press the ""Source"" button to skip to write in Hindi and click on translate to Nepali to translate.</p>");
                }
                else
                {
                    // when less than 10 edits show user help info on double click to undo etc.
                    webBrowser.Document.Write("<!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
                                              + "<html><head>" +
                                              WikiDiff.DiffHead() + @"</head><body>"
                                              + WikiDiff.TableHeader +
                                              Diff.GetDiff(originalText, changedText, 2) +
                                              "</table>" + /*"<!--<script language='Javascript'>
                                                            * // Scroll part of the way into the table, disabled due to other interface problems
                                                            * diffNode=document.getElementById('wikiDiff');
                                                            * var diffTopY = 0;
                                                            * while(diffNode) {
                                                            * diffTopY += diffNode.offsetTop;
                                                            * diffNode = diffNode.offsetParent;
                                                            * }
                                                            * window.scrollTo(0, diffTopY);
                                                            * </script>-->"*/"</body></html>");
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.Handle(ex);
            }
        }
Exemple #5
0
        public void UndoDeletion()
        {
            WikiDiff d = new WikiDiff();

            d.GetDiff(@"
A1
A2", @"A1
A2", 2);

            Assert.AreEqual(@"
A1
A2", d.UndoDeletion(0, 0), "Undo of delete first blank line");

            d = new WikiDiff();

            d.GetDiff(@"A1
A2
", @"A1
A2", 2);

            Assert.AreEqual(@"A1
A2
", d.UndoDeletion(2, 2), "Undo of delete last blank line");
        }