예제 #1
0
        public IAbstractMarkupData CreateTagPair(string tagId, string tagContent)
        {
            var tagName = GetStartTagName(tagContent, out var refId);

            // Dev Notes: the tagContent is switched with the Display text to align with how the tags are
            // recreated by the XLIFF 1.2 parser from the framework

            var startTagProperties = PropertiesFactory.CreateStartTagProperties("<bpt id=\"" + tagId + "\">");

            startTagProperties.DisplayText = tagContent;
            startTagProperties.SetMetaData("localName", "bpt");
            startTagProperties.SetMetaData("displayText", tagContent);
            startTagProperties.SetMetaData("attribute:id", tagId);

            if (ExistingTagIds.Contains(startTagProperties.TagId.Id))
            {
                startTagProperties.TagId = !ExistingTagIds.Contains(tagId)
                                        ? new TagId(tagId)
                                        : new TagId(GetUniqueTagPairId());
            }

            if (!ExistingTagIds.Contains(startTagProperties.TagId.Id))
            {
                ExistingTagIds.Add(startTagProperties.TagId.Id);
            }

            var endTagProperties = PropertiesFactory.CreateEndTagProperties("<ept id=\"" + tagId + "\">");

            endTagProperties.DisplayText = "</" + tagName + ">";
            endTagProperties.SetMetaData("localName", "ept");
            endTagProperties.SetMetaData("displayText", "</" + tagName + ">");
            endTagProperties.SetMetaData("attribute:id", tagId);


            //TODO formatting example
            //var xItem = _formattingFactory.CreateFormattingItem("italic", "True");
            //x.Formatting = _formattingFactory.CreateFormatting();
            //x.Formatting.Add(xItem);

            var tagPair = ItemFactory.CreateTagPair(startTagProperties, endTagProperties);

            return(tagPair);
        }
        private ITagPair CreateTagPair(XmlNode item)
        {
            // create the start and the end tag
            IStartTagProperties startTag = PropertiesFactory.CreateStartTagProperties(item.Name);

            #region "formatting"
            // apply character formatting to the start tag
            IFormattingGroup formattingGroup = PropertiesFactory.FormattingItemFactory.CreateFormatting();
            startTag.Formatting = new FormattingGroup();
            switch (item.Name)
            {
            case "b":
                formattingGroup.Add(new Bold(true));
                break;

            case "i":
                formattingGroup.Add(new Italic(true));
                break;

            case "u":
                formattingGroup.Add(new Underline(true));
                break;

            default:
                break;
            }
            startTag.Formatting = formattingGroup;
            #endregion

            startTag.DisplayText = item.Name;
            startTag.CanHide     = true;
            IEndTagProperties endTag = PropertiesFactory.CreateEndTagProperties(item.Name);
            endTag.DisplayText = item.Name;
            endTag.CanHide     = true;

            // create a tag pair out of the start and the end tag
            ITagPair tagPair = ItemFactory.CreateTagPair(startTag, endTag);

            // add text enclosed in the tag pair
            tagPair.Add(CreateText(item.InnerText));

            return(tagPair);
        }
예제 #3
0
        public ITagPair CreateTagPair(string tagId, string tagContent, ref List <string> existingTagIds)
        {
            var tagName            = GetStartTagName(tagContent, out var refId);
            var startTagProperties = PropertiesFactory.CreateStartTagProperties("<" + tagName + " id=\"" + tagId + "\">");

            startTagProperties.DisplayText = tagContent;
            startTagProperties.SetMetaData("localName", tagName);
            startTagProperties.SetMetaData("displayText", tagContent);
            startTagProperties.SetMetaData("attribute:id", tagId);

            if (existingTagIds.Contains(startTagProperties.TagId.Id))
            {
                startTagProperties.TagId = !existingTagIds.Contains(tagId)
                                        ? new TagId(tagId)
                                        : new TagId(GetUniqueTagPairId(existingTagIds));
            }

            if (!existingTagIds.Contains(startTagProperties.TagId.Id))
            {
                existingTagIds.Add(startTagProperties.TagId.Id);
            }

            var endTagProperties = PropertiesFactory.CreateEndTagProperties("</" + tagName + ">");

            endTagProperties.DisplayText = "</" + tagName + ">";
            endTagProperties.SetMetaData("localName", tagName);
            endTagProperties.SetMetaData("displayText", "</" + tagName + ">");
            endTagProperties.SetMetaData("attribute:id", tagId);


            //TODO formatting example
            //var xItem = _formattingFactory.CreateFormattingItem("italic", "True");
            //x.Formatting = _formattingFactory.CreateFormatting();
            //x.Formatting.Add(xItem);

            var tagPair = ItemFactory.CreateTagPair(startTagProperties, endTagProperties);


            return(tagPair);
        }
        // this function outputs an opening or a closing <b> tag
        // and applies bold character formatting to the strings
        // that the tags enclose
        private void WriteInlineTag(string tagContent, bool isStart)
        {
            _fBold = new FormattingGroup();
            _fBold.Add(new Bold(true));

            if (isStart)
            {
                IStartTagProperties startTag = PropertiesFactory.CreateStartTagProperties(tagContent);
                startTag.DisplayText = "b";
                startTag.TagContent  = tagContent;
                startTag.Formatting  = _fBold;
                startTag.CanHide     = true;
                Output.InlineStartTag(startTag);
            }
            else
            {
                IEndTagProperties endTag = PropertiesFactory.CreateEndTagProperties(tagContent);
                endTag.DisplayText = "b";
                endTag.TagContent  = tagContent;
                endTag.CanHide     = true;
                Output.InlineEndTag(endTag);
            }
        }