Skip to content

Commit 5de5ceb

Browse files
azchohfimichael-hawker
authored andcommitted
Added header margins.
1 parent b41d8f0 commit 5de5ceb

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

components/MarkdownTextBlock/src/MarkdownThemes.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ public sealed class MarkdownThemes : DependencyObject
4949

5050
public FontWeight H6FontWeight { get; set; } = FontWeights.Normal;
5151

52+
public Thickness H1Margin { get; set; } = new(0);
53+
public Thickness H2Margin { get; set; } = new(0);
54+
public Thickness H3Margin { get; set; } = new(0);
55+
public Thickness H4Margin { get; set; } = new(0);
56+
public Thickness H5Margin { get; set; } = new(0);
57+
public Thickness H6Margin { get; set; } = new(0);
58+
5259
public Brush InlineCodeBackground { get; set; } = (Brush)Application.Current.Resources["ExpanderHeaderBackground"];
5360
public Brush InlineCodeForeground { get; set; } = (Brush)Application.Current.Resources["TextFillColorPrimaryBrush"];
5461

components/MarkdownTextBlock/src/TextElements/MyHeading.cs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,7 @@ public MyHeading(HeadingBlock headingBlock, MarkdownConfig config)
2727
_paragraph = new Paragraph();
2828
_config = config;
2929

30-
var level = headingBlock.Level;
31-
_paragraph.FontSize = level switch
32-
{
33-
1 => _config.Themes.H1FontSize,
34-
2 => _config.Themes.H2FontSize,
35-
3 => _config.Themes.H3FontSize,
36-
4 => _config.Themes.H4FontSize,
37-
5 => _config.Themes.H5FontSize,
38-
_ => _config.Themes.H6FontSize,
39-
};
40-
_paragraph.Foreground = _config.Themes.HeadingForeground;
41-
_paragraph.FontWeight = level switch
42-
{
43-
1 => _config.Themes.H1FontWeight,
44-
2 => _config.Themes.H2FontWeight,
45-
3 => _config.Themes.H3FontWeight,
46-
4 => _config.Themes.H4FontWeight,
47-
5 => _config.Themes.H5FontWeight,
48-
_ => _config.Themes.H6FontWeight,
49-
};
30+
SetHProperties(headingBlock.Level);
5031
}
5132

5233
public MyHeading(HtmlNode htmlNode, MarkdownConfig config)
@@ -65,7 +46,11 @@ public MyHeading(HtmlNode htmlNode, MarkdownConfig config)
6546
_ => TextAlignment.Left,
6647
};
6748

68-
var level = int.Parse(htmlNode.Name.Substring(1));
49+
SetHProperties(int.Parse(htmlNode.Name.Substring(1)));
50+
}
51+
52+
private void SetHProperties(int level)
53+
{
6954
_paragraph.FontSize = level switch
7055
{
7156
1 => _config.Themes.H1FontSize,
@@ -85,6 +70,15 @@ public MyHeading(HtmlNode htmlNode, MarkdownConfig config)
8570
5 => _config.Themes.H5FontWeight,
8671
_ => _config.Themes.H6FontWeight,
8772
};
73+
_paragraph.Margin = level switch
74+
{
75+
1 => _config.Themes.H1Margin,
76+
2 => _config.Themes.H2Margin,
77+
3 => _config.Themes.H3Margin,
78+
4 => _config.Themes.H4Margin,
79+
5 => _config.Themes.H5Margin,
80+
_ => _config.Themes.H6Margin,
81+
};
8882
}
8983

9084
public void AddChild(IAddChild child)

0 commit comments

Comments
 (0)