Skip to content

Commit 36e8c21

Browse files
committed
Require #+ for continuing a code block, fixes #41.
1 parent f63cc93 commit 36e8c21

4 files changed

Lines changed: 20 additions & 18 deletions

File tree

docs/src/fileformat.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ julia code. We note a couple of things:
3939

4040
For simple use this is all you need to know. The following additional special syntax can also be used:
4141
- `#md`, `#nb`, `#jl`, `#src`: tags to filter lines, see [Filtering Lines](@ref Filtering-Lines),
42-
- `#-`: tag to manually control chunk-splits, see [Custom control over chunk splits](@ref).
42+
- `#-` (`#+`): tag to manually control chunk-splits, see [Custom control over chunk splits](@ref).
4343

4444
There is also some default convenience replacements that will always be performed, see
4545
[Default Replacements](@ref).

docs/src/pipeline.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ The example above would result in two consecutive code-chunks.
106106
The rest of the line, after `#-`, is discarded, so it is possible to use e.g.
107107
`#-------------` as a chunk splitter, which may make the source code more readable.
108108

109+
It is also possible to use `#+` as a chunk splitter. The difference between `#+` and `#-`
110+
is that `#+` enables Documenter's "continued"-blocks, see the
111+
[Documenter manual](https://juliadocs.github.io/Documenter.jl/stable/).
112+
109113

110114
## [**3.3.** Document generation](@id Document-generation)
111115

src/Literate.jl

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import .Documenter
1616
# * Lines starting with `#md` are filtered out unless creating a markdown file
1717
# * Lines starting with `#nb` are filtered out unless creating a notebook
1818
# * Lines starting with, or ending with, `#jl` are filtered out unless creating a script file
19+
# * Lines starting with, or ending with, `#src` are filtered out unconditionally
1920
# * Whitespace within a chunk is preserved
2021
# * Empty chunks are removed, leading and trailing empty lines in a chunk are also removed
2122

@@ -41,10 +42,15 @@ function parse(content; allow_continued = true)
4142

4243
for line in lines
4344
line = rstrip(line)
44-
# print("line = `$line`: ")
4545
if occursin(r"^\h*#-", line) # new chunk
4646
# assume same as last chunk, will be cleaned up otherwise
4747
push!(chunks, typeof(chunks[end])())
48+
elseif occursin(r"^\h*#\+", line) # new code chunk, that continues the previous one
49+
idx = findlast(x -> isa(x, CodeChunk), chunks)
50+
if idx !== nothing
51+
chunks[idx].continued = true
52+
end
53+
push!(chunks, CodeChunk())
4854
elseif ismdline(line) # markdown
4955
if !(chunks[end] isa MDChunk)
5056
push!(chunks, MDChunk())
@@ -78,19 +84,6 @@ function parse(content; allow_continued = true)
7884
end
7985
end
8086

81-
# find code chunks that are continued
82-
last_code_chunk = 0
83-
for (i, chunk) in enumerate(chunks)
84-
isa(chunk, MDChunk) && continue
85-
if startswith(last(chunk.lines)," ")
86-
chunk.continued = true
87-
end
88-
if startswith(first(chunk.lines)," ")
89-
chunks[last_code_chunk].continued = true
90-
end
91-
last_code_chunk = i
92-
end
93-
9487
# if we don't allow continued code blocks we need to merge MDChunks into the CodeChunks
9588
if !allow_continued
9689
merged_chunks = Chunk[]

test/runtests.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,28 @@ end
5353
#-
5454
Line 26
5555
Line 27
56-
#-
56+
#+
5757
Line 29
5858
#-
5959
Line 31
6060
Line 32
6161
# Line 33
62+
#+
6263
Line 34
6364
#-
6465
Line 36
65-
#-
66+
#+
6667
Line 38
67-
#-
68+
#+
6869
Line 40
6970
#-
7071
Line 42
7172
Line 43
7273
# Line 44
74+
#+
7375
Line 45
7476
# Line 46
77+
#+
7578
Line 47
7679
# Line 48
7780
#Line 49
@@ -174,6 +177,7 @@ content = """
174177
for i in 1:10
175178
print(i)
176179
# some markdown in a code block
180+
#+
177181
end
178182
# name: @__NAME__
179183
# Link to repo root: @__REPO_ROOT_URL__
@@ -195,6 +199,7 @@ content = """
195199
# Indented markdown
196200
for i in 1:10
197201
# Indented markdown
202+
#+
198203
## Indented comment
199204
end
200205
"""

0 commit comments

Comments
 (0)