Exemplo n.º 1
0
        private static bool isTextObject(StringBuilder code)
        {
            var doesNotStartWithBackslash = !Regex.IsMatch(code.ToString(), @"^\\");
            var startsWithAllowedCode     = Regex.IsMatch(code.ToString(), CodeParser.CreateCodeStartPattern(CodeIndicators));
            var isTextObject = doesNotStartWithBackslash || startsWithAllowedCode;

            return(isTextObject);
        }
        /// <summary>
        /// Parses the code given the object and sets the data to the object
        /// from the front of the string.
        /// </summary>
        /// <param name="code">The code to parse and handle</param>
        /// <returns>
        /// The newly parsed object. The string builder will also have been updted, the code parsed is removed
        /// </returns>
        /// <exception cref="ArgumentException">Thrown if the code string doesn't start with one of the accepted code indicators or the element isn't supported by the parser</exception>
        public LaTeXElement ParseCode(StringBuilder code)
        {
            var chapter = new Subsubsection();

            if (!Regex.IsMatch(code.ToString(), CodeParser.CreateCodeStartPattern(CodeIndicators)))
            {
                throw new ArgumentException("The code didn't start with an allowed indicator");
            }

            chapter.Name = CodeParser.SimpleContent("subsubsection", code);
            return(chapter);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parses the code given the object and sets the data to the object
        /// from the front of the string.
        /// </summary>
        /// <param name="code">The code to parse and handle</param>
        /// <returns>
        /// The newly parsed object. The string builder will also have been updted, the code parsed is removed
        /// </returns>
        /// <exception cref="ArgumentException">Thrown if the code string doesn't start with one of the accepted code indicators or the element isn't supported by the parser</exception>
        public Item ParseCode(StringBuilder code)
        {
            if (!Regex.IsMatch(code.ToString(), CodeParser.CreateCodeStartPattern(CodeIndicators)))
            {
                throw new ArgumentException("The code didn't start with an allowed indicator");
            }

            var item  = new Item();
            var match = CodeIndicators.SingleOrDefault(x => code.ToString().StartsWith(x));

            code.Remove(0, match?.Length ?? 5);

            return(item);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Parses the code given the object and sets the data to the object
        /// from the front of the string.
        /// </summary>
        /// <param name="code">The code to parse and handle</param>
        /// <returns>
        /// The newly parsed object. The string builder will also have been updted, the code parsed is removed
        /// </returns>
        /// <exception cref="ArgumentException">Thrown if the code string doesn't start with one of the accepted code indicators or the element isn't supported by the parser</exception>
        public LaTeXElement ParseCode(StringBuilder code)
        {
            if (!Regex.IsMatch(code.ToString(), CodeParser.CreateCodeStartPattern(CodeIndicators)))
            {
                throw new ArgumentException("The code didn't start with an allowed indicator");
            }

            removeDocumentClassInfo(code);

            var docClass = new DocumentClass();

            setPackages(code, docClass);

            return(docClass);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Parses the code given the object and sets the data to the object
        /// from the front of the string.
        /// </summary>
        /// <param name="code">The code to parse and handle</param>
        /// <returns>
        /// The newly parsed object. The string builder will also have been updted, the code parsed is removed
        /// </returns>
        /// <exception cref="ArgumentException">Thrown if the code string doesn't start with one of the accepted code indicators or the element isn't supported by the parser</exception>
        public Enumerate ParseCode(StringBuilder code)
        {
            if (!Regex.IsMatch(code.ToString(), CodeParser.CreateCodeStartPattern(CodeIndicators)))
            {
                throw new ArgumentException("The code didn't start with an allowed indicator");
            }

            if (Regex.IsMatch(code.ToString(), CodeParser.CreateCodeStartPattern(BeginCommands)))
            {
                return(createNewEnumerate(code));
            }
            else
            {
                return(endEnumerate(code));
            }
        }
Exemplo n.º 6
0
        private static string getStartTextPoint(StringBuilder code)
        {
            var textMach = Regex.Match(code.ToString(), @"^\\emph\{(.*?)\}");

            if (textMach.Success)
            {
                return(getStringWithEmpf(code, textMach));
            }
            else if (Regex.IsMatch(code.ToString(), CodeParser.CreateCodeStartPattern(CodeIndicators)))
            {
                return($@"\{getNextTextPart(code)}");
            }
            else
            {
                textMach = serachForTextString(code);
            }

            return(textMach.Groups[1].Value);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Parses the code given the object and sets the data to the object
        /// from the front of the string.
        /// </summary>
        /// <param name="code">The code to parse and handle</param>
        /// <returns>
        /// The newly parsed object. The string builder will also have been updted, the code parsed is removed
        /// </returns>
        /// <exception cref="ArgumentException">Thrown if the code string doesn't start with one of the accepted code indicators or the element isn't supported by the parser</exception>
        public LaTeXElement ParseCode(StringBuilder code)
        {
            if (!Regex.IsMatch(code.ToString(), CodeParser.CreateCodeStartPattern(CodeIndicators)))
            {
                throw new ArgumentException("The code didn't start with an allowed indicator");
            }
            if (Regex.IsMatch(code.ToString(), "^" + endDocumentPattern))
            {
                code.Remove(0, endDocumentPattern.Length - 1);
                return(null);
            }

            var doc = new Document();

            removeDocumentStart(code);
            handleMakeTitle(doc, code);
            doc.Author = CodeParser.SimpleContent("author", code);
            doc.Title  = CodeParser.SimpleContent("title", code);

            return(doc);
        }