Skip to content

Commit

Permalink
#764 Fix link translation when using relative input path
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyme committed Aug 30, 2022
1 parent 31950ff commit dc1da31
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 5 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 16.0.3
* [Fix link translation when using relative input path](https://github.com/fsprojects/FSharp.Formatting/issues/764)

## 16.0.2
* [Improves markdown emphasis parsing.](https://github.com/fsprojects/FSharp.Formatting/pull/763)

Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Formatting.CodeFormat/CommentFilter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// F# CodeFormat (CommentProcessing.fs)
// (c) Tomas Petricek, 2012, Available under Apache 2.0 license.
// --------------------------------------------------------------------------------------
module private FSharp.Formatting.CodeFormat.CommentFilter
module internal FSharp.Formatting.CodeFormat.CommentFilter

open System.Text
open FSharp.Patterns
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Formatting.CodeFormat/ToolTipReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// F# CodeFormat (ToolTipReader.fs)
// (c) Tomas Petricek, 2012, Available under Apache 2.0 license.
// --------------------------------------------------------------------------------------
module private FSharp.Formatting.CodeFormat.ToolTipReader
module internal FSharp.Formatting.CodeFormat.ToolTipReader

open System
open System.IO
Expand Down
2 changes: 1 addition & 1 deletion src/fsdocs-tool/BuildCommand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type internal DocContent
=
let markdownReferenceAsFullInputPathOpt =
try
Path.GetFullPath(markdownReference, inputFolderAsGiven) |> Some
Path.GetFullPath(Path.Combine(inputFolderAsGiven, markdownReference)) |> Some
with _ ->
None

Expand Down
99 changes: 97 additions & 2 deletions tests/FSharp.Literate.Tests/DocContentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,119 @@ let ``Can build doc content`` () =
action globals

// Check simple1.fsx --> simple1.html substititions
// Check simple2.md --> simple2.html substititions
let html1 = File.ReadAllText(rootOutputFolderAsGiven </> "simple1.html")
let html2 = File.ReadAllText(rootOutputFolderAsGiven </> "simple2.html")
html1 |> shouldContainText "simple2.html"
html2 |> shouldContainText "simple1.html"
html1 |> shouldContainText """href="simple1.html">"""
html1 |> shouldContainText """href="simple2.html">"""
html2 |> shouldContainText """href="simple1.html">"""
html2 |> shouldContainText """href="simple2.html">"""

// Check simple1.fsx --> simple1.ipynb substititions
// Check simple2.md --> simple1.ipynb substititions
let ipynb1 = File.ReadAllText(rootOutputFolderAsGiven </> "simple1.ipynb")
let ipynb2 = File.ReadAllText(rootOutputFolderAsGiven </> "simple2.ipynb")
ipynb1 |> shouldContainText "simple2.ipynb"
ipynb2 |> shouldContainText "simple1.ipynb"

// Check fsx exists
// Check simple1.fsx --> simple1.fsx substititions
// Check simple2.md --> simple1.fsx substititions
let fsx1 = File.ReadAllText(rootOutputFolderAsGiven </> "simple1.fsx")
let fsx2 = File.ReadAllText(rootOutputFolderAsGiven </> "simple2.fsx")
fsx1 |> shouldContainText "simple2.fsx"
fsx2 |> shouldContainText "simple1.fsx"

// Check md contents
// Check simple1.fsx --> simple1.md substititions
// Check simple2.md --> simple1.md substititions
let md1 = File.ReadAllText(rootOutputFolderAsGiven </> "simple1.md")
let md2 = File.ReadAllText(rootOutputFolderAsGiven </> "simple2.md")
md1 |> shouldContainText "simple2.md"
md2 |> shouldContainText "simple1.md"


// Check in-folder1.fsx --> in-folder1.html substititions
let f1html1 = File.ReadAllText(rootOutputFolderAsGiven </> "folder1" </> "in-folder1.html")
let f2html2 = File.ReadAllText(rootOutputFolderAsGiven </> "folder2" </> "in-folder2.html")
f1html1 |> shouldContainText """href="../folder2/in-folder2.html">"""
f2html2 |> shouldContainText """href="../folder1/in-folder1.html">"""

// Check in-folder1.fsx --> in-folder1.ipynb substititions
let f1ipynb1 = File.ReadAllText(rootOutputFolderAsGiven </> "folder1" </> "in-folder1.ipynb")
let f2ipynb2 = File.ReadAllText(rootOutputFolderAsGiven </> "folder2" </> "in-folder2.ipynb")
f1ipynb1 |> shouldContainText """../folder2/in-folder2.ipynb"""
f2ipynb2 |> shouldContainText """../folder1/in-folder1.ipynb"""

// Check fsx exists
let f1fsx1 = File.ReadAllText(rootOutputFolderAsGiven </> "folder1" </> "in-folder1.fsx")
let f2fsx2 = File.ReadAllText(rootOutputFolderAsGiven </> "folder2" </> "in-folder2.fsx")
f1fsx1 |> shouldContainText """../folder2/in-folder2.fsx"""
f2fsx2 |> shouldContainText """../folder1/in-folder1.fsx"""

// Check md contents
let f1md1 = File.ReadAllText(rootOutputFolderAsGiven </> "folder1" </> "in-folder1.md")
let f2md2 = File.ReadAllText(rootOutputFolderAsGiven </> "folder2" </> "in-folder2.md")
f1md1 |> shouldContainText """../folder2/in-folder2.md"""
f2md2 |> shouldContainText """../folder1/in-folder1.md"""


// Same as above with relative input folder
[<Test>]
let ``Can build doc content using relative input path`` () =
let rootOutputFolderAsGiven = __SOURCE_DIRECTORY__ </> "output1"
let relativeInputFolderAsGiven = Path.GetRelativePath(System.Environment.CurrentDirectory, __SOURCE_DIRECTORY__ </> "files")

if Directory.Exists(rootOutputFolderAsGiven) then
Directory.Delete(rootOutputFolderAsGiven, true)

let content =
DocContent(
rootOutputFolderAsGiven,
Map.empty,
lineNumbers = None,
fsiEvaluator = None,
substitutions = [],
saveImages = None,
watch = false,
root = "https://github.com",
crefResolver = (fun _ -> None),
onError = failwith
)

let docModels = content.Convert(relativeInputFolderAsGiven, None, [])
let globals = []

for (_thing, action) in docModels do
action globals

// Check simple1.fsx --> simple1.html substititions
// Check simple2.md --> simple2.html substititions
let html1 = File.ReadAllText(rootOutputFolderAsGiven </> "simple1.html")
let html2 = File.ReadAllText(rootOutputFolderAsGiven </> "simple2.html")
html1 |> shouldContainText """href="simple1.html">"""
html1 |> shouldContainText """href="simple2.html">"""
html2 |> shouldContainText """href="simple1.html">"""
html2 |> shouldContainText """href="simple2.html">"""

// Check simple1.fsx --> simple1.ipynb substititions
// Check simple2.md --> simple1.ipynb substititions
let ipynb1 = File.ReadAllText(rootOutputFolderAsGiven </> "simple1.ipynb")
let ipynb2 = File.ReadAllText(rootOutputFolderAsGiven </> "simple2.ipynb")
ipynb1 |> shouldContainText "simple2.ipynb"
ipynb2 |> shouldContainText "simple1.ipynb"

// Check fsx exists
// Check simple1.fsx --> simple1.fsx substititions
// Check simple2.md --> simple1.fsx substititions
let fsx1 = File.ReadAllText(rootOutputFolderAsGiven </> "simple1.fsx")
let fsx2 = File.ReadAllText(rootOutputFolderAsGiven </> "simple2.fsx")
fsx1 |> shouldContainText "simple2.fsx"
fsx2 |> shouldContainText "simple1.fsx"

// Check md contents
// Check simple1.fsx --> simple1.md substititions
// Check simple2.md --> simple1.md substititions
let md1 = File.ReadAllText(rootOutputFolderAsGiven </> "simple1.md")
let md2 = File.ReadAllText(rootOutputFolderAsGiven </> "simple2.md")
md1 |> shouldContainText "simple2.md"
Expand Down
1 change: 1 addition & 0 deletions tests/FSharp.Literate.Tests/files/simple1.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ substitute-in-markdown: {{fsdocs-source-basename}}
[ABC](http://substitute-in-link: {{fsdocs-source-basename}})
[substitute-in-href-text: {{fsdocs-source-basename}}](http://google.com)
Another [hyperlink](simple1.fsx)
Another [hyperlink](simple2.md)
*)
Expand Down
1 change: 1 addition & 0 deletions tests/FSharp.Literate.Tests/files/simple2.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ With some [hyperlink](http://tomasp.net)
let hello = "Code sample"

Another [hyperlink](simple1.fsx)
Yet another [hyperlink](simple2.md)

0 comments on commit dc1da31

Please sign in to comment.