Browse Source

Remove `@raw html` decorations if target is Jupyter notebook (#223)

pull/220/merge
Kipton Barros 2 years ago committed by GitHub
parent
commit
98328722c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      docs/src/documenter.md
  2. 2
      src/Literate.jl
  3. 18
      test/runtests.jl

10
docs/src/documenter.md

@ -45,6 +45,16 @@ if we set `documenter = true`: @@ -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

2
src/Literate.jl

@ -184,6 +184,8 @@ function replace_default(content, sym; @@ -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

18
test/runtests.jl

@ -234,6 +234,11 @@ content = """ @@ -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;
@ -600,6 +605,11 @@ end end @@ -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
@ -1025,6 +1035,14 @@ end end @@ -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"

Loading…
Cancel
Save