Exemple #1
0
        /// <summary>
        /// Gets or creates the <see cref="LatexAttributes"/> stored on a <see cref="MarkdownObject"/>
        /// </summary>
        /// <param name="obj">The markdown object.</param>
        /// <returns>The attached latex attributes</returns>
        public static LatexAttributes GetAttributes(this IMarkdownObject obj)
        {
            var attributes = obj.GetData(Key) as LatexAttributes;

            if (attributes == null)
            {
                attributes = new LatexAttributes();
                obj.SetAttributes(attributes);
            }
            return(attributes);
        }
Exemple #2
0
        /// <summary>
        /// Copies/merge the values from this instance to the specified <see cref="LatexAttributes"/> instance.
        /// </summary>
        /// <param name="latexAttributes">The Latex attributes.</param>
        /// <param name="mergeIdAndProperties">If set to <c>true</c> it will merge properties to the target latexAttributes. Default is <c>false</c></param>
        /// <param name="shared">If set to <c>true</c> it will try to share Classes and Properties if destination don't have them, otherwise it will make a copy. Default is <c>true</c></param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public void CopyTo(LatexAttributes latexAttributes, bool mergeIdAndProperties = false, bool shared = true)
        {
            if (latexAttributes == null)
            {
                throw new ArgumentNullException(nameof(latexAttributes));
            }
            // Add latex latexAttributes to the object
            if (!mergeIdAndProperties || Id != null)
            {
                latexAttributes.Id = Id;
            }
            if (latexAttributes.Classes == null)
            {
                latexAttributes.Classes = shared ? Classes : Classes != null ? new List <string>(Classes) : null;
            }
            else if (Classes != null)
            {
                latexAttributes.Classes.AddRange(Classes);
            }

            if (latexAttributes.Properties == null)
            {
                latexAttributes.Properties = shared ? Properties : Properties != null ? new List <KeyValuePair <string, string> >(Properties) : null;
            }
            else if (Properties != null)
            {
                if (mergeIdAndProperties)
                {
                    foreach (var prop in Properties)
                    {
                        latexAttributes.AddPropertyIfNotExist(prop.Key, prop.Value);
                    }
                }
                else
                {
                    latexAttributes.Properties.AddRange(Properties);
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Sets <see cref="LatexAttributes" /> to the <see cref="MarkdownObject" />
 /// </summary>
 /// <param name="obj">The markdown object.</param>
 /// <param name="attributes">The attributes to attach.</param>
 public static void SetAttributes(this IMarkdownObject obj, LatexAttributes attributes)
 {
     obj.SetData(Key, attributes);
 }