2009-08-28 7 views
6

से सभी अनावश्यक एमएस वर्ड स्वरूपण को पट्टी करने का कोई तरीका है मैंने एमके वर्ड से चिपकाया है और एमएस वर्ड से पेस्ट करते समय यह अनावश्यक प्रारूपण को जोड़ता है। मैं कुछ चीजों को बोल्ड, इटालिक्स, बुलेट्स और इतने आगे रखना चाहता हूं। मैंने वेब की खोज की है और ऐसे समाधानों के साथ आया है जो सबकुछ दूर ले जाता है जो मैं बोल्ड और इटालिक्स की तरह रखना चाहता था। क्या अनावश्यक शब्द स्वरूपण को पट्टी करने का कोई तरीका है?FCKEditor

+0

किसी को भी जो कभी एक सीएमएस को बनाए रखा है बुराई जिनमें से आप बात जानता है के लिए काम किया। जवाब खोजने के लिए शुभकामनाएँ। हम उन्हें बस शब्द से पेस्ट करते हैं और फिर मेरे पास एक प्रोग्राम था जो डेटाबेस से अवांछित वर्ण हटा देता था। – Steve

उत्तर

7

यहाँ एक समाधान मैं साफ़ करने से आने वाली HTML का उपयोग है समृद्ध पाठ संपादक ... यह VB.NET में लिखा गया है और मेरे पास सी # में कनवर्ट करने का समय नहीं है, लेकिन यह बहुत सरल है:

Public Shared Function CleanHtml(ByVal html As String) As String 
    '' Cleans all manner of evils from the rich text editors in IE, Firefox, Word, and Excel 
    '' Only returns acceptable HTML, and converts line breaks to <br /> 
    '' Acceptable HTML includes HTML-encoded entities. 
    html = html.Replace("&" & "nbsp;", " ").Trim() ' concat here due to SO formatting 
    '' Does this have HTML tags? 
    If html.IndexOf("<") >= 0 Then 
     '' Make all tags lowercase 
     html = RegEx.Replace(html, "<[^>]+>", AddressOf LowerTag) 
     '' Filter out anything except allowed tags 
     '' Problem: this strips attributes, including href from a 
     '' http://stackoverflow.com/questions/307013/how-do-i-filter-all-html-tags-except-a-certain-whitelist 
     Dim AcceptableTags  As String = "i|b|u|sup|sub|ol|ul|li|br|h2|h3|h4|h5|span|div|p|a|img|blockquote" 
     Dim WhiteListPattern As String = "</?(?(?=" & AcceptableTags & ")notag|[a-zA-Z0-9]+)(?:\s[a-zA-Z0-9\-]+=?(?:([""']?).*?\1?)?)*\s*/?>" 
     html = Regex.Replace(html, WhiteListPattern, "", RegExOptions.Compiled) 
     '' Make all BR/br tags look the same, and trim them of whitespace before/after 
     html = RegEx.Replace(html, "\s*<br[^>]*>\s*", "<br />", RegExOptions.Compiled) 
    End If 
    '' No CRs 
    html = html.Replace(controlChars.CR, "") 
    '' Convert remaining LFs to line breaks 
    html = html.Replace(controlChars.LF, "<br />") 
    '' Trim BRs at the end of any string, and spaces on either side 
    Return RegEx.Replace(html, "(<br />)+$", "", RegExOptions.Compiled).Trim() 
End Function 

Public Shared Function LowerTag(m As Match) As String 
    Return m.ToString().ToLower() 
End Function 

आपके मामले में, आप "अनुमोदित" "AcceptableTags" में HTML टैग की सूची में बदलाव करना चाहेंगे - कोड अभी भी सभी बेकार विशेषताएं (और, हटेगा दुर्भाग्य से, HREF की तरह उपयोगी लोगों और एसआरसी, उम्मीद है कि वे आपके लिए महत्वपूर्ण नहीं हैं)।

बेशक, इसके लिए सर्वर की यात्रा की आवश्यकता है। यदि आप इसे नहीं चाहते हैं, तो आपको टूलबार पर कुछ प्रकार का "क्लीन अप" बटन जोड़ना होगा जो जावास्क्रिप्ट को संपादक के वर्तमान टेक्स्ट के साथ गड़बड़ करने के लिए कहता है। दुर्भाग्यवश, "चिपकाना" एक ऐसी घटना नहीं है जिसे स्वचालित रूप से मार्कअप को साफ करने के लिए फंस लिया जा सके, और प्रत्येक ऑनचेंज के बाद सफाई एक अनुपयोगी संपादक के लिए तैयार करेगी (क्योंकि मार्कअप बदलने से टेक्स्ट कर्सर स्थिति बदल जाती है)।

+0

वाह .. यह कमाल है। लेकिन मुझे लिंक और बुनियादी HTML टैग की आवश्यकता है – user161433

0

लेकिन नाम और वेबसाइट के रूप में fckeditor है, टेक्स्ट एडिटर। मेरे लिए, इसका मतलब है कि यह आपको फ़ाइल में वर्ण दिखाता है।

आप कुछ अतिरिक्त पात्रों के बिना बोल्ड और इटैलिक स्वरूपण नहीं कर सकते हैं।

संपादित करें: आह, मैं देखता हूं। Fckeditor वेबसाइट पर अधिक बारीकी से देख रहे हैं, यह एक HTML संपादक है, जो कि मेरे द्वारा उपयोग किए जाने वाले साधारण टेक्स्ट संपादकों में से एक नहीं है।

