Skip to content

Commit 255721c

Browse files
author
Juan Osorio
committed
Move properties to their own file, add comments, add hardline break support
1 parent 17ee6d6 commit 255721c

File tree

3 files changed

+183
-122
lines changed

3 files changed

+183
-122
lines changed
Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
2-
<Page
3-
x:Class="MarkdownTextBlockExperiment.Samples.MarkdownTextBlockCustomSample"
4-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6-
xmlns:controls="using:CommunityToolkit.Labs.WinUI.MarkdownTextBlock"
7-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8-
xmlns:local="using:MarkdownTextBlockExperiment.Samples"
9-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10-
mc:Ignorable="d">
2+
<Page x:Class="MarkdownTextBlockExperiment.Samples.MarkdownTextBlockCustomSample"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:controls="using:CommunityToolkit.Labs.WinUI.MarkdownTextBlock"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="using:MarkdownTextBlockExperiment.Samples"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d">
1110

1211
<Grid>
1312
<Grid.RowDefinitions>
@@ -16,40 +15,35 @@
1615
<RowDefinition Height="auto" />
1716
<RowDefinition Height="auto" />
1817
</Grid.RowDefinitions>
19-
<TextBlock
20-
Grid.Row="0"
21-
Margin="0,0,0,12"
22-
FontSize="16"
23-
FontWeight="Bold"
24-
Text="Try it live!" />
18+
<TextBlock Grid.Row="0"
19+
Margin="0,0,0,12"
20+
FontSize="16"
21+
FontWeight="Bold"
22+
Text="Try it live!" />
2523
<Grid Grid.Row="1">
2624
<Grid.ColumnDefinitions>
2725
<ColumnDefinition Width="*" />
2826
<ColumnDefinition Width="*" />
2927
</Grid.ColumnDefinitions>
30-
<controls:MarkdownTextBlock
31-
Grid.Column="0"
32-
Config="{x:Bind LiveMarkdownConfig, Mode=OneTime}"
33-
Text="{x:Bind MarkdownTextBox.Text, Mode=OneWay}" />
34-
<TextBox
35-
x:Name="MarkdownTextBox"
36-
Grid.Column="1"
37-
AcceptsReturn="True" />
28+
<controls:MarkdownTextBlock Grid.Column="0"
29+
Config="{x:Bind LiveMarkdownConfig, Mode=OneTime}"
30+
Text="{x:Bind MarkdownTextBox.Text, Mode=OneWay}" />
31+
<TextBox x:Name="MarkdownTextBox"
32+
Grid.Column="1"
33+
AcceptsReturn="True" />
3834
</Grid>
39-
<TextBlock
40-
Grid.Row="2"
41-
Margin="0,0,0,12"
42-
FontSize="16"
43-
FontWeight="Bold"
44-
Text="Built-in Sample" />
45-
<controls:MarkdownTextBlock
46-
Grid.Row="3"
47-
Config="{x:Bind MarkdownConfig, Mode=OneTime}"
48-
Text="{x:Bind Text, Mode=OneTime}"
49-
UseAutoLinks="True"
50-
UseEmphasisExtras="True"
51-
UseListExtras="True"
52-
UsePipeTables="True"
53-
UseTaskLists="True" />
35+
<TextBlock Grid.Row="2"
36+
Margin="0,0,0,12"
37+
FontSize="16"
38+
FontWeight="Bold"
39+
Text="Built-in Sample" />
40+
<controls:MarkdownTextBlock Grid.Row="3"
41+
Config="{x:Bind MarkdownConfig, Mode=OneTime}"
42+
Text="{x:Bind Text, Mode=OneTime}"
43+
UseAutoLinks="True"
44+
UseEmphasisExtras="True"
45+
UseListExtras="True"
46+
UsePipeTables="True"
47+
UseTaskLists="True" />
5448
</Grid>
5549
</Page>
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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+
namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock;
6+
7+
public partial class MarkdownTextBlock
8+
{
9+
/// <summary>
10+
/// Identifies the <see cref="Config"/> dependency property.
11+
/// </summary>
12+
private static readonly DependencyProperty ConfigProperty = DependencyProperty.Register(
13+
nameof(Config),
14+
typeof(MarkdownConfig),
15+
typeof(MarkdownTextBlock),
16+
new PropertyMetadata(null, OnConfigChanged)
17+
);
18+
19+
/// <summary>
20+
/// Identifies the <see cref="Text"/> dependency property.
21+
/// </summary>
22+
private static readonly DependencyProperty TextProperty = DependencyProperty.Register(
23+
nameof(Text),
24+
typeof(string),
25+
typeof(MarkdownTextBlock),
26+
new PropertyMetadata(null, OnTextChanged));
27+
28+
/// <summary>
29+
/// Identifies the <see cref="UseEmphasisExtras"/> dependency property.
30+
/// </summary>
31+
private static readonly DependencyProperty UseEmphasisExtrasProperty = DependencyProperty.Register(
32+
nameof(UseEmphasisExtras),
33+
typeof(bool),
34+
typeof(MarkdownTextBlock),
35+
new PropertyMetadata(false));
36+
37+
/// <summary>
38+
/// Identifies the <see cref="UsePipeTables"/> dependency property.
39+
/// </summary>
40+
private static readonly DependencyProperty UsePipeTablesProperty = DependencyProperty.Register(
41+
nameof(UsePipeTables),
42+
typeof(bool),
43+
typeof(MarkdownTextBlock),
44+
new PropertyMetadata(false));
45+
46+
/// <summary>
47+
/// Identifies the <see cref="UseListExtras"/> dependency property.
48+
/// </summary>
49+
private static readonly DependencyProperty UseListExtrasProperty = DependencyProperty.Register(
50+
nameof(UseListExtras),
51+
typeof(bool),
52+
typeof(MarkdownTextBlock),
53+
new PropertyMetadata(false));
54+
55+
/// <summary>
56+
/// Identifies the <see cref="UseTaskLists"/> dependency property.
57+
/// </summary>
58+
private static readonly DependencyProperty UseTaskListsProperty = DependencyProperty.Register(
59+
nameof(UseTaskLists),
60+
typeof(bool),
61+
typeof(MarkdownTextBlock),
62+
new PropertyMetadata(false));
63+
64+
/// <summary>
65+
/// Identifies the <see cref="UseAutoLinks"/> dependency property.
66+
/// </summary>
67+
private static readonly DependencyProperty UseAutoLinksProperty = DependencyProperty.Register(
68+
nameof(UseAutoLinks),
69+
typeof(bool),
70+
typeof(MarkdownTextBlock),
71+
new PropertyMetadata(false));
72+
73+
/// <summary>
74+
/// Identifies the <see cref="UseSoftlineBreakAsHardlineBreak"/> dependency property.
75+
/// </summary>
76+
private static readonly DependencyProperty UseSoftlineBreakAsHardlineBreakProperty = DependencyProperty.Register(
77+
nameof(UseSoftlineBreakAsHardlineBreak),
78+
typeof(bool),
79+
typeof(MarkdownTextBlock),
80+
new PropertyMetadata(false));
81+
82+
public MarkdownConfig Config
83+
{
84+
get => (MarkdownConfig)GetValue(ConfigProperty);
85+
set => SetValue(ConfigProperty, value);
86+
}
87+
88+
/// <summary>
89+
/// Gets or sets the markdown text to display.
90+
/// </summary>
91+
public string Text
92+
{
93+
get => (string)GetValue(TextProperty);
94+
set => SetValue(TextProperty, value);
95+
}
96+
97+
/// <summary>
98+
/// If true, adds support for strikethroughs, superscript, subscript, inserted, and marked text.
99+
/// </summary>
100+
public bool UseEmphasisExtras
101+
{
102+
get => (bool)GetValue(UseEmphasisExtrasProperty);
103+
set => SetValue(UseEmphasisExtrasProperty, value);
104+
}
105+
106+
/// <summary>
107+
/// If true, adds support for GitHub-style pipe tables.
108+
/// </summary>
109+
public bool UsePipeTables
110+
{
111+
get => (bool)GetValue(UsePipeTablesProperty);
112+
set => SetValue(UsePipeTablesProperty, value);
113+
}
114+
115+
/// <summary>
116+
/// If true, adds support for alphabetic and roman numbering in lists.
117+
/// </summary>
118+
public bool UseListExtras
119+
{
120+
get => (bool)GetValue(UseListExtrasProperty);
121+
set => SetValue(UseListExtrasProperty, value);
122+
}
123+
124+
/// <summary>
125+
/// If true, adds support for GitHub-style task lists using the [ ] and [x] syntax.
126+
/// </summary>
127+
public bool UseTaskLists
128+
{
129+
get => (bool)GetValue(UseTaskListsProperty);
130+
set => SetValue(UseTaskListsProperty, value);
131+
}
132+
133+
/// <summary>
134+
/// If true, parses text that looks like URIs into hyperlinks (e.g. https://...).
135+
/// </summary>
136+
public bool UseAutoLinks
137+
{
138+
get => (bool)GetValue(UseAutoLinksProperty);
139+
set => SetValue(UseAutoLinksProperty, value);
140+
}
141+
142+
/// <summary>
143+
/// If true, considers single newlines as hardline breaks.
144+
/// </summary>
145+
public bool UseSoftlineBreakAsHardlineBreak
146+
{
147+
get => (bool)GetValue(UseSoftlineBreakAsHardlineBreakProperty);
148+
set => SetValue(UseSoftlineBreakAsHardlineBreakProperty, value);
149+
}
150+
}

