SetElementFromUserStringPreservingLineBreaks() public static method

public static SetElementFromUserStringPreservingLineBreaks ( XmlElement node, string form ) : void
node System.Xml.XmlElement
form string
return void
Example #1
0
        private static void CopyItemToFieldsInPages(HtmlDom dom, string key, string valueAttribute = null, string[] languagePreferences = null)
        {
            if (languagePreferences == null)
            {
                languagePreferences = new[] { "*", "en" }
            }
            ;

            MultiTextBase source = dom.GetBookSetting(key);

            foreach (XmlElement target in dom.SafeSelectNodes("//*[@data-derived='" + key + "']"))
            {
                //just put value into the text of the element
                if (string.IsNullOrEmpty(valueAttribute))
                {
                    //clear out what's there now
                    target.RemoveAttribute("lang");
                    target.InnerText = "";

                    var form = source.GetBestAlternative(languagePreferences);
                    if (form != null && !string.IsNullOrWhiteSpace(form.Form))
                    {
                        // HtmlDom.GetBookSetting(key) returns the result of XmlNode.InnerXml which will be Html encoded (& < etc).
                        // HtmlDom.SetElementFromUserStringPreservingLineBreaks() calls XmlNode.InnerText, which Html encodes if necessary.
                        // So we need to decode here to prevent double encoding.  See http://issues.bloomlibrary.org/youtrack/issue/BL-4585.
                        // Note that HtmlDom.SetElementFromUserStringPreservingLineBreaks() handles embedded <br/> elements, but makes no
                        // effort to handle p or div elements.
                        var decoded = System.Web.HttpUtility.HtmlDecode(form.Form);
                        HtmlDom.SetElementFromUserStringPreservingLineBreaks(target, decoded);
                        target.SetAttribute("lang", form.WritingSystemId);                         //this allows us to set the font to suit the language
                    }
                }
                else                 //Put the value into an attribute. The license image goes through this path.
                {
                    target.SetAttribute(valueAttribute, source.GetBestAlternativeString(languagePreferences));
                    if (source.Empty)
                    {
                        //if the license image is empty, make sure we don't have some alternative text
                        //about the image being missing or slow to load
                        target.SetAttribute("alt", "");
                        //over in javascript land, @alt will get set appropriately when the image url is not empty.
                    }
                }
            }
        }
Example #2
0
        private static void CopyItemToFieldsInPages(HtmlDom dom, string key, string valueAttribute = null, string[] languagePreferences = null)
        {
            if (languagePreferences == null)
            {
                languagePreferences = new[] { "*", "en" }
            }
            ;

            MultiTextBase source = dom.GetBookSetting(key);

            var target = dom.SelectSingleNode("//*[@data-derived='" + key + "']");

            if (target == null)
            {
                return;
            }


            //just put value into the text of the element
            if (string.IsNullOrEmpty(valueAttribute))
            {
                //clear out what's there now
                target.RemoveAttribute("lang");
                target.InnerText = "";

                var form = source.GetBestAlternative(languagePreferences);
                if (form != null && !string.IsNullOrWhiteSpace(form.Form))
                {
                    HtmlDom.SetElementFromUserStringPreservingLineBreaks(target, form.Form);
                    target.SetAttribute("lang", form.WritingSystemId);                     //this allows us to set the font to suit the language
                }
            }
            else             //Put the value into an attribute. The license image goes through this path.
            {
                target.SetAttribute(valueAttribute, source.GetBestAlternativeString(languagePreferences));
                if (source.Empty)
                {
                    //if the license image is empty, make sure we don't have some alternative text
                    //about the image being missing or slow to load
                    target.SetAttribute("alt", "");
                    //over in javascript land, @alt will get set appropriately when the image url is not empty.
                }
            }
        }
Example #3
0
 private static void CopyStringToFieldsInPages(HtmlDom dom, string key, string val, string lang)
 {
     foreach (XmlElement target in dom.SafeSelectNodes("//*[@data-derived='" + key + "']"))
     {
         if (target == null)                 // don't think this can happen, but something like it seemed to in one test...
         {
             continue;
         }
         if (string.IsNullOrEmpty(val))
         {
             target.RemoveAttribute("lang");
             target.InnerText = "";
         }
         else
         {
             HtmlDom.SetElementFromUserStringPreservingLineBreaks(target, val);
             target.SetAttribute("lang", lang);
         }
     }
 }