|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using Markdig.Syntax; |
| 6 | + |
| 7 | +namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock; |
| 8 | + |
| 9 | +public partial class MarkdownTextBlock |
| 10 | +{ |
| 11 | + /// <summary> |
| 12 | + /// Identifies the <see cref="Config"/> dependency property. |
| 13 | + /// </summary> |
| 14 | + private static readonly DependencyProperty ConfigProperty = DependencyProperty.Register( |
| 15 | + nameof(Config), |
| 16 | + typeof(MarkdownConfig), |
| 17 | + typeof(MarkdownTextBlock), |
| 18 | + new PropertyMetadata(null, OnConfigChanged) |
| 19 | + ); |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Identifies the <see cref="Text"/> dependency property. |
| 23 | + /// </summary> |
| 24 | + private static readonly DependencyProperty TextProperty = DependencyProperty.Register( |
| 25 | + nameof(Text), |
| 26 | + typeof(string), |
| 27 | + typeof(MarkdownTextBlock), |
| 28 | + new PropertyMetadata(null, OnTextChanged)); |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// Identifies the <see cref="UseEmphasisExtras"/> dependency property. |
| 32 | + /// </summary> |
| 33 | + private static readonly DependencyProperty UseEmphasisExtrasProperty = DependencyProperty.Register( |
| 34 | + nameof(UseEmphasisExtras), |
| 35 | + typeof(bool), |
| 36 | + typeof(MarkdownTextBlock), |
| 37 | + new PropertyMetadata(false)); |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Identifies the <see cref="UsePipeTables"/> dependency property. |
| 41 | + /// </summary> |
| 42 | + private static readonly DependencyProperty UsePipeTablesProperty = DependencyProperty.Register( |
| 43 | + nameof(UsePipeTables), |
| 44 | + typeof(bool), |
| 45 | + typeof(MarkdownTextBlock), |
| 46 | + new PropertyMetadata(false)); |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Identifies the <see cref="UseListExtras"/> dependency property. |
| 50 | + /// </summary> |
| 51 | + private static readonly DependencyProperty UseListExtrasProperty = DependencyProperty.Register( |
| 52 | + nameof(UseListExtras), |
| 53 | + typeof(bool), |
| 54 | + typeof(MarkdownTextBlock), |
| 55 | + new PropertyMetadata(false)); |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// Identifies the <see cref="UseTaskLists"/> dependency property. |
| 59 | + /// </summary> |
| 60 | + private static readonly DependencyProperty UseTaskListsProperty = DependencyProperty.Register( |
| 61 | + nameof(UseTaskLists), |
| 62 | + typeof(bool), |
| 63 | + typeof(MarkdownTextBlock), |
| 64 | + new PropertyMetadata(false)); |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Identifies the <see cref="UseAutoLinks"/> dependency property. |
| 68 | + /// </summary> |
| 69 | + private static readonly DependencyProperty UseAutoLinksProperty = DependencyProperty.Register( |
| 70 | + nameof(UseAutoLinks), |
| 71 | + typeof(bool), |
| 72 | + typeof(MarkdownTextBlock), |
| 73 | + new PropertyMetadata(false)); |
| 74 | + |
| 75 | + /// <summary> |
| 76 | + /// Identifies the <see cref="UseSoftlineBreakAsHardlineBreak"/> dependency property. |
| 77 | + /// </summary> |
| 78 | + private static readonly DependencyProperty UseSoftlineBreakAsHardlineBreakProperty = DependencyProperty.Register( |
| 79 | + nameof(UseSoftlineBreakAsHardlineBreak), |
| 80 | + typeof(bool), |
| 81 | + typeof(MarkdownTextBlock), |
| 82 | + new PropertyMetadata(false)); |
| 83 | + |
| 84 | + /// <summary> |
| 85 | + /// Identifies the <see cref="MarkdownDocument"/> dependency property. |
| 86 | + /// </summary> |
| 87 | + private static readonly DependencyProperty MarkdownDocumentProperty = DependencyProperty.Register( |
| 88 | + nameof(MarkdownDocument), |
| 89 | + typeof(MarkdownDocument), |
| 90 | + typeof(MarkdownTextBlock), |
| 91 | + new PropertyMetadata(null)); |
| 92 | + |
| 93 | + public MarkdownConfig Config |
| 94 | + { |
| 95 | + get => (MarkdownConfig)GetValue(ConfigProperty); |
| 96 | + set => SetValue(ConfigProperty, value); |
| 97 | + } |
| 98 | + |
| 99 | + /// <summary> |
| 100 | + /// Gets or sets the markdown text to display. |
| 101 | + /// </summary> |
| 102 | + public string Text |
| 103 | + { |
| 104 | + get => (string)GetValue(TextProperty); |
| 105 | + set => SetValue(TextProperty, value); |
| 106 | + } |
| 107 | + |
| 108 | + /// <summary> |
| 109 | + /// If true, adds support for strikethroughs, superscript, subscript, inserted, and marked text. |
| 110 | + /// </summary> |
| 111 | + public bool UseEmphasisExtras |
| 112 | + { |
| 113 | + get => (bool)GetValue(UseEmphasisExtrasProperty); |
| 114 | + set => SetValue(UseEmphasisExtrasProperty, value); |
| 115 | + } |
| 116 | + |
| 117 | + /// <summary> |
| 118 | + /// If true, adds support for GitHub-style pipe tables. |
| 119 | + /// </summary> |
| 120 | + public bool UsePipeTables |
| 121 | + { |
| 122 | + get => (bool)GetValue(UsePipeTablesProperty); |
| 123 | + set => SetValue(UsePipeTablesProperty, value); |
| 124 | + } |
| 125 | + |
| 126 | + /// <summary> |
| 127 | + /// If true, adds support for alphabetic and roman numbering in lists. |
| 128 | + /// </summary> |
| 129 | + public bool UseListExtras |
| 130 | + { |
| 131 | + get => (bool)GetValue(UseListExtrasProperty); |
| 132 | + set => SetValue(UseListExtrasProperty, value); |
| 133 | + } |
| 134 | + |
| 135 | + /// <summary> |
| 136 | + /// If true, adds support for GitHub-style task lists using the [ ] and [x] syntax. |
| 137 | + /// </summary> |
| 138 | + public bool UseTaskLists |
| 139 | + { |
| 140 | + get => (bool)GetValue(UseTaskListsProperty); |
| 141 | + set => SetValue(UseTaskListsProperty, value); |
| 142 | + } |
| 143 | + |
| 144 | + /// <summary> |
| 145 | + /// If true, parses text that looks like URIs into hyperlinks (e.g. https://...). |
| 146 | + /// </summary> |
| 147 | + public bool UseAutoLinks |
| 148 | + { |
| 149 | + get => (bool)GetValue(UseAutoLinksProperty); |
| 150 | + set => SetValue(UseAutoLinksProperty, value); |
| 151 | + } |
| 152 | + |
| 153 | + /// <summary> |
| 154 | + /// If true, considers single newlines as hardline breaks. |
| 155 | + /// </summary> |
| 156 | + public bool UseSoftlineBreakAsHardlineBreak |
| 157 | + { |
| 158 | + get => (bool)GetValue(UseSoftlineBreakAsHardlineBreakProperty); |
| 159 | + set => SetValue(UseSoftlineBreakAsHardlineBreakProperty, value); |
| 160 | + } |
| 161 | + |
| 162 | + /// <summary> |
| 163 | + /// Gets the parsed markdown document. May be null if the document has not been parsed yet. |
| 164 | + /// </summary> |
| 165 | + public MarkdownDocument? MarkdownDocument |
| 166 | + { |
| 167 | + get => (MarkdownDocument)GetValue(MarkdownDocumentProperty); |
| 168 | + private set => SetValue(MarkdownDocumentProperty, value); |
| 169 | + } |
| 170 | +} |
0 commit comments