Browse Source

Merge 183b41c75e into eb453e8358

pull/161/merge
Manuel 2 years ago committed by GitHub
parent
commit
ef48e9c6d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      docs/src/fileformat.md
  2. 2
      src/Literate.jl
  3. 20
      test/runtests.jl

2
docs/src/fileformat.md

@ -14,6 +14,8 @@ The basic syntax is simple:
Leading whitespace is allowed before `#`, but it will be removed when generating the Leading whitespace is allowed before `#`, but it will be removed when generating the
output. Since `#`-lines are treated as markdown we can not use that for regular julia output. Since `#`-lines are treated as markdown we can not use that for regular julia
comments, for this you can instead use `## `, which will render as `# ` in the output. comments, for this you can instead use `## `, which will render as `# ` in the output.
Alternatively, you can use `#~` for regular julia comments, which will render as `#`
and behaves well with code cell delimiters in VSCode.
Lets look at a simple example: Lets look at a simple example:
```julia ```julia

2
src/Literate.jl

@ -77,6 +77,8 @@ function parse(content; allow_continued = true)
end end
# remove "## " and "##\n" # remove "## " and "##\n"
line = replace(replace(line, r"^(\h*)#(# .*)$" => s"\1\2"), r"^(\h*#)#$" => s"\1") line = replace(replace(line, r"^(\h*)#(# .*)$" => s"\1\2"), r"^(\h*#)#$" => s"\1")
# similarly, change "#~x" to "#x" and remove "#~\n"
line = replace(replace(line, r"^(\h*)#~(.*)$" => s"\1#\2"), r"^(\h*#)~$" => s"\1")
push!(chunks[end].lines, line) push!(chunks[end].lines, line)
end end
end end

20
test/runtests.jl

@ -108,6 +108,14 @@ end
## Line 77 ## Line 77
## ##
## Line 79 ## Line 79
#-
#~ Line 81
#~
#~ Line 83
#-
#~ Line 85
#~
#~ Line 87
""" """
expected_chunks = Chunk[ expected_chunks = Chunk[
MDChunk(["" => "Line 1"]), MDChunk(["" => "Line 1"]),
@ -145,6 +153,8 @@ end
CodeChunk(["Line 64", " # Line 65", " Line 66", "Line 67"], false), CodeChunk(["Line 64", " # Line 65", " Line 66", "Line 67"], false),
CodeChunk(["# Line 73", "#", "# Line 75"], false), CodeChunk(["# Line 73", "#", "# Line 75"], false),
CodeChunk([" # Line 77", " #", " # Line 79"], false), CodeChunk([" # Line 77", " #", " # Line 79"], false),
CodeChunk(["# Line 81", "#", "# Line 83"], false),
CodeChunk([" # Line 85", " #", " # Line 87"], false),
] ]
parsed_chunks = Literate.parse(content) parsed_chunks = Literate.parse(content)
compare_chunks(parsed_chunks, expected_chunks) compare_chunks(parsed_chunks, expected_chunks)
@ -201,6 +211,8 @@ content = """
Source code only #src Source code only #src
## # Comment ## # Comment
## another comment ## another comment
#~ yet another comment and ...
#~... an ugly comment
#- #-
for i in 1:10 for i in 1:10
print(i) print(i)
@ -325,6 +337,8 @@ const GITLAB_ENV = Dict(
x + 3 x + 3
# # Comment # # Comment
# another comment # another comment
# yet another comment and ...
#... an ugly comment
for i in 1:10 for i in 1:10
print(i) print(i)
@ -561,6 +575,8 @@ end end
x * 3 x * 3
# # Comment # # Comment
# another comment # another comment
# yet another comment and ...
#... an ugly comment
```` ````
````@example inputfile; continued = true ````@example inputfile; continued = true
@ -1011,7 +1027,9 @@ end end
"x * 3\\n", "x * 3\\n",
"x * 3\\n", "x * 3\\n",
"# # Comment\\n", "# # Comment\\n",
"# another comment" "# another comment\\n",
"# yet another comment and ...\\n",
"#... an ugly comment"
], ],
""", """,

Loading…
Cancel
Save