public NewTopicForm(HelpComponents helpComponents) { InitializeComponent(); _helpComponents = helpComponents; _preprocessedTopic = null; }
private void NewTopicForm_FormClosing(object sender,FormClosingEventArgs e) { if( DialogResult == DialogResult.OK ) { try { if( String.IsNullOrWhiteSpace(textBoxTopicFilename.Text) ) throw new Exception("Enter a topic filename."); string topicsPath = Path.Combine(_helpComponents.projectPath,Constants.TopicsDirectoryName); string topicFilenameWithoutSpaces = textBoxTopicFilename.Text.Trim().Replace(' ','_'); string topicFilename = Path.Combine(topicsPath,topicFilenameWithoutSpaces + Constants.TopicExtension); if( File.Exists(topicFilename) ) throw new Exception("A topic with the filename already exists: " + topicFilename); // create a blank topic file using( TextWriter tw = new StreamWriter(topicFilename,false,Encoding.UTF8) ) tw.WriteLine("<title>{0}</title> <titleheader />",textBoxTopicFilename.Text); _helpComponents.preprocessor.Refresh(); _preprocessedTopic = _helpComponents.preprocessor.GetTopic(Path.GetFileName(topicFilename)); } catch( Exception exception ) { MessageBox.Show(exception.Message); e.Cancel = true; } } }
private void NewTopicForm_FormClosing(object sender, FormClosingEventArgs e) { if (DialogResult == DialogResult.OK) { try { if (String.IsNullOrWhiteSpace(textBoxTopicFilename.Text)) { throw new Exception("Enter a topic filename."); } string topicsPath = Path.Combine(_helpComponents.projectPath, Constants.TopicsDirectoryName); string topicFilenameWithoutSpaces = textBoxTopicFilename.Text.Trim().Replace(' ', '_').ToLower(); string topicFilename = Path.Combine(topicsPath, topicFilenameWithoutSpaces + Constants.TopicExtension); if (File.Exists(topicFilename)) { throw new Exception("A topic with the filename already exists: " + topicFilename); } // create a blank topic file using (TextWriter tw = new StreamWriter(topicFilename, false, Encoding.UTF8)) tw.WriteLine("<title>{0}</title>", textBoxTopicFilename.Text); _helpComponents.preprocessor.Refresh(); _preprocessedTopic = _helpComponents.preprocessor.GetTopic(Path.GetFileName(topicFilename)); } catch (Exception exception) { MessageBox.Show(exception.Message); e.Cancel = true; } } }
public TopicListNode(Preprocessor.TopicPreprocessor topic, string title) { Topic = topic; TitleSpecified = (title != null); Title = TitleSpecified ? title : topic.Title; ChildNode = null; SiblingNode = null; }
public override void AddContextSensitiveHelp(Preprocessor.TopicPreprocessor preprocessedTopic, string defineId) { if (!ContextSensitiveHelps.ContainsKey(preprocessedTopic)) { ContextSensitiveHelps.Add(preprocessedTopic, new List <string>()); } ContextSensitiveHelps[preprocessedTopic].Add(defineId); }
public TopicCompiler(CSPro.Logic.Colorizer colorizer, HelpComponents helpComponents, Preprocessor.TopicPreprocessor preprocessedTopic, TopicCompilerSettingsInterface topicCompilerSettings) { _helpComponents = helpComponents; _preprocessedTopic = preprocessedTopic; _topicCompilerSettings = topicCompilerSettings; _colorizer = colorizer; _colorizer.SetLinkFormatter(GetHtmlFilenameForKeyword); _sb = new StringBuilder(); _tagSettings = new Dictionary <string, TagSettings>(); _tagSettings.Add(TagTitle, new TagSettings(true, (StartTagHandlerDelegate)StartTitleHandler, (EndTagHandlerDelegate)EndTitleHandler, 0, 1)); _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(SuperscriptTag, new TagSettings("<sup>", "</sup>")); _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(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, 4)); _tagSettings.Add(TableCellTag, new TagSettings(true, (StartTagHandlerDelegate)StartTableCellHandler, (EndTagHandlerDelegate)EndTableCellHandler, 0, 2)); _tagSettings.Add(SeeAlsoTag, new TagSettings(false, (StartTagHandlerDelegate)StartSeeAlsoHandler, null, 1, Int32.MaxValue)); _tagSettings.Add(LogicTag, new TagSettings(true, "", (EndTagHandlerDelegate)EndLogicHandler, 0, 0)); _tagSettings.Add(LogicSyntaxTag, new TagSettings(true, (StartTagHandlerDelegate)StartLogicObjectHandler, (EndTagHandlerDelegate)EndLogicSyntaxHandler, 0, 1)); _tagSettings.Add(LogicColorTag, new TagSettings(true, (StartTagHandlerDelegate)StartLogicObjectHandler, (EndTagHandlerDelegate)EndLogicColorHandler, 0, 1)); _tagSettings.Add(LogicArgumentTag, new TagSettings("<span class=\"code_colorization_argument\">", "</span>")); _tagSettings.Add(LogicTableTag, new TagSettings(false, (StartTagHandlerDelegate)StartLogicTableHandler, null, 1, 1)); _tagSettings.Add(MessageTag, new TagSettings(true, "", (EndTagHandlerDelegate)EndMessageHandler, 0, 0)); _tagSettings.Add(ReportTag, new TagSettings(true, (StartTagHandlerDelegate)StartReportHandler, (EndTagHandlerDelegate)EndReportHandler, 0, 1)); _tagSettings.Add(PffTag, new TagSettings(true, "", (EndTagHandlerDelegate)EndPffHandler, 0, 0)); _tagSettings.Add(PffColorTag, new TagSettings(true, "", (EndTagHandlerDelegate)EndPffColorHandler, 0, 0)); _tagSettings.Add(ColorTag, new TagSettings(true, (StartTagHandlerDelegate)StartColorHandler, (EndTagHandlerDelegate)EndColorHandler, 1, 1)); _tagSettings.Add(ColorInlineTag, new TagSettings(true, (StartTagHandlerDelegate)StartColorHandler, (EndTagHandlerDelegate)EndColorInlineHandler, 1, 1)); _tagSettings.Add(HtmlTag, new TagSettings("", "")); _tagSettings.Add(CalloutTag, new TagSettings(true, "<div style=\"background-color: lightgrey;border:1px solid black;margin:10px;padding:10px\">", "</div>", 0, 0)); _tagSettings.Add(PageBreakTag, new TagSettings(false, "<div class=\"new-page\" />", "", 0, 0)); _blockTags = new HashSet <string>(); _blockTags.Add(LogicTag); _blockTags.Add(LogicSyntaxTag); _blockTags.Add(MessageTag); _blockTags.Add(ReportTag); _blockTags.Add(PffTag); _blockTags.Add(ColorTag); _blockTags.Add(HtmlTag); }
public string GetHtmlFilenameForKeyword(string html_filename) { try { string help_filename = html_filename.Replace(Constants.TopicOutputExtension, Constants.TopicExtension); Preprocessor.TopicPreprocessor topic = _helpComponents.preprocessor.GetTopic(help_filename); return(_topicCompilerSettings.GetHtmlFilename(topic)); } catch (Exception) { return(null); } }
private void DisplayTopic(Preprocessor.TopicPreprocessor preprocessedTopic, string topicText = null) { TopicCompiler topicCompiler = new TopicCompiler(_helpComponents, preprocessedTopic, _topicCompilerSettings); if (topicText == null) { topicText = File.ReadAllText(preprocessedTopic.Filename); } string html = topicCompiler.CompileForHtml(topicText); webBrowser.DocumentText = html; _lastDisplayedPreprocessedTopic = preprocessedTopic; labelTopicFilename.Text = Path.GetFileName(_lastDisplayedPreprocessedTopic.Filename); }
private string StartLinkHandler(string[] startTagComponents) { string url = startTagComponents[0]; string extras = ""; try { if (Path.GetExtension(url).Equals(Constants.TopicExtension, StringComparison.InvariantCultureIgnoreCase)) { int colonPos = url.IndexOf("::"); if (colonPos >= 0) // a link to another help document { string document = url.Substring(0, colonPos); string topic = url.Substring(colonPos + 2); _helpComponents.preprocessor.CheckExternalTopic(document, topic); url = _topicCompilerSettings.ConstructLink(LinkType.ExternalTopic, new string[] { document, topic }, ref extras); } else { Preprocessor.TopicPreprocessor topic = _helpComponents.preprocessor.GetTopic(startTagComponents[0]); url = _topicCompilerSettings.ConstructLink(LinkType.Topic, topic, ref extras); } } else if ((url.IndexOf("http", StringComparison.InvariantCultureIgnoreCase) == 0) || (url.IndexOf("mailto", StringComparison.InvariantCultureIgnoreCase) == 0)) { url = _topicCompilerSettings.ConstructLink(LinkType.Other, url, ref extras); } else { throw new Exception("Link could not be processsed"); } } catch (Exception exception) // the topic wasn't found { throw new Exception(String.Format("The topic {0} is invalid ({1})", url, exception.Message)); } return(String.Format("<a href=\"{0}\" {1}>", url, extras)); }
public override string GetStartingHtml(Preprocessor.TopicPreprocessor preprocessedTopic) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<div id=\"container\">"); sb.AppendLine("<div id=\"left\">"); _helpComponents.tableOfContents.GenerateForWebsite(sb, preprocessedTopic); sb.AppendLine("</div>"); sb.AppendLine("<div id=\"middle_spacing1\"></div>"); sb.AppendLine("<div id=\"middle\"></div>"); sb.AppendLine("<div id=\"middle_spacing2\"></div>"); sb.AppendLine("<div id=\"right\">"); return(sb.ToString()); }
private bool NodeContainsTopic(Preprocessor.TopicPreprocessor preprocessedTopic, TopicListParser.TopicListNode node) { while (node != null) { if (node.Topic == preprocessedTopic) { return(true); } if (NodeContainsTopic(preprocessedTopic, node.ChildNode)) { return(true); } node = node.SiblingNode; } return(false); }
private void GenerateForWebsiteNode(StringBuilder sb, Preprocessor.TopicPreprocessor preprocessedTopic, TopicListParser.TopicListNode node) { while (node != null) { string linkedChmFilename = TopicListParser.GetLinkToChm(node.Title); if (linkedChmFilename != null) // a link to another help file { linkedChmFilename = Path.GetFileNameWithoutExtension(linkedChmFilename); sb.AppendLine(String.Format("<li class=\"toc_li_chapter\"><a href=\"../{0}/\"><Helps for {0}></a></li>", linkedChmFilename)); } else if (node.Topic == null) // a chapter { bool continueDownTree = NodeContainsTopic(preprocessedTopic, node.ChildNode); sb.AppendLine(String.Format("<li class=\"{0}\"><a href=\"{1}\">{2}</a>", continueDownTree ? "toc_li_chapter_current" : "toc_li_chapter", GenerateForWebsiteLink(node), node.Title)); if (continueDownTree) { sb.AppendLine("<ul class=\"toc_ul\">"); GenerateForWebsiteNode(sb, preprocessedTopic, node.ChildNode); sb.AppendLine("</ul>"); } sb.AppendLine("</li>"); } else // a topic { sb.AppendLine(String.Format("<li class=\"{0}\"><a href=\"{1}\">{2}</a></li>", (node.Topic == preprocessedTopic) ? "toc_li_topic_current" : "toc_li_topic", GenerateForWebsiteLink(node), node.Title)); } node = node.SiblingNode; } }
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 string GetStartingHtml(Preprocessor.TopicPreprocessor preprocessedTopic) { return(""); }
public void AddContextSensitiveHelp(Preprocessor.TopicPreprocessor preprocessedTopic, string defineId) { }
public string GetStartingHtml(Preprocessor.TopicPreprocessor preprocessedTopic) { return(String.Format("<div id=\"{0}\">", GetHtmlAnchor(preprocessedTopic))); }
private string GetHtmlAnchor(Preprocessor.TopicPreprocessor preprocessedTopic) { return(Path.GetFileNameWithoutExtension(preprocessedTopic.Filename)); }
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 abstract string GetStartingHtml(Preprocessor.TopicPreprocessor preprocessedTopic);
public void GenerateForWebsite(StringBuilder sb, Preprocessor.TopicPreprocessor preprocessedTopic) { sb.AppendLine("<ul class=\"toc_ul\">"); GenerateForWebsiteNode(sb, preprocessedTopic, _tableOfContentsRootNode); sb.AppendLine("</ul>"); }
public Topic(Preprocessor.TopicPreprocessor preprocessedTopic) { _preprocessedTopic = preprocessedTopic; }
public TopicCompiler(Form form, HelpComponents helpComponents, Preprocessor.TopicPreprocessor preprocessedTopic, TopicCompilerSettingsInterface topicCompilerSettings) : this(new CSPro.Logic.Colorizer(form.Handle.ToInt32()), helpComponents, preprocessedTopic, topicCompilerSettings) { }
private string StartTopicHandler(string[] startTagComponents) { Preprocessor.TopicPreprocessor topic = _helpComponents.preprocessor.GetTopic(startTagComponents[0]); return(String.Format("<a href=\"{0}\">{1}</a>", _topicCompilerSettings.GetHtmlFilename(topic), topic.Title)); }