示例#1
0
        public StaticTextViewModel GetRenderedHtmlText(string name)
        {
            var staticTextEntity = new GetStaticTextWork(m_staticTextRepository, name).Execute();

            if (staticTextEntity == null)
            {
                return(new StaticTextViewModel
                {
                    Name = name,
                    Format = StaticTextFormatType.Markdown,
                    IsRecordExists = false
                });
            }

            var viewModel = Mapper.Map <StaticTextViewModel>(staticTextEntity);

            switch (staticTextEntity.Format)
            {
            case StaticTextFormat.Markdown:
                viewModel.Text   = m_markdownToHtmlConverter.ConvertToHtml(staticTextEntity.Text);
                viewModel.Format = StaticTextFormatType.Html;
                break;

            case StaticTextFormat.PlainText:
            case StaticTextFormat.Html:
                break;
            }

            return(viewModel);
        }
示例#2
0
        public StaticTextViewModel GetRenderedHtmlText(string name, string scope)
        {
            scope = m_dictionaryScopeResolver.GetDictionaryScope(scope);
            var text = m_localizationService.Translate(name, scope, LocTranslationSource.Database);

            var htmlText = m_markdownToHtmlConverter.ConvertToHtml(text);

            var viewModel = new StaticTextViewModel
            {
                Name  = name,
                Text  = htmlText,
                Scope = scope
            };

            return(viewModel);
        }
示例#3
0
        private string ConvertTextFormat(TextFormatEnumContract targetFormat, string text)
        {
            switch (targetFormat)
            {
            case TextFormatEnumContract.Html:
                return(m_markdownConverter.ConvertToHtml(text));

            case TextFormatEnumContract.Raw:
                return(text);

            case TextFormatEnumContract.Rtf:
                throw new MainServiceException(MainServiceErrorCode.UnsupportedFormatType, "Converting text to RTF format is not supported");

            default:
                throw new MainServiceException(MainServiceErrorCode.UnsupportedFormatType, $"Converting text to unknown format {targetFormat} is not supported");
            }
        }
示例#4
0
        public ActionResult RenderPreview([FromBody] RenderTextPreviewRequest request)
        {
            string result;

            switch (request.InputTextFormat)
            {
            case StaticTextFormatType.Markdown:
                result = m_markdownToHtmlConverter.ConvertToHtml(request.Text);
                break;

            default:
                result = request.Text;
                break;
            }

            return(Json(result));
        }
示例#5
0
        public string Convert(string textResourceText, TextFormatEnumContract formatValue)
        {
            switch (formatValue)
            {
            case TextFormatEnumContract.Raw:
                return(textResourceText);

            case TextFormatEnumContract.Html:
                return(m_markdownToHtmlConverter.ConvertToHtml(textResourceText));

            case TextFormatEnumContract.Rtf:
                throw new NotSupportedException();

            default:
                throw new ArgumentOutOfRangeException(nameof(formatValue), formatValue, null);
            }
        }
 public string Convert(string text)
 {
     return(m_htmlToPlainTextConverter.ConvertToPlaintext(m_markdownToHtmlConverter.ConvertToHtml(text)));
 }