// If there are any keys defined in this file, store them in a dictionary for easy use private void ParseKeyDefs() { List <DitaElement> keyDefElements = RootElement.FindChildren("keydef"); if (keyDefElements != null) { foreach (DitaElement keyDefElement in keyDefElements) { DitaKeyDef keyDef = new DitaKeyDef { Format = keyDefElement.AttributeValueOrDefault("format", ""), Href = keyDefElement.AttributeValueOrDefault("href", ""), Keys = keyDefElement.AttributeValueOrDefault("keys", ""), Scope = keyDefElement.AttributeValueOrDefault("scope", ""), ProcessingRole = keyDefElement.AttributeValueOrDefault("processing-role", ""), Keywords = keyDefElement.ToString() }; if (!KeyDefs.ContainsKey(keyDef.Keys)) { KeyDefs.Add(keyDef.Keys, keyDef); } else { Trace.TraceWarning($"Duplicate keyref {keyDef.Keys}"); } } } }
private void ResolveKeywords(DitaElement parentElement, DitaCollection collection) { if (parentElement != null) { if (parentElement.Type == "keyword") { string keyref = parentElement.AttributeValueOrDefault("keyref", String.Empty); if (!string.IsNullOrWhiteSpace(keyref)) { // Try to find the referred to file DitaKeyDef keyDef = collection.GetKeyDefByKey(keyref); if (keyDef != null) { if (!string.IsNullOrWhiteSpace(keyDef.Keywords)) { parentElement.SetInnerText(keyDef.Keywords); } } } } else { // Check the child elements if (parentElement.Children != null) { foreach (DitaElement childElement in parentElement.Children) { ResolveKeywords(childElement, collection); } } } } }
// Tries to find a reference to a key with the given name public DitaFile GetFileByKey(string keys) { foreach (DitaFile file in Files) { if (file.KeyDefs.ContainsKey(keys)) { DitaKeyDef keyDef = file.KeyDefs[keys]; if (!string.IsNullOrWhiteSpace(keyDef.Href)) { return(GetFileByName(keyDef.Href)); } } } Trace.TraceWarning($"No keydef found for {keys}"); return(null); }