From 867f091557d72db4a698abbaec591e9093a3fae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Fri, 25 Aug 2023 14:36:42 +0200 Subject: [PATCH] Do not export setup cell output (#2184) --- lib/livebook/live_markdown/export.ex | 2 +- test/livebook/live_markdown/export_test.exs | 29 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/livebook/live_markdown/export.ex b/lib/livebook/live_markdown/export.ex index 5382e1c24..a4a020e17 100644 --- a/lib/livebook/live_markdown/export.ex +++ b/lib/livebook/live_markdown/export.ex @@ -62,7 +62,7 @@ defmodule Livebook.LiveMarkdown.Export do end) name = ["# ", notebook.name] - setup_cell = render_setup_cell(setup_cell, ctx) + setup_cell = render_setup_cell(setup_cell, %{ctx | include_outputs?: false}) sections = Enum.map(notebook.sections, &render_section(&1, notebook, ctx)) metadata = notebook_metadata(notebook) diff --git a/test/livebook/live_markdown/export_test.exs b/test/livebook/live_markdown/export_test.exs index de6128287..d9b2c966b 100644 --- a/test/livebook/live_markdown/export_test.exs +++ b/test/livebook/live_markdown/export_test.exs @@ -642,6 +642,35 @@ defmodule Livebook.LiveMarkdown.ExportTest do assert expected_document == document end + test "does not include setup cell output" do + notebook = %{Notebook.new() | name: "My Notebook"} + + notebook = + update_in(notebook.setup_section.cells, fn [setup_cell] -> + [ + %{ + setup_cell + | source: """ + IO.puts("hey")\ + """, + outputs: [{0, terminal_text("hey", true)}] + } + ] + end) + + expected_document = """ + # My Notebook + + ```elixir + IO.puts("hey") + ``` + """ + + {document, []} = Export.notebook_to_livemd(notebook, include_outputs: true) + + assert expected_document == document + end + test "removes ANSI escape codes from the output text" do notebook = %{ Notebook.new()