public string MarkedToHtml() { HtmlText = service.MarkedToHtml(MarkedText); var str = HtmlTransformService.ToHtml(HtmlText); return(str); }
public TransformEditViewModel(SettingsViewModel vmSettings, MDictionaryEdit itemEdit) { TEMPLATE = itemEdit.TEMPLATE; URL = itemEdit.URL; TransformItems = new ObservableCollection <MTransformItem>(HtmlTransformService.ToTransformItems(itemEdit.TRANSFORM)); this.WhenAnyValue(x => x.IntermediateResults).Subscribe(_ => IntermediateText = IntermediateResults[IntermediateIndex = 0]); this.WhenAnyValue(x => x.IntermediateIndex).Subscribe(_ => IntermediateText = IntermediateResults[IntermediateIndex]); GetHtmlCommand = ReactiveCommand.CreateFromTask(async() => { SourceUrl = string.Format(URL, SourceWord); SourceText = await vmSettings.client.GetStringAsync(SourceUrl); }); ExecuteTransformCommand = ReactiveCommand.Create(() => { var text = HtmlTransformService.RemoveReturns(SourceText); IntermediateResults = new List <string> { text }; foreach (var item in TransformItems) { text = HtmlTransformService.DoTransform(text, item); IntermediateResults.Add(text); } IntermediateMaxIndex = IntermediateResults.Count - 1; ResultText = text; ResultHtml = string.IsNullOrEmpty(TEMPLATE) ? HtmlTransformService.ToHtml(text) : HtmlTransformService.ApplyTemplate(TEMPLATE, SourceWord, text); }); GetAndTransformCommand = ReactiveCommand.CreateFromObservable(() => GetHtmlCommand.Execute().Concat(ExecuteTransformCommand.Execute())); Save = ReactiveCommand.Create(() => { itemEdit.TRANSFORM = string.Join("\r\n", TransformItems.SelectMany(o => new[] { o.Extractor, o.Replacement })); itemEdit.TEMPLATE = TEMPLATE; }); TransformItems.CollectionChanged += (s, e) => Reindex(); }