/* Function: GetBodyLinks * Goes through the body of the passed <Topic> and adds any Natural Docs and image links it finds in the <NDMarkup> * to <LinkSet> and <ImageLinkSet>. */ protected void GetBodyLinks(Topic topic, ref LinkSet linkSet, ref ImageLinkSet imageLinkSet) { if (topic.Body == null) { return; } NDMarkup.Iterator iterator = new NDMarkup.Iterator(topic.Body); // Doing two passes of GoToFirstTag is probably faster than iterating through each element if (iterator.GoToFirstTag("<link type=\"naturaldocs\"")) { do { Link link = new Link(); // ignore LinkID link.Type = LinkType.NaturalDocs; link.Text = iterator.Property("originaltext"); link.Context = topic.BodyContext; // ignore contextID link.FileID = topic.FileID; link.ClassString = topic.ClassString; // ignore classID link.LanguageID = topic.LanguageID; // ignore EndingSymbol // ignore TargetTopicID // ignore TargetScore linkSet.Add(link); }while (iterator.GoToNextTag("<link type=\"naturaldocs\"")); } iterator = new NDMarkup.Iterator(topic.Body); if (iterator.GoToFirstTag("<image")) { do { ImageLink imageLink = new ImageLink(); // ignore ImageLinkID imageLink.OriginalText = iterator.Property("originaltext"); imageLink.Path = new Path(iterator.Property("target")); // ignore FileName, generated from Path imageLink.FileID = topic.FileID; imageLink.ClassString = topic.ClassString; // ignore classID // ignore TargetFileID // ignore TargetScore imageLinkSet.Add(imageLink); }while (iterator.GoToNextTag("<image")); } }
/* Function: ExtractTypeLinks * Goes through the prototype of the passed <Topic> and adds any type links it finds to <LinkSet>. */ protected void ExtractTypeLinks(Topic topic, LinkSet linkSet) { if (topic.Prototype == null) { return; } Language language = EngineInstance.Languages.FromID(topic.LanguageID); TokenIterator symbolStart = topic.ParsedPrototype.Tokenizer.FirstToken; TokenIterator symbolEnd; while (symbolStart.IsInBounds) { if (symbolStart.PrototypeParsingType == PrototypeParsingType.Type || symbolStart.PrototypeParsingType == PrototypeParsingType.TypeQualifier) { symbolEnd = symbolStart; do { symbolEnd.Next(); }while (symbolEnd.PrototypeParsingType == PrototypeParsingType.Type || symbolEnd.PrototypeParsingType == PrototypeParsingType.TypeQualifier); if (language.IsBuiltInType(symbolStart, symbolEnd) == false) { Link link = new Link(); // ignore LinkID link.Type = LinkType.Type; link.Symbol = SymbolString.FromPlainText_NoParameters(symbolStart.Tokenizer.TextBetween(symbolStart, symbolEnd)); link.Context = topic.PrototypeContext; // ignore contextID link.FileID = topic.FileID; link.ClassString = topic.ClassString; // ignore classID link.LanguageID = topic.LanguageID; // ignore EndingSymbol // ignore TargetTopicID // ignore TargetScore linkSet.Add(link); } symbolStart = symbolEnd; } else { symbolStart.Next(); } } }
/* Function: GetPrototypeLinks * Goes through the prototype of the passed <Topic> and adds any type links it finds to <LinkSet>. */ protected void GetPrototypeLinks(Topic topic, ref LinkSet linkSet) { if (topic.Prototype == null) { return; } Language language = EngineInstance.Languages.FromID(topic.LanguageID); // We do this even for topics in the class hierarchy because the HTML output falls back to regular prototypes // if there's no class prototype. Also, if there's parameter lists in the description the HTML generator will require // type links to exist regardless of what type of prototype it creates. For example, this SystemVerilog interface: // // // Interface: myInterface // // // // Parameters: // // PARAMNAME - description // // interface myInterface #(parameter PARAMNAME = 8) (input reset, clk); // // The HTML generation for the Parameters section will expect a type link to exist for PARAMNAME. TokenIterator symbolStart = topic.ParsedPrototype.Tokenizer.FirstToken; TokenIterator symbolEnd; while (symbolStart.IsInBounds) { if (symbolStart.PrototypeParsingType == PrototypeParsingType.Type || symbolStart.PrototypeParsingType == PrototypeParsingType.TypeQualifier) { symbolEnd = symbolStart; do { symbolEnd.Next(); }while (symbolEnd.PrototypeParsingType == PrototypeParsingType.Type || symbolEnd.PrototypeParsingType == PrototypeParsingType.TypeQualifier); if (language.Parser.IsBuiltInType(symbolStart, symbolEnd) == false) { Link link = new Link(); // ignore LinkID link.Type = LinkType.Type; link.Symbol = SymbolString.FromPlainText_NoParameters(symbolStart.TextBetween(symbolEnd)); link.Context = topic.PrototypeContext; // ignore contextID link.FileID = topic.FileID; link.ClassString = topic.ClassString; // ignore classID link.LanguageID = topic.LanguageID; // ignore EndingSymbol // ignore TargetTopicID // ignore TargetScore linkSet.Add(link); } symbolStart = symbolEnd; } else { symbolStart.Next(); } } }