Skip to content

Hide code lines with #hide when executing Markdown#188

Merged
fredrikekre merged 4 commits into
fredrikekre:masterfrom
devmotion:dw/documenter_hide
Feb 19, 2022
Merged

Hide code lines with #hide when executing Markdown#188
fredrikekre merged 4 commits into
fredrikekre:masterfrom
devmotion:dw/documenter_hide

Conversation

@devmotion
Copy link
Copy Markdown
Contributor

@devmotion devmotion commented Feb 10, 2022

This PR fixes a surprising behaviour that seemed a bug to me, both intuitively and after reading the documentation. Feel free to close the PR if it is intended and there is another way to achieve the same behaviour 🙂

For different reasons, I would like to execute a Documenter-flavored Markdown file generated with Literate with Literate instead of Documenter. However, as with Documenter, I would like to suppress the output of lines that end with #hide in the final file. To my surprise, currently this does not work:

julia> using Literate

julia> write("literate_script.jl",
       """
       a = 2 + 2
       print("a: ", a); nothing #hide
       """);

julia> Literate.markdown("literate_script.jl"; execute=true, credit=false);
[ Info: generating markdown page from ~/literate_script.jl
[ Info: writing result to ~/literate_script.md

julia> print(read("literate_script.md", String))
```@meta
EditURL = "<unknown>/literate_script.jl"
```

````julia
a = 2 + 2
print("a: ", a); nothing #hide
````

````
a: 4
````

Including this file in a Documenter setup doesn't help either since Documenter does not remove lines in julia codeblocks (only in @example AFAIK).

With this PR the line is removed from the resulting Markdown file but, of course, still executed. Hence including it in my documentation yields the same output as if I would have executed the Markdown file with Documenter instead of Literate:

julia> using Literate

julia> write("literate_script.jl",
       """
       a = 2 + 2
       print("a: ", a); nothing #hide
       """);

julia> Literate.markdown("literate_script.jl"; execute=true, credit=false);
[ Info: generating markdown page from ~/literate_script.jl
[ Info: writing result to ~/literate_script.md

julia> print(read("literate_script.md", String))
```@meta
EditURL = "<unknown>/literate_script.jl"
```

````julia
a = 2 + 2
````

````
a: 4
````

@racinmat noticed this inconsistency in #166 (comment) as well. I checked that the example there is fixed as well, with this PR the code block is shown as
image

@devmotion
Copy link
Copy Markdown
Contributor Author

What's your opinion @fredrikekre? Do you think the PR is a good idea?

@fredrikekre
Copy link
Copy Markdown
Owner

Yea this seems fine, it is a bit difficult to understand all the combinations of options at this point, sadly.

Can you add a note in the CHANGELOG.md?

Comment thread test/runtests.jl
a = 2 + 2
print("a: ", a); nothing #hide
#-
47 #hide
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a test for 123+123; (which was already part of the test) that checks that no nothing #hide is added. I hope this was what you had in mind.

@fredrikekre fredrikekre merged commit a7f4059 into fredrikekre:master Feb 19, 2022
@fredrikekre
Copy link
Copy Markdown
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants