public IEnumerable <ContentTranslationDto> BreakIntoParagraphs(string content)
        {
            var contents          = Regex.Split(content.Replace(Environment.NewLine, string.Empty), $@"(<p>[\s\S]+?<\/p>)").ToList();
            var formattedContents = new List <string>();
            var dtos = new List <ContentTranslationDto>();

            foreach (var item in contents)
            {
                var dto = new ContentTranslationDto();

                var formattedItem = item.Replace(paragraphStart, string.Empty).Replace(paragraphEnd, string.Empty).Trim();
                if (string.IsNullOrEmpty(formattedItem))
                {
                    dto.lineBreak        = true;
                    dto.amountLineBreaks = 2;
                    dto.content          = string.Empty;
                }
                else
                {
                    dto.content = formattedItem;
                }

                dtos.Add(dto);
            }

            return(dtos);
        }
Exemplo n.º 2
0
        IList <ContentTranslationDto> BreakIntoAttribute(IEnumerable <ContentTranslationDto> paragraphedContents, FontAttribute attribute, string regexPattern, string attributeMarkStart, string attributeMarkEnd)
        {
            var regexSplitter = new RegexSplitter();

            var newContents = new List <ContentTranslationDto>();

            foreach (var content in paragraphedContents)
            {
                var contents = regexSplitter.Split(content.content, regexPattern);

                if (content.lineBreak)
                {
                    newContents.Add(content);
                }

                foreach (var item in contents)
                {
                    var hasAttribute  = (item.Contains(attributeMarkStart) && item.Contains(attributeMarkEnd));
                    var formattedItem = item.Replace(attributeMarkStart, string.Empty).Replace(attributeMarkEnd, string.Empty);

                    var dto = new ContentTranslationDto()
                    {
                        content = formattedItem, fontAttribute = hasAttribute ? attribute : FontAttribute.None
                    };

                    newContents.Add(dto);
                }
            }

            return(newContents);
        }
        public async Task <IEnumerable <ContentTranslationDto> > MapDtoToTranslatedContentAsync(IEnumerable <PageContentDto> contents)
        {
            return(await Task.Run(() =>
            {
                var translatedContents = new List <ContentTranslationDto>();

                foreach (var item in contents)
                {
                    var translatedContent = new ContentTranslationDto();
                    translatedContent.amountLineBreaks = item.AmountLineBreaks;
                    translatedContent.content = item.Content;
                    translatedContent.fontAttribute = (FontAttribute)item.FontAttribute;
                    translatedContent.fontFamily = item.FontFamily;
                    translatedContent.fontSize = (FontNamedSize)item.FontSize;
                    translatedContent.hexBackgroundColor = item.HexBackgroundColor;
                    translatedContent.hexForegroundColor = item.HexForegroundColor;
                    translatedContent.lineBreak = item.LineBreak;

                    translatedContents.Add(translatedContent);
                }

                return translatedContents;
            }));
        }