Fix relative link URL in Markdown output (#1189)

This commit is contained in:
Tw 2022-05-17 09:03:18 +08:00 committed by GitHub
parent 07a75887e0
commit 641ac96ae7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View file

@ -13,7 +13,9 @@ const MarkdownRenderer = {
mounted() {
this.props = this.getProps();
const markdown = new Markdown(this.el, "");
const markdown = new Markdown(this.el, "", {
baseUrl: this.props.sessionPath,
});
this.handleEvent(
`markdown_renderer:${this.props.id}:content`,
@ -26,6 +28,7 @@ const MarkdownRenderer = {
getProps() {
return {
id: getAttributeOrThrow(this.el, "data-id"),
sessionPath: getAttributeOrThrow(this.el, "data-session-path"),
};
},
};

View file

@ -47,8 +47,12 @@ defmodule LivebookWeb.Output do
"""
end
defp render_output({:markdown, markdown}, %{id: id}) do
live_component(Output.MarkdownComponent, id: id, content: markdown)
defp render_output({:markdown, markdown}, %{id: id, session_id: session_id}) do
live_component(Output.MarkdownComponent,
id: id,
session_id: session_id,
content: markdown
)
end
defp render_output({:image, content, mime_type}, %{id: id}) do

View file

@ -17,7 +17,8 @@ defmodule LivebookWeb.Output.MarkdownComponent do
<div class="markdown"
id={"markdown-renderer-#{@id}"}
phx-hook="MarkdownRenderer"
data-id={@id}>
data-id={@id}
data-session-path={Routes.session_path(@socket, :page, @session_id)}>
</div>
"""
end