public override IEnumerable <string> GetQueryLines(string[] lines, DfmFencesToken token) { // NOTE: Parsing language and removing comment lines only do for tag name representation var lang = GetCodeLanguageOrExtension(token); if (!_codeLanguageExtractors.TryGetValue(lang, out List <ICodeSnippetExtractor> extractors)) { throw new DfmCodeExtractorException($"{lang} is not supported languaging name, alias or extension for parsing code snippet with tag name, you can use line numbers instead"); } _resolveResult = ResolveTagNamesFromPath(token.Path, lines, TagName, extractors); if (!string.IsNullOrEmpty(_resolveResult.ErrorMessage)) { Logger.LogWarning( DfmCodeExtractor.GenerateErrorMessage(token, _resolveResult.ErrorMessage), line: token.SourceInfo.LineNumber.ToString()); } var included = new List <string>(); for (int i = _resolveResult.StartLine; i <= Math.Min(_resolveResult.EndLine, lines.Length); i++) { if (_resolveResult.ExcludesLines == null || !_resolveResult.ExcludesLines.Contains(i)) { included.Add(lines[i - 1]); } } return(ProcessIncludedLines(included, token)); }
protected IEnumerable <string> ProcessIncludedLines(List <string> lines, DfmFencesToken token) { var message = ValidateHighlightLinesAndDedentLength(lines.Count); if (!string.IsNullOrEmpty(message)) { Logger.LogWarning( DfmCodeExtractor.GenerateErrorMessage(token, message), line: token.SourceInfo.LineNumber.ToString()); ErrorMessage = message; } return(DfmCodeExtractor.Dedent(lines, DedentLength)); }
public DfmCodeRenderer(CodeLanguageExtractorsBuilder builder) { _dfmCodeExtractor = new DfmCodeExtractor(builder); }
public DfmCodeRenderer(DfmCodeExtractor extractor) { _dfmCodeExtractor = extractor ?? new DfmCodeExtractor(); }