in src/dotnet/APIView/APIView/CodeFileRenderer.cs [32:218]
private void Render(List<CodeLine> list, IEnumerable<CodeFileToken> node, bool showDocumentation, bool enableSkipDiff, Dictionary<int,TreeNode<CodeLine>> sections)
{
var stringBuilder = new StringBuilder();
string currentId = null;
string currentCrossLangId = null;
string currentTableId = null;
bool isDocumentationRange = false;
bool isHiddenApiToken = false;
bool isDeprecatedToken = false;
bool isSkipDiffRange = false;
Stack<SectionType> nodesInProcess = new Stack<SectionType>();
int lineNumber = 0;
(int Count, int Curr) tableColumnCount = (0, 0);
(int Count, int Curr) tableRowCount = (0, 0);
TreeNode<CodeLine> section = null;
int leafSectionPlaceHolderNumber = 0;
foreach (var token in node)
{
// Skip all tokens till range end
if (enableSkipDiff && isSkipDiffRange && token.Kind != CodeFileTokenKind.SkipDiffRangeEnd)
continue;
if (!showDocumentation && isDocumentationRange && token.Kind != CodeFileTokenKind.DocumentRangeEnd)
continue;
switch (token.Kind)
{
case CodeFileTokenKind.Newline:
CaptureCodeLine(list, sections, nodesInProcess, ref section, stringBuilder, ref lineNumber, ref leafSectionPlaceHolderNumber, ref currentId, ref currentCrossLangId, isDocumentationRange, isHiddenApiToken);
break;
case CodeFileTokenKind.DocumentRangeStart:
StartDocumentationRange(stringBuilder);
isDocumentationRange = true;
break;
case CodeFileTokenKind.DocumentRangeEnd:
CloseDocumentationRange(stringBuilder);
isDocumentationRange = false;
break;
case CodeFileTokenKind.HiddenApiRangeStart:
isHiddenApiToken = true;
break;
case CodeFileTokenKind.HiddenApiRangeEnd:
isHiddenApiToken = false;
break;
case CodeFileTokenKind.DeprecatedRangeStart:
isDeprecatedToken = true;
break;
case CodeFileTokenKind.DeprecatedRangeEnd:
isDeprecatedToken = false;
break;
case CodeFileTokenKind.SkipDiffRangeStart:
isSkipDiffRange = true;
break;
case CodeFileTokenKind.SkipDiffRangeEnd:
isSkipDiffRange = false;
break;
case CodeFileTokenKind.FoldableSectionHeading:
nodesInProcess.Push(SectionType.Heading);
currentId = (token.DefinitionId != null) ? token.DefinitionId : currentId;
currentCrossLangId = (token.CrossLanguageDefinitionId != null) ? token.CrossLanguageDefinitionId : currentCrossLangId;
RenderToken(token, stringBuilder, isDeprecatedToken, isHiddenApiToken);
break;
case CodeFileTokenKind.FoldableSectionContentStart:
nodesInProcess.Push(SectionType.Content);
break;
case CodeFileTokenKind.FoldableSectionContentEnd:
section = (section.IsRoot) ? section : section.Parent;
nodesInProcess.Pop();
if (nodesInProcess.Peek().Equals(SectionType.Heading))
{
nodesInProcess.Pop();
}
if (nodesInProcess.Count == 0 && section != null)
{
sections.Add(sections.Count, section);
section = null;
}
break;
case CodeFileTokenKind.TableBegin:
currentTableId = (token.DefinitionId != null) ? token.DefinitionId : currentId;
break;
case CodeFileTokenKind.TableColumnCount:
tableColumnCount.Count = Convert.ToInt16(token.Value);
tableColumnCount.Curr = 0;
break;
case CodeFileTokenKind.TableRowCount:
tableRowCount.Count = Convert.ToInt16(token.Value);
tableRowCount.Curr = 0;
break;
case CodeFileTokenKind.TableColumnName:
if (tableColumnCount.Curr == 0)
{
stringBuilder.Append($"<ul class=\"list-group list-group-horizontal\">");
stringBuilder.Append($"<li class=\"list-group-item border-top\"><strong>");
RenderToken(token, stringBuilder, isDeprecatedToken, isHiddenApiToken);
stringBuilder.Append("</strong></li>");
tableColumnCount.Curr++;
}
else if (tableColumnCount.Curr == tableColumnCount.Count - 1)
{
currentId = $"{currentTableId}-th";
stringBuilder.Append($"<li class=\"list-group-item border-top\"><strong>");
RenderToken(token, stringBuilder, isDeprecatedToken, isHiddenApiToken);
stringBuilder.Append("</strong></li>");
stringBuilder.Append("</ul>");
tableColumnCount.Curr = 0;
CaptureCodeLine(list, sections, nodesInProcess, ref section, stringBuilder, ref lineNumber, ref leafSectionPlaceHolderNumber, ref currentId, ref currentCrossLangId, isDocumentationRange, isHiddenApiToken);
}
else
{
stringBuilder.Append($"<li class=\"list-group-item border-top\"><strong>");
RenderToken(token, stringBuilder, isDeprecatedToken, isHiddenApiToken);
stringBuilder.Append("</strong></li>");
tableColumnCount.Curr++;
}
break;
case CodeFileTokenKind.TableCellBegin:
if (tableColumnCount.Curr == 0)
{
stringBuilder.Append($"<ul class=\"list-group list-group-horizontal\">");
stringBuilder.Append($"<li class=\"list-group-item\">");
tableColumnCount.Curr++;
}
else if (tableColumnCount.Curr == tableColumnCount.Count - 1)
{
currentId = $"{currentTableId}-tr-{tableRowCount.Curr + 1}";
stringBuilder.Append($"<li class=\"list-group-item\">");
tableColumnCount.Curr = 0;
tableRowCount.Curr++;
}
else
{
stringBuilder.Append($"<li class=\"list-group-item\">");
tableColumnCount.Curr++;
}
break;
case CodeFileTokenKind.TableCellEnd:
stringBuilder.Append("</li>");
if (tableColumnCount.Curr == 0)
{
stringBuilder.Append("</ul>");
CaptureCodeLine(list, sections, nodesInProcess, ref section, stringBuilder, ref lineNumber, ref leafSectionPlaceHolderNumber, ref currentId, ref currentCrossLangId, isDocumentationRange, isHiddenApiToken);
}
break;
case CodeFileTokenKind.TableEnd:
break;
case CodeFileTokenKind.LeafSectionPlaceholder:
stringBuilder.Append(token.Value);
leafSectionPlaceHolderNumber = (int)token.NumberOfLinesinLeafSection;
break;
case CodeFileTokenKind.ExternalLinkStart:
stringBuilder.Append($"<a target=\"_blank\" href=\"{token.Value}\">");
break;
case CodeFileTokenKind.ExternalLinkEnd:
stringBuilder.Append("</a>");
break;
default:
currentId = (token.DefinitionId != null) ? token.DefinitionId : currentId;
currentCrossLangId = (token.CrossLanguageDefinitionId != null) ? token.CrossLanguageDefinitionId : currentCrossLangId;
RenderToken(token, stringBuilder, isDeprecatedToken, isHiddenApiToken);
break;
}
}
}