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

[BUG] Embedding local images doesn't work #136

Closed
artisticat1 opened this issue Jun 13, 2022 · 6 comments
Closed

[BUG] Embedding local images doesn't work #136

artisticat1 opened this issue Jun 13, 2022 · 6 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@artisticat1
Copy link
Collaborator

Describe the bug
Embedding local images in a text column doesn't work

To Reproduce

  1. Add an image to your vault (e.g. img.png)
  2. Open a database folder
  3. Add a new text column
  4. In the column settings, set "Enable media links" to off
  5. In one of the rows, type ![[img.png]], then exit the cell. No image is shown.
  6. Close the database
  7. Reopen the database
  8. The row we tried to add the image to has disappeared from the database

Expected behavior
The image is shown in the text column, and persists after closing/reopening the database

Desktop (please complete the following information):

  • OS: Windows
  • Plugin version: 1.7.0
@RafaelGB
Copy link
Owner

thanks @artisticat1
added to the roadmap

@RafaelGB RafaelGB added the bug Something isn't working label Jun 13, 2022
@RafaelGB RafaelGB self-assigned this Jun 17, 2022
@RafaelGB RafaelGB added the help wanted Extra attention is needed label Jun 17, 2022
@RafaelGB
Copy link
Owner

I am working on this. I'm trying to see what's broken... when the embed string arrives to renderMarkdown does not continue the function, so the handleEmbeds service does not do its magic

export async function renderMarkdown(
  cell: Cell,
  markdownString: string,
  domElement: HTMLDivElement,
  depth: number
) {
  try {
    const view: DatabaseView = (cell as any).tableData.view;
    const column = cell.column as unknown as DatabaseColumn;
    const { media_height, media_width, enable_media_view } = column.config;
    if (enable_media_view && isValidHttpUrl(markdownString)) {
      markdownString = `![embedded link|${media_height}x${media_width}](${markdownString})`;
    }
    console.log("rendering markdown", markdownString);
    domElement.empty();
    const dom = domElement.createDiv();

    dom.addClasses(["markdown-preview-view", c("markdown-preview-view")]);
    dom.createDiv(c("embed-link-wrapper"), (wrapper) => {
      wrapper.createEl(
        "a",
        {
          href: domElement.getAttr("src") || view.file.basename,
          cls: `internal-link ${c("embed-link")}`,
        },
        (link) => {
          link.setAttr("aria-label", view.file.basename);
        }
      );
    });
    await MarkdownRenderer.renderMarkdown(
      markdownString,
      dom.createDiv(),
      view.file.path,
      view
    );
   // STOPS HERE BY SOME MISTERIOUS REASON
    domElement.addClass("is-loaded");
    if (depth > 0) {
      await handleEmbeds(dom, view, --depth);
    }
  } catch (e) {
    LOGGER.error(e);
  }
}

@RafaelGB
Copy link
Owner

Okay.... Looks like MarkdownPreviewView works! (instead of use MarkdownRenderer)

@RafaelGB
Copy link
Owner

Screen.Recording.2022-06-17.at.20.48.55.mov

@artisticat1
Copy link
Collaborator Author

Great! I tested it and it works, but when I close and reopen the database, the image stops showing up.

@RafaelGB
Copy link
Owner

just work with inline fields yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants