Ejemplo n.º 1
0
        protected string readJsDocsProcessTextSectionReplacements(ref JsDocsSection section)
        {
            string sectionValue = section.Value
                                  .Replace("\r\n", "\n").Replace("\r", "\n")
                                  .Replace("<h1>", "\n\n# ").Replace("</h1>", "")
                                  .Replace("<h2>", "\n\n## ").Replace("</h2>", "")
                                  .Replace("<h3>", "\n\n### ").Replace("</h3>", "")
                                  .Replace("<h4>", "\n\n#### ").Replace("</h4>", "")
                                  .Replace("<h5>", "\n\n##### ").Replace("</h5>", "")
                                  .Replace("<h6>", "\n\n###### ").Replace("</h3>", "")
                                  .Replace("<hr>", "\n\n---\n\n").Replace("<hr/>", "\n\n---\n\n").Replace("<hr />", "\n\n---\n\n")
                                  .Replace("<p>", "\n\n").Replace("</p>", "\n")
                                  .Replace("<i>", "_").Replace("</i>", "_")
                                  .Replace("<em>", "_").Replace("</em>", "_")
                                  .Replace("<b>", "**").Replace("</b>", "**")
                                  .Replace("<strong>", "**").Replace("</strong>", "**")
                                  .Replace("<s>", "~~").Replace("</s>", "~~")
                                  .Replace("<del>", "~~").Replace("</del>", "~~")
                                  .Replace("<br>", "\n").Replace(")<br/>", "\n").Replace("<br />", "\n");

            sectionValue = Regex.Replace(
                sectionValue,
                @"([^\n])\n(\s*)([\#]+) ([^\n]+)\n",
                "$1\n\n$2$3 $4\n"
                );
            // Process relative links: {@link #somethingElse}

            // process <ul> sections:
            this.readJsDocsProcessBulletSections(ref section, ref sectionValue);
            // process <ol> sections:
            this.readJsDocsProcessNumberedSections(ref section, ref sectionValue);
            // process <img> tags:
            this.readJsDocsProcessTextImages(ref sectionValue);
            sectionValue = Regex.Replace(
                sectionValue,
                @"\n\n+",
                "\n\n"
                );
            return(sectionValue);
        }
Ejemplo n.º 2
0
        protected List <JsDocsSection> readJsDocsMergeTheSameSections(List <JsDocsSection> sections)
        {
            List <JsDocsSection> newSections = new List <JsDocsSection>();

            if (sections.Count <= 1)
            {
                return(sections);
            }
            newSections = new List <JsDocsSection>()
            {
                sections[0]
            };
            JsDocsSection newSection;
            JsDocsSection lastResSection;
            int           lastResSecsIndex = 0;

            for (int i = 1; i < sections.Count; i++)
            {
                newSection     = sections[i];
                lastResSection = newSections[lastResSecsIndex];
                if (newSection.Type == lastResSection.Type)
                {
                    // merge this section with last result section
                    newSections[lastResSecsIndex] = new JsDocsSection()
                    {
                        Type             = lastResSection.Type,
                        Value            = lastResSection.Value += "\n" + newSection.Value,
                        EndingListIndent = 0
                    };
                }
                else
                {
                    // add the section
                    newSections.Add(newSection);
                    lastResSecsIndex += 1;
                }
            }
            return(newSections);
        }