components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -20,90 +20,6 @@ public partial class MarkdownTextBlock : Control
2020
private MyFlowDocument _document;
2121
private WinUIRenderer? _renderer;
2222

23-
private static readonly DependencyProperty ConfigProperty = DependencyProperty.Register(
24-
nameof(Config),
25-
typeof(MarkdownConfig),
26-
typeof(MarkdownTextBlock),
27-
new PropertyMetadata(null, OnConfigChanged)
28-
);
29-
30-
private static readonly DependencyProperty TextProperty = DependencyProperty.Register(
31-
nameof(Text),
32-
typeof(string),
33-
typeof(MarkdownTextBlock),
34-
new PropertyMetadata(null, OnTextChanged));
35-
36-
public MarkdownConfig Config
37-
{
38-
get => (MarkdownConfig)GetValue(ConfigProperty);
39-
set => SetValue(ConfigProperty, value);
40-
}
41-
42-
public string Text
43-
{
44-
get => (string)GetValue(TextProperty);
45-
set => SetValue(TextProperty, value);
46-
}
47-
48-
#region Built in Extensions
49-
50-
private static readonly DependencyProperty UseEmphasisExtrasProperty = DependencyProperty.Register(
51-
nameof(UseEmphasisExtras),
52-
typeof(bool),
53-
typeof(MarkdownTextBlock),
54-
new PropertyMetadata(false));
55-
public bool UseEmphasisExtras
56-
{
57-
get => (bool)GetValue(UseEmphasisExtrasProperty);
58-
set => SetValue(UseEmphasisExtrasProperty, value);
59-
}
60-
61-
private static readonly DependencyProperty UsePipeTablesProperty = DependencyProperty.Register(
62-
nameof(UsePipeTables),
63-
typeof(bool),
64-
typeof(MarkdownTextBlock),
65-
new PropertyMetadata(false));
66-
public bool UsePipeTables
67-
{
68-
get => (bool)GetValue(UsePipeTablesProperty);
69-
set => SetValue(UsePipeTablesProperty, value);
70-
}
71-
72-
private static readonly DependencyProperty UseListExtrasProperty = DependencyProperty.Register(
73-
nameof(UseListExtras),
74-
typeof(bool),
75-
typeof(MarkdownTextBlock),
76-
new PropertyMetadata(false));
77-
public bool UseListExtras
78-
{
79-
get => (bool)GetValue(UseListExtrasProperty);
80-
set => SetValue(UseListExtrasProperty, value);
81-
}
82-
83-
private static readonly DependencyProperty UseTaskListsProperty = DependencyProperty.Register(
84-
nameof(UseTaskLists),
85-
typeof(bool),
86-
typeof(MarkdownTextBlock),
87-
new PropertyMetadata(false));
88-
public bool UseTaskLists
89-
{
90-
get => (bool)GetValue(UseTaskListsProperty);
91-
set => SetValue(UseTaskListsProperty, value);
92-
}
93-
94-
private static readonly DependencyProperty UseAutoLinksProperty = DependencyProperty.Register(
95-
nameof(UseAutoLinks),
96-
typeof(bool),
97-
typeof(MarkdownTextBlock),
98-
new PropertyMetadata(false));
99-
public bool UseAutoLinks
100-
{
101-
get => (bool)GetValue(UseAutoLinksProperty);
102-
set => SetValue(UseAutoLinksProperty, value);
103-
}
104-
105-
#endregion
106-
10723
private static void OnConfigChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
10824
{
10925
if (d is MarkdownTextBlock self && e.NewValue != null)
@@ -138,6 +54,7 @@ protected override void OnApplyTemplate()
13854
if (UseListExtras) pipelineBuilder = pipelineBuilder.UseListExtras();
13955
if (UseTaskLists) pipelineBuilder = pipelineBuilder.UseTaskLists();
14056
if (UseAutoLinks) pipelineBuilder = pipelineBuilder.UseAutoLinks();
57+
if (UseSoftlineBreakAsHardlineBreak) pipelineBuilder = pipelineBuilder.UseSoftlineBreakAsHardlineBreak();
14158

14259
_pipeline = pipelineBuilder.Build();
14360

0 commit comments

Comments
 (0)