Exemple #1
0
        // Returns the width of a given column, as a percent
        private string ColumnWidthAsPercent(string colname, int currentColumn)
        {
            // Get the total width of all the columns
            double total       = 0.0;
            double columnValue = 1.0;

            for (int column = 0; column < _tableColumnSpecs.Length; column++)
            {
                DitaTableColumnSpec columnSpec = _tableColumnSpecs[column];
                double value = 1.0;
                if (!string.IsNullOrWhiteSpace(columnSpec?.Width))
                {
                    // We only want numbers or a decimal point, so get rid of everything else
                    string input = new string(columnSpec.Width.ToCharArray().TakeWhile(c => (Char.IsDigit(c) || c == '.')).ToArray());
                    if (!string.IsNullOrWhiteSpace(input))
                    {
                        if (!double.TryParse(input, out value))
                        {
                            Trace.TraceWarning($"Unable to parse table column width: {input}.");
                        }
                    }
                }

                value = Math.Max(value, 1.0);

                if (columnSpec?.Name == colname || currentColumn == column)
                {
                    columnValue = value;
                }

                total += value;
            }

            if (total.Equals(0.0))
            {
                return("");
            }

            return($"{(columnValue / total * 100.0)}%");
        }
Exemple #2
0
        // Takes a DITA "tag" and returns the corresponding HTML tag
        private string ConvertDitaTagToHtmlTag(DitaElement element)
        {
            switch (element.Type)
            {
            case "b": return("strong");

            case "colspec":
                TableColumnIndex++;
                FixUpTableColumnSpecs();
                _tableColumnSpecs[TableColumnIndex] = new DitaTableColumnSpec {
                    Number = (TableColumnIndex + 1)
                };

                return("");

            case "entry":
                TableRowColumnIndex++;
                if (element.Parent?.Parent?.Type == "thead" || element.AttributeValueOrDefault("class", "") == "th")
                {
                    return("th");
                }

                return("td");

            case "fig": return("figure");

            case "image":
                // Is this referring to an SVG or other type of image?
                if (IsImageElementSvg(element))
                {
                    return("object");
                }

                return("img");

            case "keyword": return("");

            case "row":
                TableRowColumnIndex = -1;
                return("tr");

            case "steps":
                return("ol");

            case "step":
                return("li");

            case "table":
                TableColumnIndex  = -1;
                _tableColumnSpecs = null;
                break;

            case "tgroup":
                TableColumnIndex  = -1;
                _tableColumnSpecs = null;
                return("");

            case "title":
                if (element.Parent?.Type == "section")
                {
                    // Create a reference to this section, if this is the title of the section
                    if (CurrentSection != null)
                    {
                        if (string.IsNullOrEmpty(CurrentSection.Title) && !string.IsNullOrEmpty(CurrentSection.Anchor))
                        {
                            CurrentSection.Title = element.ToString();
                            Sections.Add(CurrentSection);
                            CurrentSection = null;
                        }
                    }

                    return("h3");
                }

                return("h4");

            case "xref":
                return("a");

            case "#text": return("");
            }

            return(element.Type);
        }