diff --git a/MdXaml/Markdown.cs b/MdXaml/Markdown.cs index 6da980b..14256d2 100644 --- a/MdXaml/Markdown.cs +++ b/MdXaml/Markdown.cs @@ -77,6 +77,8 @@ public class Markdown : DependencyObject, IMarkdown, IUriContext public bool DisabledContextMenu { get; set; } + public bool UseSoftlineBreakAsHardlineBreak { get; set; } + public string? AssetPathRoot { get; set; } public ICommand? HyperlinkCommand { get; set; } @@ -2079,8 +2081,9 @@ private Inline UnderlineEvaluator(Match match) private static readonly Regex _eoln = new("\\s+"); private static readonly Regex _lbrk = new(@"\ {2,}\n"); - public static IEnumerable DoText(string text) + public IEnumerable DoText(string text) { + text = UseSoftlineBreakAsHardlineBreak ? text.Replace("\n", " \n") : text; var lines = _lbrk.Split(text); bool first = true; foreach (var line in lines) diff --git a/MdXaml/MarkdownScrollViewer.cs b/MdXaml/MarkdownScrollViewer.cs index cc54369..4ba007b 100644 --- a/MdXaml/MarkdownScrollViewer.cs +++ b/MdXaml/MarkdownScrollViewer.cs @@ -78,6 +78,12 @@ public class MarkdownScrollViewer : FlowDocumentScrollViewer, IUriContext typeof(MarkdownScrollViewer), new PropertyMetadata(false, UpdateDisabledLazyLoad)); + public static readonly DependencyProperty UseSoftlineBreakAsHardlineBreakProperty = + DependencyProperty.Register( + nameof(UseSoftlineBreakAsHardlineBreak), + typeof(bool), + typeof(MarkdownScrollViewer), + new PropertyMetadata(false, UpdateUseSoftlineBreakAsHardlineBreak)); private static void UpdateSource(DependencyObject d, DependencyPropertyChangedEventArgs e) { @@ -181,6 +187,17 @@ private static void UpdateDisabledLazyLoad(DependencyObject d, DependencyPropert } } } + private static void UpdateUseSoftlineBreakAsHardlineBreak(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if(d is MarkdownScrollViewer owner) + { + var useSoftlineBreakAsHardlineBreak = (bool)e.NewValue; + if (useSoftlineBreakAsHardlineBreak != owner.Engine.UseSoftlineBreakAsHardlineBreak) + { + owner.Engine.UseSoftlineBreakAsHardlineBreak = (bool)e.NewValue; + } + } + } private string _fragment; private Uri _source; @@ -341,6 +358,11 @@ public string Fragment get { return (string)GetValue(FragmentProperty); } set { SetValue(FragmentProperty, value); } } + public bool UseSoftlineBreakAsHardlineBreak + { + get { return (bool)GetValue(UseSoftlineBreakAsHardlineBreakProperty); } + set { SetValue(UseSoftlineBreakAsHardlineBreakProperty, value); } + } private ClickAction _clickAction; public ClickAction ClickAction