From 1f5b27974493af3cb6d9ea217fb5720b4c931a79 Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Thu, 17 Dec 2015 18:34:08 +0100 Subject: [PATCH] Fixes a bug/crash when a fenced code block starts with an empty line - Fixes the bug (only remove the line-ending character when FSharp.Formatting commands are found). - Upgrades some missing projects to net45 (because the bugfix contains logging which is in FSharp.Formatting.Common, which in itself is build for net45) --- src/Common/StringParsing.fs | 20 ++++++ .../FSharp.CodeFormat.fsproj | 7 ++ src/FSharp.Literate/Transformations.fs | 10 +-- src/FSharp.Markdown/FSharp.Markdown.fsproj | 11 +++- tests/FSharp.Literate.Tests/Tests.fs | 41 ++++++++++++ tests/FSharp.Markdown.Tests/App.config | 66 +++++++++---------- .../FSharp.Markdown.Tests.fsproj | 2 +- 7 files changed, 114 insertions(+), 43 deletions(-) diff --git a/src/Common/StringParsing.fs b/src/Common/StringParsing.fs index a4e8d67f7..baedfc451 100644 --- a/src/Common/StringParsing.fs +++ b/src/Common/StringParsing.fs @@ -78,6 +78,26 @@ module String = if n = 0 || n % repeated.Length <> 0 then None else Some(n/repeated.Length, text.Substring(n, text.Length - n)) + /// Ignores everything until a end-line character is detected, returns the remaining string. + let (|SkipSingleLine|) (text:string) = + let rec tryEol eolList = + match eolList with + | h : string :: t -> + match text.IndexOf(h) with + | i when i < 0 -> tryEol t + | i -> + text.Substring (i + h.Length) + | _ -> + text + let result = tryEol [ "\r\n"; "\n" ] + let skipped = text.Substring(0, text.Length - result.Length) + if not <| String.IsNullOrWhiteSpace(skipped) then + FSharp.Formatting.Common.Log.warnf "skipped '%s' which contains non-whitespace character!" skipped + if result = text then + FSharp.Formatting.Common.Log.warnf "could not skip a line of %s, because no line-ending character was found!" text + result + + /// Matches when a string starts with a sub-string wrapped using the /// opening and closing sub-string specified in the parameter. /// For example "[aa]bc" is wrapped in [ and ] pair. Returns the wrapped diff --git a/src/FSharp.CodeFormat/FSharp.CodeFormat.fsproj b/src/FSharp.CodeFormat/FSharp.CodeFormat.fsproj index 3f20618a5..6b89954cf 100644 --- a/src/FSharp.CodeFormat/FSharp.CodeFormat.fsproj +++ b/src/FSharp.CodeFormat/FSharp.CodeFormat.fsproj @@ -93,6 +93,13 @@ + + + FSharp.Formatting.Common + {91bad90e-bf3b-4646-a1a7-1568f8f25075} + True + +