Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish output code blocks #1611

Merged
merged 3 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions assets/css/content/code.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,24 @@
padding: .5em 1em;
background-color: var(--codeBackground);
}

.content-inner pre code.output {
margin-left: 24px;
}

.content-inner pre code.output:before {
content: "Output";
display: block;
position: absolute;
top: -16px;
left: 24px;
padding: 2px 4px;
font-size: 12px;
font-family: var(--monoFontFamily);
line-height: 1;
color: var(--textHeaders);
background-color: var(--codeBackground);
border: 1px solid var(--codeBorder);
border-bottom: 0;
border-radius: 2px;
}
4 changes: 4 additions & 0 deletions lib/ex_doc/doc_ast.ex
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ defmodule ExDoc.DocAST do
{"shell", ExDoc.ShellLexer, []}
end

defp pick_language_and_lexer("output", highlight_info, _code) do
{"output", highlight_info.lexer, highlight_info.opts}
end

defp pick_language_and_lexer("", highlight_info, _code) do
{highlight_info.language_name, highlight_info.lexer, highlight_info.opts}
end
Expand Down
13 changes: 13 additions & 0 deletions lib/ex_doc/markdown/earmark.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ defmodule ExDoc.Markdown.Earmark do
[]
end

defp fixup_list(
[
{:comment, _, [~s/ livebook:{"output":true} /], %{comment: true}},
{"pre", pre_attrs, [{"code", code_attrs, [source], code_meta}], pre_meta}
| ast
],
acc
) do
code_attrs = Enum.reject(code_attrs, &match?({"class", _}, &1))
new_code = {"code", [{"class", "output"} | code_attrs], [source], code_meta}
fixup_list([{"pre", pre_attrs, [new_code], pre_meta} | ast], acc)
end
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if the Livebook matching shouldn't happen somewhere upstream, but here we reject all comments, so it is the only place given the current approach.


defp fixup_list([head | tail], acc) do
fixed = fixup(head)

Expand Down