Skip to content

Commit

Permalink
closes #938
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart committed Jan 31, 2022
1 parent c66493a commit b0d0bbb
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 16 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[compat]
DocStringExtensions = "0.8"
Expand Down
4 changes: 3 additions & 1 deletion src/Franklin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using DelimitedFiles: readdlm
using OrderedCollections
using Pkg
using DocStringExtensions: SIGNATURES, TYPEDEF
using TOML

import Logging
import LiveServer
Expand Down Expand Up @@ -86,7 +87,8 @@ const FD_ENV = LittleDict(
:SHOW_WARNINGS => true, # franklin-specific warnings
:FAIL_ON_WARNING => false, # turn warnings into fatal errors
:UTILS_COUNTER => 0, # counter for utils module
:UTILS_HASH => nothing # hash of the utils
:UTILS_HASH => nothing, # hash of the utils
:LITERATE_VERSION => VersionNumber(TOML.parsefile(joinpath(dirname(dirname(pathof(Literate))), "Project.toml"))["version"]),
)

utils_name() = "Utils_$(FD_ENV[:UTILS_COUNTER]::Int)"
Expand Down
3 changes: 2 additions & 1 deletion src/eval/codeblock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ function parse_fenced_block(ss::SubString, shortcut=false)::Tuple
# * ```lang ... ``` where lang can be something like julia-repl
# * ```lang:path ... ``` where path is a relative path like "this/path"
# group 1 => lang; group 2 => path; group 3 => code
reg = ifelse(startswith(ss, "`````"), CODE_5_PAT, CODE_3_PAT)
reg = startswith(ss, "`````") ? CODE_5_PAT :
startswith(ss, "````") ? CODE_4_PAT : CODE_3_PAT
m = match(reg, ss)
lang = m.captures[1]
rpath = m.captures[2]
Expand Down
11 changes: 8 additions & 3 deletions src/eval/literate.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const LITERATE_FENCER = "julialit"
const LITERATE_JULIA_FENCE = "```$LITERATE_FENCER"
const LITERATE_JULIA_REPLACE = ifelse(FD_ENV[:LITERATE_VERSION] < v"2.9.0",
"```", "````")
const LITERATE_JULIA_FENCE = "$LITERATE_JULIA_REPLACE$LITERATE_FENCER"
const LITERATE_JULIA_FENCE_L = length(LITERATE_JULIA_FENCE)
const LITERATE_JULIA_FENCE_R = Regex(LITERATE_JULIA_FENCE)

const LITERATE_FLAV = ifelse(FD_ENV[:LITERATE_VERSION] < v"2.9.0",
Literate.CommonMarkFlavor(),
Literate.FranklinFlavor())

"""
$SIGNATURES
Expand Down Expand Up @@ -44,7 +49,7 @@ function literate_to_franklin(rpath::AS)::Tuple{String,Bool}
fpath, outpath;
flavor=Literate.CommonMarkFlavor(),
mdstrings=locvar(:literate_mds)::Bool,
config=Dict("codefence" => (LITERATE_JULIA_FENCE => "```")),
config=Dict("codefence" => (LITERATE_JULIA_FENCE => LITERATE_JULIA_REPLACE)),
preprocess=s->replace(s, r"#hide\s*?\n" => "# hide\n"),
postprocess=literate_post_process,
credit=false
Expand Down Expand Up @@ -82,7 +87,7 @@ function literate_post_process(s::String)::String
c = 1
for m in em
write(buf, SubString(s, head, prevind(s, m.offset)))
write(buf, "```julia:ex$c\n")
write(buf, "$(LITERATE_JULIA_REPLACE)julia:ex$c\n")
head = nextind(s, m.offset + LITERATE_JULIA_FENCE_L)
c += 1
end
Expand Down
4 changes: 3 additions & 1 deletion src/regexes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ const CODE_3_PAT = Regex(
")|(?:\\n|\\s))" *
"\\s*\\n?((?:.|\\n)*)```") # rest of the code

const CODE_5_PAT = Regex("``" * CODE_3_PAT.pattern * "``")
const CODE_4_PAT = Regex("`" * CODE_3_PAT.pattern * "`")

const CODE_5_PAT = Regex("`" * CODE_4_PAT.pattern * "`")

const CODE_HIDE_PAT = Regex(raw"(?:^|[^\S\r\n]*?)#(\s)*?(?i)hide(all)?")

Expand Down
20 changes: 10 additions & 10 deletions test/integration/literate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ end
In julia rational numbers can be constructed with the `//` operator.
Lets define two rational numbers, `x` and `y`:
```julia:ex1
````julia:ex1
# Define variable x and y
x = 1//3
y = 2//5
```
````
When adding `x` and `y` together we obtain a new rational number:
```julia:ex2
````julia:ex2
z = x + y
```
````
"""

Expand Down Expand Up @@ -110,9 +110,9 @@ end
# Literate to Franklin
s = raw"""
# # Rational numbers
# ```julia
# ````julia
# const a = 1
# ```
# ````
a = 5
"""
path = joinpath(F.path(:literate), "tutorial.jl")
Expand All @@ -123,13 +123,13 @@ end
@test out // """
<!--This file was generated, do not modify it.-->
# Rational numbers
```julia
````julia
const a = 1
```
````
```julia:ex1
````julia:ex1
a = 5
```
````
"""

# Use of `\literate` command
Expand Down
9 changes: 9 additions & 0 deletions test/parser/markdown-extra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,12 @@ end
s = "abc :joi: def" |> fd2html
@test s // "<p>abc :joi: def</p>"
end

@testset "quad-backticks" begin
s = """
````julia
1+1
````
""" |> fd2html
@test s // """<pre><code class="language-julia">1&#43;1</code></pre>"""
end

2 comments on commit b0d0bbb

@tlienart
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/53546

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.67 -m "<description of version>" b0d0bbbdec11a31ec6f8d987b36efd3da13195c1
git push origin v0.10.67

Please sign in to comment.