private static Scope CreateEndRowScope(Scope scope, string content) { int index = content.IndexOf('\n', scope.Index + scope.Length); return index > 0 ? new Scope(ScopeName.TableRowEnd, index, 1) : new Scope(ScopeName.TableRowEnd, content.Length); }
private static bool EnsureBlockStarted(int index, IList<Scope> augmentedScopes, Scope current) { if (index != 0) return false; // this is the first item, ensure the block has started augmentedScopes.Add(CreateStartScope(current)); augmentedScopes.Add(current); return true; }
private static bool EnsureEndingRow(IList<Scope> augmentedScopes, Scope current, Scope peek, string content) { if ((current.Name == ScopeName.TableCell || current.Name == ScopeName.TableCellHeader) && peek.Name == ScopeName.TableRowBegin && (current.Index + current.Length + 2) == peek.Index) { // missing end table row, adding one augmentedScopes.Add(current); augmentedScopes.Add(current.Name == ScopeName.TableCell ? CreateEndRowScope(current, content) : CreateEndRowHeaderScope(current, content)); augmentedScopes.Add(peek); return true; } return false; }
private static Scope CreateStartScope(Scope scope) { return new Scope(ScopeName.TableBegin, scope.Index, scope.Length); }
private static Scope CreateEndScope(Scope scope) { return new Scope(ScopeName.TableEnd, scope.Index + scope.Length); }
private static bool EnsureStartingNewBlockWithEndingRow(IList<Scope> augmentedScopes, Scope current, Scope peek, string content) { if ((current.Name == ScopeName.TableCell || current.Name == ScopeName.TableCellHeader) && (peek.Name == ScopeName.TableRowBegin || peek.Name == ScopeName.TableRowHeaderBegin) && (current.Index + current.Length + 2) < peek.Index) { Scope endRow = current.Name == ScopeName.TableCell ? CreateEndRowScope(current, content) : CreateEndRowHeaderScope(current, content); // missing end table row, and ending a block and starting a new block augmentedScopes.Add(current); augmentedScopes.Add(endRow); augmentedScopes.Add(CreateEndScope(endRow)); augmentedScopes.Add(CreateStartScope(peek)); augmentedScopes.Add(peek); return true; } return false; }
private static bool EnsureStartingNewBlock(IList<Scope> augmentedScopes, Scope current, Scope peek) { if ((current.Name == ScopeName.TableRowEnd || current.Name == ScopeName.TableRowHeaderEnd) && (current.Index + current.Length + 1) < peek.Index) { // ending a block and starting a new block augmentedScopes.Add(current); augmentedScopes.Add(CreateEndScope(current)); augmentedScopes.Add(CreateStartScope(peek)); augmentedScopes.Add(peek); return true; } return false; }
private void RenderScope(StringBuilder writer, Scope scope, string content) { IRenderer renderer = renderers.FirstOrDefault(r => r.CanExpand(scope.Name)); string renderedContent; try { renderedContent = renderer == null ? string.Format("<span class=\"unresolved\">Cannot resolve macro, as no renderers were found.</span>[{0}]", EncodeContent(content)) : renderer.Expand(scope.Name, content, EncodeContent, EncodeAttributeContent); } catch { renderedContent = string.Format("<span class=\"unresolved\">Cannot resolve macro, as an unhandled exception occurred.</span>[{0}]", EncodeContent(content)); } writer.Append(renderedContent); OnScopeRendered(new RenderedScopeEventArgs(scope, content, renderedContent)); }
/// <summary> /// Initializes a new instance of the <see cref="RenderedScopeEventArgs"/> class. /// </summary> /// <param name="scope">The scope name.</param> /// <param name="content">The content.</param> /// <param name="renderedContent">The rendered content.</param> public RenderedScopeEventArgs(Scope scope, string content, string renderedContent) { Scope = scope; Content = content; RenderedContent = renderedContent; }