public TableCellDefinition(string content, TableCellAlignment alignment, int colSpan, int rowSpan, TableCellStyle cellStyle) { this._content = content; this._alignment = alignment; this._colSpan = colSpan; this._rowSpan = rowSpan; this._cellStyle = cellStyle; }
public void RenderOpenTag(StringBuilder b, string tagName, TableCellAlignment columnAlignment) { b.Append("<"); // Add tagName (priority to argument) b.Append(tagName ?? this.TagName); // Determining alignment (priority to cell) var alig = (this.Alignment != TableCellAlignment.NA ? this.Alignment : columnAlignment); switch (alig) { case TableCellAlignment.Left: b.Append(" align=\"left\""); break; case TableCellAlignment.Right: b.Append(" align=\"right\""); break; case TableCellAlignment.Center: b.Append(" align=\"center\""); break; } if (this.ColSpan > 1) { b.Append(" colspan=\""); b.Append(this.ColSpan); b.Append("\""); } if (this.RowSpan > 1) { b.Append(" rowspan=\""); b.Append(this.RowSpan); b.Append("\""); } b.Append(">"); }
public static TableSpec Parse(StringScanner p) { // Leading line space allowed p.SkipLinespace(); // Quick check for typical case if (p.current != '|' && p.current != ':' && p.current != '-') { return(null); } // Don't create the spec until it at least looks like one TableSpec spec = null; // Leading bar, looks like a table spec if (p.SkipChar('|')) { spec = new TableSpec(); spec.LeadingBar = true; } // Process all columns while (true) { // Parse column spec p.SkipLinespace(); // Must have something in the spec if (p.current == '|') { return(null); } bool AlignLeft = p.SkipChar(':'); while (p.current == '-') { p.SkipForward(1); } bool AlignRight = p.SkipChar(':'); p.SkipLinespace(); // Work out column alignment TableCellAlignment col = TableCellAlignment.NA; if (AlignLeft && AlignRight) { col = TableCellAlignment.Center; } else if (AlignLeft) { col = TableCellAlignment.Left; } else if (AlignRight) { col = TableCellAlignment.Right; } if (p.eol) { // Not a spec? if (spec == null) { return(null); } // Add the final spec? spec.Columns.Add(col); return(spec); } // We expect a vertical bar if (!p.SkipChar('|')) { return(null); } // Create the table spec if (spec == null) { spec = new TableSpec(); } // Add the column spec.Columns.Add(col); // Check for trailing vertical bar p.SkipLinespace(); if (p.eol) { spec.TrailingBar = true; return(spec); } // Next column } }
/// <summary> /// Constructs an HTML style attribute implementing the specified <see cref="TableCellAlignment"/>. /// </summary> /// <param name="alignment">The desired cell alignment.</param> /// <returns> /// A string containing the full HTML style attribute name and value, or an empty string /// if the alignment is specified as <see cref="TableCellAlignment.None"/>. /// </returns> /// <remarks> /// This method uses <c>start</c> and <c>end</c> values for the <c>text-align</c> CSS attribute, /// which respect the reading direction (LTR or RTL) of the surrounding HTML. For example, if the /// specified alignment is <see cref="TableCellAlignment.Left"/>, the text will be aligned to the left /// in LTR and to the right in RTL. /// </remarks> public static string ToStyleAttribute(this TableCellAlignment alignment) => alignment switch {