Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not convert links to markdown data files to html #447

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sandpaper
Title: Create and Curate Carpentries Lessons
Version: 0.11.15
Version: 0.11.16
Authors@R: c(
person(given = "Zhian N.",
family = "Kamvar",
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# sandpaper 0.11.16 (unreleased)

## BUG FIX

- links to markdown files under `episodes/{data,fig,files}` folders are no
longer converted to html extensions.

# sandpaper 0.11.15 (2023-04-05)

## BUG FIX
Expand Down
11 changes: 9 additions & 2 deletions inst/rmarkdown/lua/lesson.lua
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,15 @@ flatten_links = function(el)
-- rename local markdown/Rmarkdown
-- link.md goes to link.html
-- link.md#section1 goes to link.html#section1
local proto = text.sub(tgt, 1, 4)
if proto ~= "http" and proto ~= "ftp:" then
-- We want to transformt the links only for local markdown files
-- TODO: revisit this to allow/disallow/retransform files that should be
-- included.
local our_prose = tgt:find("^https?:") == nil and
tgt:find("^ftp:") == nil and
tgt:find("^data/") == nil and
tgt:find("^files/") == nil and
tgt:find("^fig/") == nil
if our_prose then
tgt,_ = tgt:gsub("%.R?md(#[%S]+)$", ".html%1")
tgt,_ = tgt:gsub("%.R?md$", ".html")
end
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/_snaps/render_html.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
,Para [Str "This",Space,Link ("",[],[]) [Str "rmd",Space,Str "link",Space,Str "also"] ("01-Introduction.html","")]
,Para [Str "This",Space,Link ("",["newclass"],[]) [Str "rmd",Space,Str "is",Space,Str "safe"] ("https://example.com/01-Introduction.Rmd","")]
,Para [Str "This",Space,Link ("",[],[]) [Str "too"] ("Setup.html#windows-setup","windows setup")]
,Para [Image ("fig-first",["imgclass"],[("alt","alt text")]) [Str "link",Space,Str "should",Space,Str "be",Space,Str "transformed"] ("fig/Setup.png","fig:")]]]]
,Para [Image ("fig-first",["imgclass"],[("alt","alt text")]) [Str "link",Space,Str "should",Space,Str "be",Space,Str "transformed"] ("fig/Setup.png","fig:")]
,Para [Str "This",Space,Link ("",[],[]) [Str "markdown",Space,Str "data",Space,Str "file",Space,Str "is",Space,Str "also",Space,Str "safe"] ("data/markdown-example.md","")]]]]
,Div ("accordionSolution1",["accordion","challenge-accordion","accordion-flush"],[])
[Div ("",["accordion-item"],[])
[RawBlock (Format "html") "<button class=\"accordion-button solution-button collapsed\" type=\"button\" data-bs-toggle=\"collapse\" data-bs-target=\"#collapseSolution1\" aria-expanded=\"false\" aria-controls=\"collapseSolution1\">\n <h4 class=\"accordion-header\" id=\"headingSolution1\">\n Write now\n </h4>\n</button>"
Expand Down Expand Up @@ -119,6 +120,7 @@
<img src="fig/Setup.png" id="fig-first" class="imgclass" alt="alt text" alt="" />
<p class="caption">link should be transformed</p>
</div>
<p>This <a href="data/markdown-example.md">markdown data file is also safe</a></p>
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/examples/ex.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ This [too](learners/Setup.md#windows-setup 'windows setup')

![link should be transformed](../episodes/fig/Setup.png){#fig-first .imgclass alt='alt text'}

This [markdown data file is also safe](data/markdown-example.md)

::: solution

# Write now
Expand Down