diff --git a/lib/livebook/live_markdown.ex b/lib/livebook/live_markdown.ex index 483e1c61bbf1..69a843dbf944 100644 --- a/lib/livebook/live_markdown.ex +++ b/lib/livebook/live_markdown.ex @@ -65,7 +65,7 @@ defmodule Livebook.LiveMarkdown do # * Elixir # * PostgreSQL # - # + # # # ```elixir # Enum.to_list(1..10) diff --git a/lib/livebook/live_markdown/export.ex b/lib/livebook/live_markdown/export.ex index 7de8153a8afa..726a6fe86523 100644 --- a/lib/livebook/live_markdown/export.ex +++ b/lib/livebook/live_markdown/export.ex @@ -210,7 +210,7 @@ defmodule Livebook.LiveMarkdown.Export do defp render_cell(%Cell.Code{} = cell, ctx) do delimiter = MarkdownHelpers.code_block_delimiter(cell.source) - code = get_code_cell_code(cell) + code = cell.source outputs = if ctx.include_outputs?, do: render_outputs(cell, ctx), else: [] metadata = cell_metadata(cell) @@ -240,7 +240,7 @@ defmodule Livebook.LiveMarkdown.Export do end defp cell_metadata(%Cell.Code{} = cell) do - keys = [:disable_formatting, :reevaluate_automatically, :continue_on_error] + keys = [:reevaluate_automatically, :continue_on_error] put_unless_default(%{}, Map.take(cell, keys), Map.take(Cell.Code.new(), keys)) end @@ -299,11 +299,6 @@ defmodule Livebook.LiveMarkdown.Export do defp encode_js_data(data) when is_binary(data), do: {:ok, data} defp encode_js_data(data), do: data |> ensure_order() |> Jason.encode() - defp get_code_cell_code(%{source: source, language: :elixir, disable_formatting: false}), - do: format_elixir_code(source) - - defp get_code_cell_code(%{source: source}), do: source - defp render_metadata(metadata) do metadata_json = metadata |> ensure_order() |> Jason.encode!() [""] @@ -349,14 +344,6 @@ defmodule Livebook.LiveMarkdown.Export do end) end - defp format_elixir_code(code) do - try do - Code.format_string!(code) - rescue - _ -> code - end - end - defp put_unless_default(map, entries, defaults) do Enum.reduce(entries, map, fn {key, value}, map -> if value == defaults[key] do diff --git a/lib/livebook/live_markdown/import.ex b/lib/livebook/live_markdown/import.ex index 64a33f1952df..b427ea61e330 100644 --- a/lib/livebook/live_markdown/import.ex +++ b/lib/livebook/live_markdown/import.ex @@ -537,9 +537,6 @@ defmodule Livebook.LiveMarkdown.Import do defp cell_metadata_to_attrs(:code, metadata) do Enum.reduce(metadata, %{}, fn - {"disable_formatting", disable_formatting}, attrs -> - Map.put(attrs, :disable_formatting, disable_formatting) - {"reevaluate_automatically", reevaluate_automatically}, attrs -> Map.put(attrs, :reevaluate_automatically, reevaluate_automatically) diff --git a/lib/livebook/notebook/cell/code.ex b/lib/livebook/notebook/cell/code.ex index ecd86ccdc150..168f01220446 100644 --- a/lib/livebook/notebook/cell/code.ex +++ b/lib/livebook/notebook/cell/code.ex @@ -9,7 +9,6 @@ defmodule Livebook.Notebook.Cell.Code do :source, :outputs, :language, - :disable_formatting, :reevaluate_automatically, :continue_on_error ] @@ -22,7 +21,6 @@ defmodule Livebook.Notebook.Cell.Code do source: String.t() | :__pruned__, outputs: list(Cell.indexed_output()), language: :elixir | :erlang, - disable_formatting: boolean(), reevaluate_automatically: boolean(), continue_on_error: boolean() } @@ -37,7 +35,6 @@ defmodule Livebook.Notebook.Cell.Code do source: "", outputs: [], language: :elixir, - disable_formatting: false, reevaluate_automatically: false, continue_on_error: false } diff --git a/lib/livebook/notebook/export/elixir.ex b/lib/livebook/notebook/export/elixir.ex index ff4e11541016..29c46a67e4f8 100644 --- a/lib/livebook/notebook/export/elixir.ex +++ b/lib/livebook/notebook/export/elixir.ex @@ -40,7 +40,7 @@ defmodule Livebook.Notebook.Export.Elixir do cells = section.cells |> Enum.map(&render_cell(&1, section)) - |> Enum.reject(&(&1 == [])) + |> Enum.reject(&(&1 in ["", []])) [name | cells] |> Enum.intersperse("\n\n") @@ -57,15 +57,12 @@ defmodule Livebook.Notebook.Export.Elixir do end defp render_cell(%Cell.Code{language: :elixir} = cell, section) do - code = get_code_cell_code(cell) - if section.parent_id do - code - |> IO.iodata_to_binary() + cell.source |> String.split("\n") |> Enum.map_intersperse("\n", &comment_out/1) else - code + cell.source end end @@ -73,7 +70,6 @@ defmodule Livebook.Notebook.Export.Elixir do code = cell.source code - |> IO.iodata_to_binary() |> String.split("\n") |> Enum.map_intersperse("\n", &comment_out/1) end @@ -86,17 +82,4 @@ defmodule Livebook.Notebook.Export.Elixir do defp comment_out(""), do: "" defp comment_out(line), do: ["# ", line] - - defp get_code_cell_code(%{source: source, disable_formatting: true}), - do: source - - defp get_code_cell_code(%{source: source}), do: format_code(source) - - defp format_code(code) do - try do - Code.format_string!(code) - rescue - _ -> code - end - end end diff --git a/lib/livebook_web/live/session_live/code_cell_settings_component.ex b/lib/livebook_web/live/session_live/code_cell_settings_component.ex index 96ab4649c8fe..d81e408a74e2 100644 --- a/lib/livebook_web/live/session_live/code_cell_settings_component.ex +++ b/lib/livebook_web/live/session_live/code_cell_settings_component.ex @@ -10,7 +10,6 @@ defmodule LivebookWeb.SessionLive.CodeCellSettingsComponent do socket = socket |> assign(assigns) - |> assign_new(:disable_formatting, fn -> cell.disable_formatting end) |> assign_new(:reevaluate_automatically, fn -> cell.reevaluate_automatically end) |> assign_new(:continue_on_error, fn -> cell.continue_on_error end) @@ -25,13 +24,6 @@ defmodule LivebookWeb.SessionLive.CodeCellSettingsComponent do Cell settings