Esempio n. 1
0
        public string HtmlString(string html, string word, bool useTemplate2 = false)
        {
            var template = useTemplate2 && !string.IsNullOrEmpty(TEMPLATE2) ? TEMPLATE2 : TEMPLATE;

            return(HtmlTransformService.ExtractTextFromHtml(html, TRANSFORM, template, (text, template2) =>
                                                            HtmlTransformService.ApplyTemplate(template2, word, text)));
        }
Esempio n. 2
0
        public string MarkedToHtml()
        {
            HtmlText = service.MarkedToHtml(MarkedText);
            var str = HtmlTransformService.ToHtml(HtmlText);

            return(str);
        }
Esempio n. 3
0
        async Task <string> GetTranslation()
        {
            if (!vmSettings.HasDictTranslation)
            {
                return("");
            }
            var url  = DictTranslation.UrlString(CurrentWord, vmSettings.AutoCorrects);
            var html = await vmSettings.client.GetStringAsync(url);

            return(HtmlTransformService.ExtractTextFromHtml(html, DictTranslation.TRANSFORM, "", (text, _) => text));
        }
Esempio n. 4
0
 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();
 }