public void VisitText_WhenTextHasTags_ShouldAddTagPair() { // Arrange var testee = CreateTestee(); A.CallTo(() => _textProcessorMock.Process(TexBeforeProcessing)).Returns(new List <IFragment> { new Fragment(InlineType.StartTag, "start", SegmentationHint.Undefined, true), new Fragment(InlineType.EndTag, "end", SegmentationHint.Undefined, true) }); var startTagPropertiesMock = A.Fake <IStartTagProperties>(); A.CallTo(() => _propertiesFactoryMock.CreateStartTagProperties("start")).Returns(startTagPropertiesMock); var endTagPropertiesMock = A.Fake <IEndTagProperties>(); A.CallTo(() => _propertiesFactoryMock.CreateEndTagProperties("end")).Returns(endTagPropertiesMock); var tagPairMock = A.Fake <ITagPair>(); A.CallTo(() => _itemFactoryMock.CreateTagPair(startTagPropertiesMock, endTagPropertiesMock)).Returns(tagPairMock); // Act testee.VisitText(_textMock); // Assert A.CallTo(() => _sourceParagraphMock.Add(tagPairMock)).MustHaveHappened(); }
public IAbstractMarkupData CreateTagPair(string tagId, string tagContent) { var tagName = GetStartTagName(tagContent, out var refId); var startTagProperties = _propertiesFactory.CreateStartTagProperties(tagContent); if (ExistingTagPairIds.Contains(startTagProperties.TagId.Id)) { if (!ExistingTagPairIds.Contains(tagId)) { startTagProperties.TagId = new TagId(tagId); } else { startTagProperties.TagId = new TagId(GetUniqueTagPairId()); } } if (!ExistingTagPairIds.Contains(startTagProperties.TagId.Id)) { ExistingTagPairIds.Add(startTagProperties.TagId.Id); } var endTagProperties = _propertiesFactory.CreateEndTagProperties("</" + tagName + ">"); //TODO formatting example //var xItem = _formattingFactory.CreateFormattingItem("italic", "True"); //x.Formatting = _formattingFactory.CreateFormatting(); //x.Formatting.Add(xItem); var tagPair = _factory.CreateTagPair(startTagProperties, endTagProperties); return(tagPair); }
internal IStartTagProperties CreateStartTagProperties(IPropertiesFactory factory, string tagContent, IMatchRule rule) { var startProperties = factory.CreateStartTagProperties(tagContent); ApplyInlineTagProperties(startProperties, rule); startProperties.DisplayText = GetDisplayName(tagContent); startProperties.Formatting = FormattingInflator.InflateFormatting(rule.Formatting); startProperties.SegmentationHint = rule.SegmentationHint; return(startProperties); }
private IAbstractMarkupData CreateTags(IFragment startTagFragment, Queue <IFragment> fragments) { var startTagProperties = _propertiesFactory.CreateStartTagProperties(startTagFragment.Content); startTagProperties.DisplayText = CreateDisplayText(startTagFragment.Content); startTagProperties.SegmentationHint = startTagFragment.SegmentationHint; var enclosedContent = new List <IAbstractMarkupData>(); while (fragments.Count > 0) { var fragment = fragments.Dequeue(); switch (fragment.InlineType) { case InlineType.Text: enclosedContent.Add(CreateText(fragment.Content)); break; case InlineType.Placeholder: enclosedContent.Add(CreatePlaceholder(fragment.Content, fragment.SegmentationHint)); break; case InlineType.StartTag: enclosedContent.Add(CreateTags(fragment, fragments)); break; case InlineType.EndTag: var endTagProperties = _propertiesFactory.CreateEndTagProperties(fragment.Content); endTagProperties.DisplayText = CreateDisplayText(fragment.Content); return(fragment.IsContentTranslatable ? CreateTagPair(startTagProperties, endTagProperties, enclosedContent) : CreateLockedContent(enclosedContent)); default: throw new ArgumentOutOfRangeException(); } } throw new ArgumentOutOfRangeException(); }
public IAbstractMarkupData CreateTagPair(string tagId, string tagContent) { var tagName = GetStartTagName(tagContent, out var refId); var startTagProperties = _propertiesFactory.CreateStartTagProperties(tagContent); //if (!string.IsNullOrEmpty(tagId)) //{ // startTagProperties.TagId = new TagId(tagId); //} var endTagProperties = _propertiesFactory.CreateEndTagProperties("</" + tagName + ">"); //TODO formatting example //var xItem = _formattingFactory.CreateFormattingItem("italic", "True"); //x.Formatting = _formattingFactory.CreateFormatting(); //x.Formatting.Add(xItem); var tagPair = _factory.CreateTagPair(startTagProperties, endTagProperties); return(tagPair); }
private static IStartTagProperties CreateStartTagProperties(IPropertiesFactory propertyFactory, IFormattingItemFactory formattingFactory, IFormattingItem formattingItem, int tagId, string colorName) { var startTagProperties = propertyFactory.CreateStartTagProperties("<cf highlight=" + colorName + ">"); if (startTagProperties.Formatting == null) { startTagProperties.Formatting = formattingFactory.CreateFormatting(); } startTagProperties.Formatting.Add(formattingItem); startTagProperties.TagId = new TagId(tagId.ToString()); startTagProperties.CanHide = true; startTagProperties.DisplayText = "cf"; startTagProperties.SetMetaData(CadfBackgroundColorKey, "True"); foreach (var keyPair in GetBackgroundColorMetaData(colorName)) { startTagProperties.SetMetaData(keyPair.Key, keyPair.Value); } return(startTagProperties); }