public void Initalize() { _instance = new ProcessorFactory(); _containerBuilder = new ContainerBuilder(); _globalContext = Substitute.For <IGlobalContext>(); _elementContext = Substitute.For <IElementContext>(); }
public static HtmlNode[] Step1(IElementContext elementContext) { var nodes = elementContext.Nodes.ToList(); HtmlNodesFlatterner.Flattern(nodes); return(nodes.ToArray()); }
private void TestSample1() { var(context, hyperlink) = TOCSample1.GenerateProcessingArgs(); _elementContext = context; _elementContext.Nodes.Returns(new HtmlNode[] { _pNode }); _instance.ProcessHyperlink(_elementContext, hyperlink); }
private void ApplyTOC(IElementContext context, Hyperlink a, Match m) { RemovePreviousText(context); ReplaceCrossRefBySpacer(context, m); AddCssClassParagraph(context.Nodes); context.ProcessChilden(); }
private void RemovePreviousText(IElementContext context) { context.AddMutation(new TextDeletion { Position = 0, Count = context.TextIndex }); }
public static bool IsOffsetInsideElement(IElementContext element, int offset) { var isInsideStartTag = element.StartTagSource.Offset <= offset && element.StartTagSource.EndOffset >= offset; var isInsideEndTag = element.EndTagSource.Offset <= offset && element.EndTagSource.EndOffset >= offset; return(isInsideStartTag || isInsideEndTag); }
public void InsertNumbering(IElementContext context, Paragraph p) { var numberingMapper = context.Resolve <INumberingMapper>(); if (!numberingMapper.IsValid) { return; } var paragraphData = numberingMapper.GetNumbering(p); if (paragraphData != null) { context.ViewBag[_config.ParagraphNumberingDataKey] = (paragraphData.NumberingId, paragraphData.LevelIndex); context.AddNode(BuildNumberingContainer()); if (context.TryResolve(out ICssRegistrator cssRegistrator)) { context.AddNode(BuildNumberingNumber(p, cssRegistrator, paragraphData)); } else { context.AddNode(BuildNumberingNumber(p, paragraphData)); } } }
private void MockElementContext(int numberingId, int levelId, string verbose) { _p = new Paragraph(); _pData = Substitute.For <IParagraphData>(); _pData.NumberingId.Returns(numberingId); _pData.LevelIndex.Returns(levelId); _pData.Verbose.Returns(verbose); _pData.LevelXmlElement.Returns(_level); _nMapper = Substitute.For <INumberingMapper>(); _nMapper.IsValid.Returns(true); _nMapper.GetNumbering(_p).Returns(_pData); _cssRegistrator = Substitute.For <ICssRegistrator>(); _cssRegistrator .RegisterRun(Arg.Any <ParagraphProperties>(), Arg.Any <RunProperties>(), (numberingId, levelId)) .Returns(new CssClass { Name = $"dynamic-cls" }); _elementContext = Substitute.For <IElementContext>(); _elementContext.Resolve <INumberingMapper>().Returns(_nMapper); _elementContext.TryResolve(out ICssRegistrator z).Returns(x => { x[0] = _cssRegistrator; return(true); }); _elementContext.Element.Returns(_p); _elementContext.RootElement.Returns(_p); _elementContext .When(x => x.AddNode(Arg.Any <HtmlNode>())) .Do(x => _nodes.Add(x.ArgAt <HtmlNode>(0))); _elementContext .When(x => x.AddMutation(Arg.Any <Mutation>())) .Do(x => _mutations.Add(x.ArgAt <Mutation>(0))); }
public StartTagNameSuggestion(DataTypes dataTypes, IElementContext parentElement, IElementContext targetElement, IDictionary <string, string> namespaceDeclarations) { _dataTypes = dataTypes; _parentElement = parentElement; _targetElement = targetElement; _namespaceDeclarations = namespaceDeclarations; }
private Task <string> RenderElementContext(IElementContext context) { return(Task.Factory.StartNew(state => { string x = ContextRenderer.Render((IElementContext)state); return x; }, context)); }
public void InsertSoftHyphen(IElementContext context, SoftHyphen hyphen) { context.AddMutation(new TextInsertion { Position = context.TextIndex, Text = "­" }); }
public void InsertNoBreakHyphen(IElementContext context, NoBreakHyphen hyphen) { context.AddMutation(new TextInsertion { Position = context.TextIndex, Text = "‑" }); }
private void AssertHasProcessedAllRootElements() { foreach (var elem in _globalContext.RootElements) { IElementContext processorContextArg = BuildProcessArgValidator(elem.RootElement); _processor.Received(1).ProcessElement(processorContextArg, Arg.Is(elem.RootElement)); } }
protected override IElement OnBuild(IElementContext context) { IElementParent parent = OnBuildParent(context); OnBuildChildren(parent, context); return(parent); }
private static void DeleteAllText(IElementContext context, Table table) { context.AddMutation(new TextDeletion { Count = table.InnerText.Length, Position = 0 }); }
public StandardAttributesSuggestion(DataTypes dataTypes, IElementContext targetElement, IElementContext parentElement, string attributeName, ICodeReader codeReader, IDictionary <string, string> namespaces) { _dataTypes = dataTypes; _targetElement = targetElement; _parentElement = parentElement; _attributeName = attributeName; _codeReader = codeReader; _namespaces = namespaces; }
public void Initialize() { _instance = new InstrTxtCleanupPlugin(); _mutations = new List <Mutation>(); _context = Substitute.For <IElementContext>(); _context .When(x => x.AddMutation(Arg.Any <Mutation>())) .Do(x => _mutations.Add(x.ArgAt <Mutation>(0))); }
private void ReplaceCrossRefBySpacer(IElementContext context, Match m) { context.AddMutation(new TextDeletion { Position = m.Index, Count = m.Length, }); context.AddNode(GenerateSpaceNode(m.Index)); }
public void Initialize() { _instance = new EscapeHtmlPlugin(); _mutations = new List <Mutation>(); _context = Substitute.For <IElementContext>(); _context.TextIndex.Returns(0); _context .When(x => x.AddMutations(Arg.Any <IEnumerable <Mutation> >())) .Do(x => _mutations.AddRange(x.ArgAt <IEnumerable <Mutation> >(0))); }
public void EscapeCharacters(IElementContext context, Paragraph p) { string text = p.InnerText; var mutations = FindEscapeChar(context.TextIndex, text); if (mutations.Any()) { context.AddMutations(mutations); } }
public static IEnumerable <IElementContext> TraverseAllChildren(this IElementContext element) { foreach (var child in element.Children) { foreach (var i in TraverseSelfAndAllChildren(child)) { yield return(i); } } }
public void Initialize() { _config = new TableOfContentConfig(); _instance = new TableOfContentPlugin(_config); _pNode = new HtmlNode { Start = 0, Tag = "p" }; _elementContext = Substitute.For <IElementContext>(); _elementContext.Nodes.Returns(new HtmlNode[] { _pNode }); }
static string[] GetNamespacesForElement(IElementContext element, IDictionary <string, string> namespaceDeclarations) { var ns = GetQualifiedNamespaceForElement(element); if (ns != null) { return new string[] { ns } } ; return(namespaceDeclarations.Keys.ToArray()); }
Context(SourceFile file, AXmlDocument document, int caret) { _file = file; _document = document; _caret = caret; var root = document.Children.OfType <AXmlElement>().FirstOrDefault(); _root = root == null ? null : new ElementContext(file, root, null); _targetElement = _root == null ? null : FindTargetElement(); InitNamespaces(); }
public static DataType ToDataType(this IElementContext element, IEnumerable <DataType> dataTypes, IEnumerable <KeyValuePair <string, string> > namespaces) { if (element.Name.Contains('.')) { return(dataTypes.FirstOrDefault(d => d.QualifiedName == element.Name)); } var elmNamespaces = DataTypeHelper.ResolveNamespacesForNamespacePrefix(element.NamespacePrefix, namespaces); return(dataTypes.FirstOrDefault(d => DataTypeHelper.IsNameThisDataType(element.Name, elmNamespaces, d))); }
public void Initialize() { _instance = new HyphenInsertionPlugin(); _textInsertions = new List<TextInsertion>(); _context = Substitute.For<IElementContext>(); _context.TextIndex.Returns(666); _context.When(x => x.AddMutation(Arg.Any<Mutation>())).Do(x => { if (x.ArgAt<Mutation>(0) is TextInsertion ti) _textInsertions.Add(ti); }); }
private void FixContainer(IElementContext context) { var container = context.Nodes .FirstOrDefault(IsContainer); if (container != null) { container.AddClasses(_config.BreakAtStartCls); } }
public void RemoveCrossRefs(IElementContext context, Paragraph p) { foreach (Match match in crossReferenceRegex.Matches(p.InnerText)) { context.AddMutation(new TextDeletion { Position = context.TextIndex + match.Index, Count = match.Length }); } }
private void AddWarningNode(IElementContext context) { var node = new HtmlNode { Start = 0, End = 0, TextPrefix = _config.WarningMessage }; node.AddClasses(_config.WarningCssClass); context.AddNode(node); }
public void ProcessHyperlink(IElementContext context, Hyperlink a) { if (context.RootElement.LastChild == a) { var m = tocRegex.Match(context.RootElement.InnerText); if (!m.Success) { return; } ApplyTOC(context, a, m); } }