Example #1
0
        // Parse the version of the document
        private void ParseBookMapVersion(DitaElement bookMetaElement)
        {
            // Try checking the publisher information section
            DitaElement publisherInformationElement = bookMetaElement?.FindOnlyChild("publisherinformation");
            DitaElement publishedElement            = publisherInformationElement?.FindChildren("published")?.Last();
            DitaElement revisionIdElement           = publishedElement?.FindOnlyChild("revisionid");
            string      version = revisionIdElement?.ToString();

            // Try checking the prodinfo section
            if (string.IsNullOrWhiteSpace(version) || version == "ProductVersionNumber")
            {
                DitaElement prodinfoElement = bookMetaElement?.FindOnlyChild("prodinfo");
                DitaElement vrmlistElement  = prodinfoElement?.FindOnlyChild("vrmlist");
                DitaElement vrmElement      = vrmlistElement?.FindChildren("vrm")?[0];
                version = vrmElement?.Attributes?["version"];
            }

            if (!string.IsNullOrWhiteSpace(version))
            {
                BookMeta.Add("version", version);
            }
        }
Example #2
0
        // Converts a single dita tag attribute to an html attribute
        private (string newKey, string newValue) ConvertDitaTagAttributeToHtmlTagAttribute(string key, string value, DitaElement element)
        {
            switch (element.Type)
            {
            case "a":
                return(key, value);

            case "colspec":
                if (key == "colname")
                {
                    FixUpTableColumnSpecs();
                    _tableColumnSpecs[TableColumnIndex].Name = value;
                }

                if (key == "colwidth")
                {
                    FixUpTableColumnSpecs();
                    _tableColumnSpecs[TableColumnIndex].Width = value;
                }

                if (key == "colnum")
                {
                    if (int.TryParse(value, out int colnum))
                    {
                        FixUpTableColumnSpecs();
                        _tableColumnSpecs[TableColumnIndex].Number = colnum;
                    }
                }

                break;

            case "entry":
                if (key == "morerows")
                {
                    if (int.TryParse(value, out int rowspan))
                    {
                        return("rowspan", $"{rowspan + 1}");
                    }
                }

                if (key == "valign")
                {
                    return(key, value);
                }

                break;

            case "image":
                if (key == "href")
                {
                    if (IsImageElementSvg(element))
                    {
                        return("data", ImageUrlFromHref(value));
                    }

                    return("src", ImageUrlFromHref(value));
                }

                break;

            case "section":
                if (key == "id")
                {
                    CurrentSection = new DitaPageSectionJson {
                        Anchor = value
                    };
                    return(key, value);
                }

                break;

            case "tgroup":
                if (key == "cols")
                {
                    if (int.TryParse(value, out int columns))
                    {
                        _tableColumnSpecs = new DitaTableColumnSpec[columns];
                    }
                }

                break;

            case "xref":
                if (key == "href")
                {
                    string url = UrlFromXref(element, out string title);

                    // If we encounter an empty xref, we want to try to generate link text, based on what it links too
                    if (string.IsNullOrWhiteSpace(element.ToString()))
                    {
                        element.SetInnerText(title);
                    }

                    return(key, url);
                }

                break;
            }

            return("", "");
        }
Example #3
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);
        }