rlranft Posted June 25, 2016 Share Posted June 25, 2016 I use this to keep the side-bar in the docs in sync with the documents - so that the right bit rolls out and stuff is all lined up right:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace tocUpdate { class Program { static void Main(string[] args) { if(args.Length < 1) return; String path = args[0]; List lines = new List(); StreamReader sr = new StreamReader(path + "\\toc.html"); while (!sr.EndOfStream) { lines.Add(sr.ReadLine()); } sr.Close(); int docLine = 0; for(int i = 0; i < lines.Count; ++i) { if(lines.Contains("id = \"doc")) { // this has a doc id int start = 0; int end = 0; int count = 0; int index = 0; while(count <= 3) { if(lines[index] == '\"') { count++; } else if(count == 3) { start = index; count++; break; } index++; } while(count <= 4) { if (lines[index] == '\"') { end = index; count++; break; } index++; } String sub = lines.Substring(start, (end - start)); lines = lines.Replace(sub, "doc" + docLine); // now find the referenced page and update the document id in the script section int hrefStart = lines.IndexOf("href ="); int hrefEnd = hrefStart + 1; char quote = lines[hrefStart]; while (quote != '\"') { ++hrefStart; quote = lines[hrefStart]; hrefEnd = hrefStart + 1; } // should now have index of starting quote for doc path quote = lines[hrefEnd]; while (quote != '\"') { ++hrefEnd; quote = lines[hrefEnd]; } // and the end of the doc path List docLines = new List(); String targetDoc = lines.Substring(hrefStart + 1, (hrefEnd - hrefStart) - 1); targetDoc = targetDoc.Replace('/', '\\'); using (StreamReader docReader = new StreamReader(path + "\\" + targetDoc)) { bool inScript = false; while(!docReader.EndOfStream) { String line = docReader.ReadLine(); if (line.Contains(" inScript = true; if (line.Contains("")) inScript = false; if (!inScript) docLines.Add(line); else { // look for our doc id and update to new id if(line.Contains("pageID")) { String substr = line.Substring(line.IndexOf("pageID")); line = line.Replace(substr, "pageID = " + docLine + ";"); } if(line.Contains("'doc")) { String substr = line.Substring(line.IndexOf("'doc")); line = line.Replace(substr, "'doc" + docLine + "');"); } docLines.Add(line); } } } using (StreamWriter docWriter = new StreamWriter(path + "\\" + targetDoc)) { foreach(String line in docLines) { docWriter.WriteLine(line); } } ++docLine; } StreamWriter sw = new StreamWriter(path + "\\toc.html"); foreach (String line in lines) sw.WriteLine(line); sw.Flush(); sw.Close(); } } } }In case anyone is planning to add stuff to https://github.com/dottools/Torque3D-Documentation. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.