Ejemplo n.º 3
0
        protected void readJsDocsProcessNumberedSections(ref JsDocsSection section, ref string sectionValue)
        {
            int             index = 0;
            int             olTagOpenPos;
            int             olTagClosePos;
            string          olSection;
            List <string[]> liItemsArrs;
            List <string>   liItems;
            int             liTagOpenPos;
            int             liTagClosePos;
            string          liSection;

            string[] liSectionLines;
            int      indentLength;
            string   indent;
            string   indentBase;
            int      counter;
            string   restValue;

            while (true)
            {
                olTagOpenPos = sectionValue.IndexOf("<ol>", index);
                if (olTagOpenPos == -1)
                {
                    break;
                }
                olTagClosePos = sectionValue.IndexOf("</ol>", olTagOpenPos + 4);
                if (olTagClosePos == -1)
                {
                    break;
                }

                olSection   = sectionValue.Substring(olTagOpenPos + 4, olTagClosePos - (olTagOpenPos + 4));
                liItemsArrs = new List <string[]>();
                index       = 0;
                while (true)
                {
                    liTagOpenPos = olSection.IndexOf("<li>", index);
                    if (liTagOpenPos == -1)
                    {
                        break;
                    }
                    liTagClosePos = olSection.IndexOf("</li>", liTagOpenPos + 4);
                    if (liTagClosePos == -1)
                    {
                        break;
                    }
                    liSection      = olSection.Substring(liTagOpenPos + 4, liTagClosePos - (liTagOpenPos + 4));
                    liSectionLines = liSection.Split(
                        new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries
                        ).ToArray <string>();
                    for (int i = 0; i < liSectionLines.Length; i++)
                    {
                        liSectionLines[i] = liSectionLines[i].Trim();
                    }
                    liItemsArrs.Add(liSectionLines);
                    index = liTagClosePos + 5;
                }
                if (liItemsArrs.Count < 10)
                {
                    indentLength = 3;
                    indentBase   = "   ";                   // 3 spaces
                }
                else
                {
                    indentLength = 4;
                    indentBase   = "    ";                   // 4 spaces
                }
                counter = 1;
                liItems = new List <string>();
                foreach (string[] liItem in liItemsArrs)
                {
                    indent = counter.ToString() + "."
                             + "".PadLeft(indentLength - counter.ToString().Length - 1, ' ');
                    for (int j = 0; j < liItem.Length; j++)
                    {
                        liItem[j] = indent + liItem[j];
                        indent    = indentBase;
                    }
                    liItems.Add(String.Join("\n", liItem));
                    counter += 1;
                }

                olSection = "\n\n" + String.Join("\n", liItems) + "\n\n";

                restValue = this.readJsDocsTrimSectionValue(
                    sectionValue.Substring(olTagClosePos + 5), false
                    );
                if (restValue.Length == 0)
                {
                    section.EndingListIndent = indentLength;
                }

                sectionValue = sectionValue.Substring(0, olTagOpenPos)
                               + olSection
                               + sectionValue.Substring(olTagClosePos + 5);
                index = olTagOpenPos + olSection.Length;
            }
        }
Ejemplo n.º 4
0
        protected void readJsDocsProcessBulletSections(ref JsDocsSection section, ref string sectionValue)
        {
            int           index = 0;
            int           ulTagOpenPos;
            int           ulTagClosePos;
            string        ulSection;
            List <string> liItems;
            int           liTagOpenPos;
            int           liTagClosePos;
            string        liSection;

            string[] liSectionLines;
            string   indent;
            string   restValue;

            while (true)
            {
                ulTagOpenPos = sectionValue.IndexOf("<ul>", index);
                if (ulTagOpenPos == -1)
                {
                    break;
                }
                ulTagClosePos = sectionValue.IndexOf("</ul>", ulTagOpenPos + 4);
                if (ulTagClosePos == -1)
                {
                    break;
                }
                ulSection = sectionValue.Substring(ulTagOpenPos + 4, ulTagClosePos - (ulTagOpenPos + 4));
                liItems   = new List <string>();
                index     = 0;
                while (true)
                {
                    liTagOpenPos = ulSection.IndexOf("<li>", index);
                    if (liTagOpenPos == -1)
                    {
                        break;
                    }
                    liTagClosePos = ulSection.IndexOf("</li>", liTagOpenPos + 4);
                    if (liTagClosePos == -1)
                    {
                        break;
                    }
                    liSection      = ulSection.Substring(liTagOpenPos + 4, liTagClosePos - (liTagOpenPos + 4));
                    liSectionLines = liSection.Split(
                        new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries
                        ).ToArray <string>();
                    indent = "- ";
                    for (int i = 0; i < liSectionLines.Length; i++)
                    {
                        liSectionLines[i] = indent + liSectionLines[i].Trim();
                        indent            = "  ";             // 2 spaces
                    }
                    liItems.Add(String.Join("\n", liSectionLines));
                    index = liTagClosePos + 5;
                }
                ulSection = "\n\n" + String.Join("\n", liItems) + "\n\n";
                restValue = this.readJsDocsTrimSectionValue(
                    sectionValue.Substring(ulTagClosePos + 5), false
                    );
                if (restValue.Length == 0)
                {
                    section.EndingListIndent = 2;
                }
                sectionValue = sectionValue.Substring(0, ulTagOpenPos)
                               + ulSection
                               + sectionValue.Substring(ulTagClosePos + 5);
                index = ulTagOpenPos + ulSection.Length;
            }
        }