Removes comments ('<!-- ... >' and '<![ ... ]>') from an html source.
Inheritance: IHTMLCleaner
        public void TestCleaner()
        {
            bool canLoadXML = false;
            initialHTML = new CommentsRemover().Clean(initialHTML);
            Assert.AreEqual(initialHTML, expectedHTML);

            try
            {
                new XmlDocument().LoadXml(initialHTML);
                canLoadXML = true;
            }
            catch
            {
                canLoadXML = false;
            }

            Assert.IsTrue(canLoadXML);
        }
Esempio n. 2
0
        /// <summary>
        /// Saves the currently edited page or document to the server.
        /// </summary>
        private void SaveToXWiki()
        {
            try
            {
                String contentFilePath = "";
                addin.ReinforceApplicationOptions();
                String filePath = addin.ActiveDocumentFullName;
                String currentFileName = Path.GetDirectoryName(addin.ActiveDocumentFullName);
                currentFileName += "\\" + Path.GetFileNameWithoutExtension(addin.ActiveDocumentFullName);
                String tempExportFileName = currentFileName + "_TempExport.html";
                if (!ShadowCopyDocument(addin.ActiveDocumentInstance, tempExportFileName, addin.SaveFormat))
                {
                    UserNotifier.Error(UIMessages.ERROR_SAVING_PAGE);
                    return;
                }
                contentFilePath = tempExportFileName;
                StreamReader sr = new StreamReader(contentFilePath);
                String fileContent = sr.ReadToEnd();
                sr.Close();
                File.Delete(contentFilePath);
                String cleanHTML = "";

                cleanHTML = new CommentsRemover().Clean(fileContent);
                cleanHTML = new HeadSectionRemover().Clean(cleanHTML);

                ConversionManager pageConverter;
                if (pageConverters.ContainsKey(addin.CurrentPageFullName))
                {
                    pageConverter = pageConverters[addin.CurrentPageFullName];
                }
                else
                {
                    pageConverter = new ConversionManager(addin.ServerURL, Path.GetDirectoryName(contentFilePath),
                                                          addin.CurrentPageFullName, Path.GetFileName(contentFilePath), addin.Client);
                }
                cleanHTML = pageConverter.ConvertFromWordToWeb(cleanHTML);
                cleanHTML = new BodyContentExtractor().Clean(cleanHTML);

                if (addin.AddinStatus.Syntax == null)
                {
                    addin.AddinStatus.Syntax = addin.DefaultSyntax;
                }

                //Convert the source to the propper encoding.
                Encoding iso = Client.ServerEncoding;
                byte[] content = Encoding.Unicode.GetBytes(cleanHTML);
                byte[] wikiContent = null;
                wikiContent = Encoding.Convert(Encoding.Unicode, iso, content);
                cleanHTML = iso.GetString(wikiContent);
                SavePage(addin.CurrentPageFullName, ref cleanHTML, addin.AddinStatus.Syntax);
            }
            catch (COMException ex)
            {
                string message = "An internal Word error appeared when trying to save your file.";
                message += Environment.NewLine + ex.Message;
                Log.Exception(ex);
                UserNotifier.Error(message);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Saves the currently edited page or document to the server.
        /// </summary>
        private void SaveToXwiki()
        {
            try
            {
                addin.AnnotationMaintainer.ClearComments();
                String contentFilePath = "";
                addin.ReinforceApplicationOptions();
                String filePath = addin.ActiveDocumentFullName;
                String currentFileName = Path.GetDirectoryName(addin.ActiveDocumentFullName);
                currentFileName += "\\" + Path.GetFileNameWithoutExtension(addin.ActiveDocumentFullName);
                String tempExportFileName = currentFileName + "_TempExport.html";
                if (!ShadowCopyDocument(addin.ActiveDocumentInstance, tempExportFileName, addin.SaveFormat))
                {
                    ReportSaveProblem();
                    return;
                }
                contentFilePath = tempExportFileName;
                StreamReader sr = new StreamReader(contentFilePath, Client.ServerEncoding);
                String fileContent = sr.ReadToEnd();
                sr.Close();
                File.Delete(contentFilePath);
                String cleanHTML = "";

                cleanHTML = new CommentsRemover().Clean(fileContent);
                cleanHTML = new HeadSectionRemover().Clean(cleanHTML);

                ConversionManager pageConverter;
                if (pageConverters.ContainsKey(addin.currentPageFullName))
                {
                    pageConverter = pageConverters[addin.currentPageFullName];
                }
                else
                {
                    pageConverter = new ConversionManager(addin.AddinSettings, addin.serverURL, Path.GetDirectoryName(contentFilePath),
                                                          addin.currentPageFullName, Path.GetFileName(contentFilePath), addin.Client);
                }
                cleanHTML = pageConverter.ConvertFromWordToWeb(cleanHTML);

                SSXManager ssxManager = SSXManager.BuildFromLocalHTML(pageConverter, cleanHTML);

                cleanHTML = new BodyContentExtractor().Clean(cleanHTML);

                //openHTMLDocument(addin.currentLocalFilePath);
                if (addin.AddinStatus.Syntax == null)
                {
                    addin.AddinStatus.Syntax = addin.DefaultSyntax;
                }

                if (SavePage(addin.currentPageFullName, ref cleanHTML, addin.AddinStatus.Syntax))
                {
                    ssxManager.UploadStyleSheetExtensions();
                    pageConverter.UploadAttachments();
                    addin.AnnotationMaintainer.UpdateAnnotations();
                }
            }
            catch (COMException ex)
            {
                string message = "An internal Word error appeared when trying to save your file.";
                message += Environment.NewLine + ex.Message;
                Log.Exception(ex);
                UserNotifier.Error(message);
            }
        }