Skip to content

Commit

Permalink
Remove @raw html decorations if target is Jupyter notebook (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarros committed Sep 4, 2023
1 parent c1af5d4 commit 9832872
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/src/documenter.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ if we set `documenter = true`:
\int f dx
$$
```
- Whereas Documenter requires HTML blocks to be escaped
````
```@raw html
<tag>...</tag>
```
````
the output to a notebook markdown cell will be raw HTML
```
<tag>...</tag>
```

### [`Literate.script`](@ref):
- Documenter style `@ref`s and `@id` will be removed. This means that you can use
Expand Down
2 changes: 2 additions & 0 deletions src/Literate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ function replace_default(content, sym;
# Replace Markdown stdlib math environments
push!(repls, r"```math(.*?)```"s => s"$$\1$$")
push!(repls, r"(?<!`)``([^`]+?)``(?!`)" => s"$\1$")
# Remove Documenter escape sequence around HTML
push!(repls, r"```@raw(\h+)html(.*?)```"s => s"\2")
else # sym === :jl
push!(repls, r"^#(!md|!nb|jl) "m => "") # remove leading #!md, #!nb, and #jl
push!(repls, r" #(!md|!nb|jl)$"m => "") # remove trailing #!md, #!nb, and #jl
Expand Down
18 changes: 18 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ content = """
## Indented comment
end
# Some inline html
# ```@raw html
# <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>
# ```
# Semicolon output supression
1 + 1;
Expand Down Expand Up @@ -600,6 +605,11 @@ end end
end
````
Some inline html
```@raw html
<a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>
```
Semicolon output supression
````@example inputfile
Expand Down Expand Up @@ -1025,6 +1035,14 @@ end end
]
""",

"""
"source": [
"Some inline html\\n",
"\\n",
" <a href=\\"https://github.com/fredrikekre/Literate.jl\\">Literate.jl</a>"
]
""",

"""
"metadata": {
"meta": "data"
Expand Down

0 comments on commit 9832872

Please sign in to comment.