Exemplo n.º 1
0
        private string BeautyMyCode(string Source)
        {
            Source = RemoveStr(Source, new string[] { "\n", "\x09", "  " });
            Source = new Regex("#include <(.*?)>").Replace(Source, "$0\n");
            Source = new Regex(";").Replace(Source, "$0\n");
            Source = new Regex("{").Replace(Source, "\n$0\n");
            Source = new Regex("}").Replace(Source, "$0\n");
            int DeepCount = 0;
            for (int i = 0; i < Source.Length; i++)
            {
                if (Source[i] == '}') DeepCount--;
                else if (Source[i] == '{') DeepCount++;
                else if (Source[i]  == '\n')
                {
                    int NextNewLinePos = Source.IndexOf("\n", i + 1);
                    if (NextNewLinePos != -1)
                    {
                        Console.WriteLine(Source.Substring(i, NextNewLinePos - i));
                        if (Source.Substring(i, NextNewLinePos - i).Contains("}"))
                        {
                            Source = Source.Insert(i + 1, GetManyBlankStr(DeepCount -1));
                        }
                        else
                        {
                            Source = Source.Insert(i + 1, GetManyBlankStr(DeepCount));
                        }

                    }
                }
            }
            return (Source);
        }
		private void KeyDowned (object sender, KeyEventArgs e) {
			if (e.Key == Key.Tab && this.TxtScript.SelectionLength > 0) {
				string script = this.TxtScript.Text;
				string newScript = script;

				//how many new lines are in the selection
				int numNewLines = this.TxtScript.SelectedText.Split ('\n').Length - 1;

				//get the beginning of the first line
				int firstLineStartIndex = script.LastIndexOf ("\n", this.TxtScript.SelectionStart, this.TxtScript.SelectionStart);

				//get the end of the last line
				int lastLineEndIndex = script.IndexOf ("\n", this.TxtScript.SelectionStart + this.TxtScript.SelectionLength);

				if (firstLineStartIndex <= -1) {
					firstLineStartIndex = 0;
				}

				if (lastLineEndIndex <= -1) {
					lastLineEndIndex = script.Length;
				}

				if (Keyboard.IsKeyDown (Key.LeftShift) || Keyboard.IsKeyDown (Key.RightShift)) {
					//string interestedText = script.Substring (firstLineStartIndex, lastLineEndIndex - firstLineStartIndex);
					//string newText = interestedText;
					//string [] lines = interestedText.Split ('\n');
					
					//for (int i = 0; i < lines.Length; i++) {
						
					//	if (lines [i][0] == '\t') {
					//		lines [i] = lines [i].Substring (1);
					//	}
					//}

					//newText = string.Join ("\n", lines);
					//newScript = script.Replace (interestedText, newText);
					//this.TxtScript.Text = newScript;
				} else {
					//insert a tab after every selected newline
					newScript = new Regex ("\n").Replace (newScript, "\n\t", numNewLines, firstLineStartIndex + 1);

					//insert tab in the first line
					newScript = newScript.Insert (firstLineStartIndex + (firstLineStartIndex == 0 ? 0 : 1), "\t");

					this.TxtScript.Text = newScript;
					this.TxtScript.SelectionStart = firstLineStartIndex;
					this.TxtScript.SelectionLength = lastLineEndIndex - firstLineStartIndex + numNewLines + 1;
				}

				//cancel event
				e.Handled = true;
			}
		}
Exemplo n.º 3
0
        public static string GetHtml(Parser parser)
        {
            string document = parser.GetDocument();

            StringBuilder html = new StringBuilder();

            html.Append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\r\n");
            html.Append("<html>\r\n<head>\r\n<title>Title</title>\r\n<link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\">\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body>\r\n");

            if (!parser.GetSuccess())
            {
                html.Append("<p>Errors occurred while parsing the document. Please correct these before trying to export.</p>\r\n");
            }
            else
            {
                // Convert @pageref links to actual page numbers
                document = new Regex("@pageref\\((.+?)\\)").Replace(document, "<a href='#$1' class='pageref'>this link</a>");

                // Center lines
                document = new Regex("^--\\s*(.*?)\\s*$", RegexOptions.Multiline).Replace(document, "<p style='text-align: center'>$1</p>");

                // Convert lines to paragraphs (ignoring any figures, tables, or raw html)
                MatchCollection paragraphs = new Regex("(^([^@figure\\(|^@table\\(|^\n|^#|^\\$|^\\<].+?)\n)+", RegexOptions.Multiline).Matches(document);

                for (int i = paragraphs.Count - 1; i >= 0; i--)
                {
                    Match m = paragraphs[i];

                    document = document.Remove(m.Index, m.Length);
                    document = document.Insert(m.Index, "<p>\n" + m.Groups[0].Value.ToString().Substring(0, m.Groups[0].Value.Length - 1).Replace("\n", "<br>\n") + "\n</p>\n");
                }

                // Convert lines only containing # to vertical padding paragraphs
                document = new Regex("^#\n", RegexOptions.Multiline).Replace(document, "<p><br></p>\n");

                document = ProcessChapters(document, parser.GetChapters());
                document = ProcessFigures(document, parser.GetFigures());
                document = ProcessTables(document, parser.GetTables());
                document = ProcessReferences(document, parser.GetReferences());

                html.Append(document);
            }

            html.Append("</body></html>");

            return html.ToString();
        }