Bloom.Book.HtmlDom.ConvertHtmlBreaksToNewLines C# (CSharp) Method

ConvertHtmlBreaksToNewLines() public static method

public static ConvertHtmlBreaksToNewLines ( string html ) : string
html string
return string
        public static string ConvertHtmlBreaksToNewLines(string html)
        {
            // newlines had no meaning in html-land, may well have been introduced for readability of the xml/html
            html = html.Replace("\r", "").Replace("\n", ""); // works for \n (linux) and \r\n (windows)

            //now we can move from the html br to newlines for non-html use
            return html.Replace("<br/>", Environment.NewLine)
                .Replace("<br />", Environment.NewLine)
                .Replace("<br>", Environment.NewLine);
        }

Usage Example

Example #1
0
        /// <summary>
        /// Create a Clearshare.Metadata object by reading values out of the dom's bloomDataDiv
        /// </summary>
        /// <param name="brandingNameOrFolderPath"> Normally, the branding is just a name, which we look up in the official branding folder
        //but unit tests can instead provide a path to the folder.
        /// </param>
        public static Metadata GetMetadata(HtmlDom dom, string brandingNameOrFolderPath = "")
        {
            if (ShouldSetToDefaultCopyrightAndLicense(dom))
            {
                return(GetMetadataWithDefaultCopyrightAndLicense(brandingNameOrFolderPath));
            }
            var metadata  = new Metadata();
            var copyright = dom.GetBookSetting("copyright");

            if (!copyright.Empty)
            {
                metadata.CopyrightNotice = WebUtility.HtmlDecode(copyright.GetFirstAlternative());
            }

            var licenseUrl = dom.GetBookSetting("licenseUrl").GetBestAlternativeString(new[] { "*", "en" });

            if (string.IsNullOrWhiteSpace(licenseUrl))
            {
                //NB: we are mapping "RightsStatement" (which comes from XMP-dc:Rights) to "LicenseNotes" in the html.
                //custom licenses live in this field, so if we have notes (and no URL) it is a custom one.
                var licenseNotes = dom.GetBookSetting("licenseNotes");
                if (!licenseNotes.Empty)
                {
                    metadata.License = new CustomLicense {
                        RightsStatement = WebUtility.HtmlDecode(licenseNotes.GetFirstAlternative())
                    };
                }
                else
                {
                    // The only remaining current option is a NullLicense
                    metadata.License = new NullLicense();                     //"contact the copyright owner
                }
            }
            else             // there is a licenseUrl, which means it is a CC license
            {
                try
                {
                    metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl);
                }
                catch (IndexOutOfRangeException)
                {
                    // Need to handle urls which do not end with the version number.
                    // Simply set it to the default version.
                    if (!licenseUrl.EndsWith("/"))
                    {
                        licenseUrl += "/";
                    }
                    licenseUrl      += CreativeCommonsLicense.kDefaultVersion;
                    metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl);
                }
                catch (Exception e)
                {
                    throw new ApplicationException("Bloom had trouble parsing this license url: '" + licenseUrl + "'. (ref BL-4108)", e);
                }
                //are there notes that go along with that?
                var licenseNotes = dom.GetBookSetting("licenseNotes");
                if (!licenseNotes.Empty)
                {
                    var s = WebUtility.HtmlDecode(licenseNotes.GetFirstAlternative());
                    metadata.License.RightsStatement = HtmlDom.ConvertHtmlBreaksToNewLines(s);
                }
            }
            return(metadata);
        }
All Usage Examples Of Bloom.Book.HtmlDom::ConvertHtmlBreaksToNewLines