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

Handle trailing markdown content in qmd files correctly #11

Merged
merged 1 commit into from
Jan 17, 2024
Merged
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
8 changes: 8 additions & 0 deletions src/server.jl
Original file line number Diff line number Diff line change
@@ -176,6 +176,14 @@ function raw_markdown_chunks(path::String)
push!(raw_chunks, (type = :code, source, file = path, line, evaluate))
end
end
if terminal_line <= length(source_lines)
markdown = join(source_lines[terminal_line:end], "\n")
push!(
raw_chunks,
(type = :markdown, source = markdown, file = path, line = terminal_line),
)
end

# The case where the notebook has no code cells.
if isempty(raw_chunks) && !code_cells
push!(
11 changes: 11 additions & 0 deletions test/examples/trailing_content.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Trailing content
---

A code block:

```{julia}
1 + 1
```

And some trailing content.
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -538,6 +538,23 @@ end
@test cell["execution_count"] == 0
@test isempty(cell["outputs"])
end
file("trailing_content") do json
cells = json["cells"]
@test length(cells) == 3

cell = cells[1]
@test cell["cell_type"] == "markdown"
@test any(line -> contains(line, "A code block:"), cell["source"])

cell = cells[2]
@test cell["cell_type"] == "code"
@test cell["execution_count"] == 1
@test cell["outputs"][1]["data"]["text/plain"] == "2"

cell = cells[3]
@test cell["cell_type"] == "markdown"
@test any(line -> contains(line, "And some trailing content."), cell["source"])
end

tests
end