public static Preprocessor Create(string projectPath) { Preprocessor preprocessor = null; string preprocessorFilename = Path.Combine(projectPath,Constants.PreprocessorFilename); if( File.Exists(preprocessorFilename) ) { try { using( Stream stream = new FileStream(preprocessorFilename,FileMode.Open,FileAccess.Read,FileShare.Read) ) preprocessor = (Preprocessor)new BinaryFormatter().Deserialize(stream); } catch( Exception exception ) { MessageBox.Show("The preprocessor file was corrupt and will be regenerated: " + exception.Message); } } if( preprocessor == null ) { preprocessor = new Preprocessor(); preprocessor._topics = new Dictionary<string,TopicPreprocessor>(); preprocessor._images = new Dictionary<string,ImagePreprocessor>(); } preprocessor._projectPath = projectPath; preprocessor._preprocessorFilename = preprocessorFilename; return preprocessor; }
public void AddContextSensitiveHelp(Preprocessor.TopicPreprocessor preprocessedTopic,string defineId) { if( !ContextSensitiveHelps.ContainsKey(preprocessedTopic) ) ContextSensitiveHelps.Add(preprocessedTopic,new List<string>()); ContextSensitiveHelps[preprocessedTopic].Add(defineId); }
public TopicCompiler(HelpComponents helpComponents,Preprocessor.TopicPreprocessor preprocessedTopic,TopicCompilerSettingsInterface topicCompilerSettings) { _helpComponents = helpComponents; _preprocessedTopic = preprocessedTopic; _topicCompilerSettings = topicCompilerSettings; _sb = new StringBuilder(); _tagSettings = new Dictionary<string,TagSettings>(); _tagSettings.Add(TagTitle,new TagSettings(true,null,(EndTagHandlerDelegate)EndTitleHandler,0,0)); _tagSettings.Add(ContextTag,new TagSettings(false,(StartTagHandlerDelegate)StartContextHandler,null,1,Int32.MaxValue)); _tagSettings.Add(IndentTag,new TagSettings(true,(StartTagHandlerDelegate)StartIndentHandler,(EndTagHandlerDelegate)EndTagHandlerUsingFilledEndTagStack,0,1)); _tagSettings.Add(CenterTag,new TagSettings("<div align=\"center\">","</div>")); _tagSettings.Add(BoldTag,new TagSettings("<b>","</b>")); _tagSettings.Add(ItalicsTag,new TagSettings("<i>","</i>")); _tagSettings.Add(FontTag,new TagSettings(true,(StartTagHandlerDelegate)StartFontHandler,"</span>",1,3)); _tagSettings.Add(ListTag,new TagSettings(true,(StartTagHandlerDelegate)StartListHandler,(EndTagHandlerDelegate)EndTagHandlerUsingFilledEndTagStack,0,1)); _tagSettings.Add(ListItemTag,new TagSettings("<li>","</li>")); _tagSettings.Add(HeaderTag,new TagSettings("<div class=\"header_size header\">","</div>")); _tagSettings.Add(TitleHeaderTag,new TagSettings(false,(StartTagHandlerDelegate)StartTitleHeaderHandler,null,0,0)); _tagSettings.Add(SubheaderTag,new TagSettings("<div class=\"subheader_size subheader\">","</div>")); _tagSettings.Add(ImageTag,new TagSettings(false,(StartTagHandlerDelegate)StartImageHandler,null,1,2)); _tagSettings.Add(TopicTag,new TagSettings(false,(StartTagHandlerDelegate)StartTopicHandler,null,1,1)); _tagSettings.Add(LinkTag,new TagSettings(true,(StartTagHandlerDelegate)StartLinkHandler,"</a>",1,1)); _tagSettings.Add(TableTag,new TagSettings(true,(StartTagHandlerDelegate)StartTableHandler,(EndTagHandlerDelegate)EndTableHandler,1,3)); _tagSettings.Add(TableCellTag,new TagSettings(true,(StartTagHandlerDelegate)StartTableCellHandler,(EndTagHandlerDelegate)EndTableCellHandler,0,1)); _tagSettings.Add(SeeAlsoTag,new TagSettings(false,(StartTagHandlerDelegate)StartSeeAlsoHandler,null,1,Int32.MaxValue)); _tagSettings.Add(LogicTag,new TagSettings(true,"",(EndTagHandlerDelegate)EndLogicHandler,0,0)); _tagSettings.Add(LogicColorTag,new TagSettings(true,"",(EndTagHandlerDelegate)EndLogicColorHandler,0,0)); _tagSettings.Add(PffTag,new TagSettings(true,"",(EndTagHandlerDelegate)EndPffHandler,0,0)); _tagSettings.Add(PffColorTag,new TagSettings(true,"",(EndTagHandlerDelegate)EndPffColorHandler,0,0)); _tagSettings.Add(HtmlTag,new TagSettings("","")); _blockTags = new Dictionary<string,string>(); _blockTags.Add(MakeTag(LogicTag,true),MakeTag(LogicTag,false)); _blockTags.Add(MakeTag(PffTag,true),MakeTag(PffTag,false)); _blockTags.Add(MakeTag(HtmlTag,true),MakeTag(HtmlTag,false)); }
public void Compile(Preprocessor preprocessor) { Compile(File.ReadAllLines(_tableOfContentsFilename),preprocessor); }
public void Compile(string[] lines,Preprocessor preprocessor) { _tableOfContentsRootNode = _tableOfContentsParser.Parse(lines,preprocessor); }
public string Format(string[] lines,Preprocessor preprocessor) { Compile(lines,preprocessor); return TopicListParser.Format(_indexRootNode,true); }
public void Compile(Preprocessor preprocessor) { Compile(File.ReadAllLines(_indexFilename),preprocessor); }
public void Compile(string[] lines,Preprocessor preprocessor) { _indexRootNode = _indexParser.Parse(lines,preprocessor); }
public TopicListNode Parse(string[] lines, Preprocessor preprocessor) { string fileDescription = _indexParser ? "index" : "table of contents"; TopicListNode rootNode = null; List <TopicListNode> parentNodes = new List <TopicListNode>(); for (int i = 0; i < lines.Length; i++) { string line = lines[i]; int zeroBasedLevel = 0; // the level is zero-based (but displayed as one-based) for ( ; zeroBasedLevel < line.Length && line[zeroBasedLevel] == '\t'; zeroBasedLevel++) { ; } line = line.Trim(); int hashPos = line.IndexOf('#'); if (hashPos >= 0) // a comment { line = line.Substring(0, hashPos).Trim(); } if (line.Length == 0) // an empty line { continue; } try { if (parentNodes.Count == 0 && zeroBasedLevel >= 1) { throw new Exception("must be at level 1 because it is the first node"); } if (_indexParser && zeroBasedLevel >= 2) { throw new Exception(String.Format("has more than the maximum allowed levels ({0} > 2)", zeroBasedLevel + 1)); } if (zeroBasedLevel > parentNodes.Count) { throw new Exception(String.Format("cannot increase more than one level from {0} to {1}", parentNodes.Count, zeroBasedLevel + 1)); } int pipePos = line.IndexOf('|'); string filename = (pipePos >= 0) ? line.Substring(0, pipePos).Trim() : line; string title = (pipePos >= 0) ? line.Substring(pipePos + 1).Trim() : null; if (title != null && String.IsNullOrWhiteSpace(title)) { throw new Exception("has a blank title"); } Preprocessor.TopicPreprocessor topic = String.IsNullOrWhiteSpace(filename) ? null : preprocessor.GetTopic(filename); bool isLinkToChm = (title != null && GetLinkToChm(title) != null); if (isLinkToChm && zeroBasedLevel > 0) { throw new Exception("is invalid because links to other help files must only be at level one"); } if (_indexParser) // index { // an index entry must be either a topic or a link to a help file if (topic == null && !isLinkToChm) { throw new Exception("must specify a topic filename"); } } TopicListNode newNode = new TopicListNode(topic, title); if (rootNode == null) // the root node { rootNode = newNode; parentNodes.Add(rootNode); } else if (zeroBasedLevel == parentNodes.Count) // child node { if (!_indexParser && parentNodes[zeroBasedLevel - 1].Topic != null) { throw new Exception("is invalid because nothing can come at a level under a topic"); } parentNodes[zeroBasedLevel - 1].ChildNode = newNode; parentNodes.Add(newNode); } else // sibling node (at the same or previous level) { while (parentNodes.Count > (zeroBasedLevel + 1)) { parentNodes.RemoveAt(parentNodes.Count - 1); } if (!_indexParser && newNode.Topic != null && parentNodes[zeroBasedLevel].Topic == null) { throw new Exception("is invalid because a topic cannot come after a chapter at the same level"); } parentNodes[zeroBasedLevel].SiblingNode = newNode; parentNodes[zeroBasedLevel] = newNode; } } catch (Exception exception) { throw new Exception(String.Format("The {0} line #{1} \"{2}\" {3}", fileDescription, i + 1, line, exception.Message)); } } if (rootNode == null) { throw new Exception(String.Format("The {0} does not have any entries", fileDescription)); } // make sure that every topic is included HashSet <Preprocessor.TopicPreprocessor> allTopics = preprocessor.GetAllTopics(false); RemoveUsedTopics(rootNode, allTopics); StringBuilder sb = new StringBuilder(); foreach (Preprocessor.TopicPreprocessor topic in allTopics) { if (!topic.Optional) { sb.AppendLine(Path.GetFileName(topic.Filename)); } } if (sb.Length > 0) { throw new Exception(String.Format("The {0} is missing entries for the topics:\r\n\r\n{1}", fileDescription, sb.ToString())); } return(rootNode); }
public void Compile(string[] lines,Preprocessor preprocessor) { throw new NotImplementedException(); }
public string Format(string[] lines, Preprocessor preprocessor) { Compile(lines, preprocessor); return(TopicListParser.Format(_indexRootNode, true)); }
public void Compile(Preprocessor preprocessor) { Compile(File.ReadAllLines(_indexFilename), preprocessor); }
public void Compile(string[] lines, Preprocessor preprocessor) { _indexRootNode = _indexParser.Parse(lines, preprocessor); }
public void AddContextSensitiveHelp(Preprocessor.TopicPreprocessor preprocessedTopic,string defineId) { }
public string Format(string[] lines,Preprocessor preprocessor) { Compile(lines,preprocessor); return TopicListParser.Format(_tableOfContentsRootNode,false); }
public Topic(Preprocessor.TopicPreprocessor preprocessedTopic) { _preprocessedTopic = preprocessedTopic; }
public void Compile(string[] lines, Preprocessor preprocessor) { throw new NotImplementedException(); }
public string Format(string[] lines,Preprocessor preprocessor) { throw new Exception("The topic file does not support automatic formatting."); }
public string Format(string[] lines, Preprocessor preprocessor) { throw new Exception("The topic file does not support automatic formatting."); }