Paste from Word cleanup with autodetection एक सुविधा के रूप में सूचीबद्ध है।

+0

पैवियम, फ्लेडिटर एक रिच टेक्स्ट संपादक है, संपादन योग्य डीआईवी का उपयोग करने की सभी नैतिकता को सारणीबद्ध करता है और सुंदर टूलबार जोड़ता है। हुड के तहत, यह HTML में संग्रहीत है, जिसका अर्थ है कि जब कोई शब्द से चिपकता है, तो शब्द इसे HTML ईविलनेस के सभी प्रकार से गुजरता है। – richardtallent

2

मैं समस्या को बहुत अच्छी तरह समझता हूं। जब एमएस-वर्ड (या किसी भी शब्द प्रसंस्करण या समृद्ध पाठ संपादन जागरूक पाठ क्षेत्र) से बाहर निकलते हैं तो FCKEditor में चिपकाते हैं (एक ही समस्या TinyMCE के साथ होती है), मूल मार्कअप क्लिपबोर्ड में क्या होता है और संसाधित हो जाता है। यह मार्कअप हमेशा मार्कअप के साथ मानार्थ नहीं है कि यह पेस्ट ऑपरेशन के लक्ष्य के साथ एम्बेडेड हो जाता है।

मुझे FCKEditor में योगदानकर्ता बनने और कोड का अध्ययन करने और संशोधन करने के अलावा अन्य समाधान नहीं पता है। मैं आमतौर पर जो करता हूं वह उपयोगकर्ताओं को दो चरण क्लिपबोर्ड ऑपरेशन करने के लिए निर्देश देता है। नोटपैड में एमएस-वर्ड

  • पेस्ट से

    • कॉपी
    • FCKeditor में
    • पेस्ट नोटपैड से सभी
    • कॉपी का चयन करें
  • 8

    शायद ज़रुरत पड़े किसी स्वीकार किए जाते हैं जवाब की एक सी # संस्करण चाहता है:

    public string CleanHtml(string html) 
        { 
         //Cleans all manner of evils from the rich text editors in IE, Firefox, Word, and Excel 
         // Only returns acceptable HTML, and converts line breaks to <br /> 
         // Acceptable HTML includes HTML-encoded entities. 
    
         html = html.Replace("&" + "nbsp;", " ").Trim(); //concat here due to SO formatting 
         // Does this have HTML tags? 
    
         if (html.IndexOf("<") >= 0) 
         { 
          // Make all tags lowercase 
          html = Regex.Replace(html, "<[^>]+>", delegate(Match m){ 
           return m.ToString().ToLower(); 
          }); 
          // Filter out anything except allowed tags 
          // Problem: this strips attributes, including href from a 
          // http://stackoverflow.com/questions/307013/how-do-i-filter-all-html-tags-except-a-certain-whitelist 
          string AcceptableTags = "i|b|u|sup|sub|ol|ul|li|br|h2|h3|h4|h5|span|div|p|a|img|blockquote"; 
          string WhiteListPattern = "</?(?(?=" + AcceptableTags + @")notag|[a-zA-Z0-9]+)(?:\s[a-zA-Z0-9\-]+=?(?:([""']?).*?\1?)?)*\s*/?>"; 
          html = Regex.Replace(html, WhiteListPattern, "", RegexOptions.Compiled); 
          // Make all BR/br tags look the same, and trim them of whitespace before/after 
          html = Regex.Replace(html, @"\s*<br[^>]*>\s*", "<br />", RegexOptions.Compiled); 
         } 
    
    
         // No CRs 
         html = html.Replace("\r", ""); 
         // Convert remaining LFs to line breaks 
         html = html.Replace("\n", "<br />"); 
         // Trim BRs at the end of any string, and spaces on either side 
         return Regex.Replace(html, "(<br />)+$", "", RegexOptions.Compiled).Trim(); 
        } 
    
    3

    स्वीकार कर लिया समाधान की कोशिश की लेकिन यह शब्द उत्पन्न टैग साफ नहीं किया।

    लेकिन this code मुझे

    स्थिर स्ट्रिंग CleanWordHtml (स्ट्रिंग एचटीएमएल) {

    StringCollection sc = new StringCollection(); 
    // get rid of unnecessary tag spans (comments and title) 
    sc.Add(@"<!--(\w|\W)+?-->"); 
    sc.Add(@"<title>(\w|\W)+?</title>"); 
    // Get rid of classes and styles 
    sc.Add(@"\s?class=\w+"); 
    sc.Add(@"\s+style='[^']+'"); 
    // Get rid of unnecessary tags 
    sc.Add(
    @"<(meta|link|/?o:|/?style|/?div|/?st\d|/?head|/?html|body|/?body|/?span|!\[)[^>]*?>"); 
    // Get rid of empty paragraph tags 
    sc.Add(@"(<[^>]+>)+&nbsp;(</\w+>)+"); 
    // remove bizarre v: element attached to <img> tag 
    sc.Add(@"\s+v:\w+=""[^""]+"""); 
    // remove extra lines 
    sc.Add(@"(\n\r){2,}"); 
    foreach (string s in sc) 
    { 
        html = Regex.Replace(html, s, "", RegexOptions.IgnoreCase); 
    } 
    return html; 
    } 
    
    संबंधित मुद्दे