internal InlineInfo(InlineType inlineType, TInline inline, Tag tag) : this() { this.InlineType = inlineType; this.Inline = inline; this.Tag = tag; }
private static IEnumerable <TagMatch> GetTagMatches(IList <TagMatch> tagMatchesPerChar, IEnumerable regexMatches, InlineType inlineType, MatchRule matchRule) { foreach (Match regexMatch in regexMatches) { var newTagMatch = new TagMatch(inlineType, regexMatch, matchRule); var currentTagMatch = tagMatchesPerChar[newTagMatch.Start]; if (currentTagMatch != null && currentTagMatch.End == newTagMatch.End) { continue; } var indexBeforeNewTagMatch = newTagMatch.Start - 1; if (newTagMatch.Start != 0 && tagMatchesPerChar[indexBeforeNewTagMatch] != null && tagMatchesPerChar[indexBeforeNewTagMatch].End >= newTagMatch.Start) { continue; } var indexAfterNewTagMatch = newTagMatch.Start + newTagMatch.Length; if (indexAfterNewTagMatch != tagMatchesPerChar.Count && tagMatchesPerChar[indexAfterNewTagMatch] != null && tagMatchesPerChar[indexAfterNewTagMatch].Start <= newTagMatch.End) { continue; } yield return(newTagMatch); } }
public Fragment(InlineType inlineType, string content, SegmentationHint segmentationHint, bool isContentTranslatable) { InlineType = inlineType; Content = content; SegmentationHint = segmentationHint; IsContentTranslatable = isContentTranslatable; }
private static void AddTagMatches(IList <TagMatch> tagMatchesPerChar, IEnumerable regexMatches, InlineType inlineType, MatchRule matchRule) { var newTagMatches = GetTagMatches(tagMatchesPerChar, regexMatches, inlineType, matchRule); foreach (var newTagMatch in newTagMatches) { for (var i = newTagMatch.Start; i <= newTagMatch.End; ++i) { tagMatchesPerChar[i] = newTagMatch; } } }
public void BeginRenderInline(InlineType inlineType, Tag tag) { #if PRINT_RENDER System.Diagnostics.Debug.WriteLine("BeginRenderInline({0}, {1}, \"{2}\")", inlineType, tag?.Name, tag?.Value ?? "<no value>"); #endif var inline = CreateInline(inlineType, tag); var inlineInfo = new InlineInfo(inlineType, inline, tag); if (this.inlineStack.Count == 0 || AddInline(this.inlineStack.Peek().Inline, inlineInfo.Inline) == false) { if (this.blockStack.Count == 0) { // There was no content before this tag on a new line, so create a new paragraph implicitly BeginRenderBlock(BlockType.Paragraph, null); } AddInline(this.blockStack.Peek().Block, inlineInfo.Inline); } this.inlineStack.Push(inlineInfo); }
private static Span CreateSpan(InlineType inlineType, string param) { Span span = null; switch (inlineType) { case InlineType.Hyperlink: var link = new Hyperlink(); Uri uri; if (Uri.TryCreate(param, UriKind.Absolute, out uri)) { link.NavigateUri = uri; } span = link; break; case InlineType.Bold: span = new Bold(); break; case InlineType.Italic: span = new Italic(); break; case InlineType.Underline: span = new Underline(); break; default: span = new Span(); break; } return(span); }
protected abstract TInline CreateInline(InlineType inlineType, Tag tag);
private static Span CreateSpan(InlineType inlineType, string param) { Span span = null; switch (inlineType) { case InlineType.Hyperlink: Hyperlink link = new Hyperlink(); Uri uri; if (Uri.TryCreate(param, UriKind.Absolute, out uri)) { link.NavigateUri = uri; } span = link; break; case InlineType.Bold: span = new Bold(); break; case InlineType.Italic: span = new Italic(); break; case InlineType.Underline: span = new Underline(); break; default: span = new Span(); break; } return span; }
public Fragment(InlineType inlineType, string content) : this(inlineType, content, SegmentationHint.Undefined, false) { }
public void InsertInline(InlineType inline) { switch (inline) { case InlineType.TextRun: this.TextBox.CaretPosition.InsertTextInRun(string.Empty); break; } }
public TagMatch(InlineType inlineType, Match match, MatchRule matchRule) { _match = match; InlineType = inlineType; MatchRule = matchRule; }
/// <summary> /// Converts a value. /// </summary> /// <param name="value">The value produced by the GTMT#binding source.</param> /// <param name="targetType">The type of the GTMT#binding target property.</param> /// <param name="parameter">The converter parameter to use.</param> /// <param name="culture">The culture to use in the converter.</param> /// <returns> /// A converted value. If the method returns null, the valid null value is used. /// </returns> public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string source = (string)value; if (string.IsNullOrEmpty(source)) { return(Binding.DoNothing); } List <Inline> inlines = new List <Inline>(); string[] lines = source.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) { StringBuilder sb = new StringBuilder(); Span parentSpan = new Span(); for (int i = 0; i < line.Length; ++i) { var current = line[i]; var next = (i + 1 < line.Length) ? line[i + 1] : (char?)null; if (current == '[' && next != '[') { string text = sb.ToString(); sb = new StringBuilder(); i += (next == '/') ? 2 : 1; current = line[i]; while (i < line.Length && current != ']') { sb.Append(current); ++i; if (i < line.Length) { current = line[i]; } } if (text.Length > 0) { parentSpan.Inlines.Add(text); } if (next == '/' && parentSpan.Parent != null) { parentSpan = (Span)parentSpan.Parent; } else { string[] tag = sb.ToString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (tag.Length > 0) { InlineType inlineType = GetInlineType(tag[0].TrimEnd('/')); if (inlineType == InlineType.LineBreak) { parentSpan.Inlines.Add(new LineBreak()); } else if (inlineType != InlineType.Run) { string tagParam = (tag.Length > 1) ? tag[1] : null; Span newParentSpan = CreateSpan(inlineType, tagParam); parentSpan.Inlines.Add(newParentSpan); parentSpan = newParentSpan; } } } sb = new StringBuilder(); } else { if (current == '[' && next == '[') { ++i; } sb.Append(current); } } if (sb.Length > 0) { parentSpan.Inlines.Add(sb.ToString()); } inlines.Add(parentSpan); inlines.Add(new LineBreak()); } return(inlines.ToArray()); }
protected override Inline CreateInline(InlineType inlineType, Tag tag) { Inline inline = null; switch (inlineType) { case InlineType.Bold: inline = new Bold(); break; case InlineType.Italic: inline = new Italic(); break; case InlineType.StrikeThrough: inline = new Span { Foreground = VisualParameters.PhoneDisabledBrush }; break; case InlineType.Underline: inline = new Underline(); break; case InlineType.Hyperlink: { Uri uri = null; if (Uri.TryCreate(tag.Value, UriKind.Absolute, out uri)) { inline = new Hyperlink { NavigateUri = uri, Foreground = VisualParameters.PhoneAccentBrush }; } } break; case InlineType.Image: inline = CreateImageInline(tag); break; case InlineType.PhoneNumber: inline = new Span(); break; case InlineType.Command: { var commandContent = tag.ToString(); if (String.IsNullOrWhiteSpace(commandContent)) { commandContent = tag.Value; } Uri uri = null; if (Uri.TryCreate(tag.Value, UriKind.Absolute, out uri)) { inline = new InlineUIContainer { Child = new HyperlinkButton { Content = commandContent, Command = this.control.Command, CommandParameter = uri, Style = this.control.HyperlinkButtonStyle, Foreground = VisualParameters.ThemeBrandBrush } }; } } break; case InlineType.Code: inline = new Span { FontFamily = VisualParameters.CodeFontFamily, }; break; default: break; } if (inline == null) { inline = new Span(); } return(inline); }