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

Same key fields in different sections rendered incorrectly #2241

Open
AliceLeyou opened this issue Feb 18, 2024 · 0 comments
Open

Same key fields in different sections rendered incorrectly #2241

AliceLeyou opened this issue Feb 18, 2024 · 0 comments
Labels
bug Something isn't working.

Comments

@AliceLeyou
Copy link

What happened?

When using multiple fields with the same key within a table, they are all rendered with the value of the first occurence of the key.
Source view:
grafik
Reading view:
grafik

A similar thing happens when using fields with the same keys in different sections. Once I use an already used key in a different section, it is rendered with the corresponding occurence of the key in the first section.
Source view:
grafik
Reading view:
grafik

I believe this has to do with PR-2098, where the replacing of inline fields was adjusted to correctly display LaTeX notation. I believe this is due to MarkdownPostProcessorContext.getSectionInfo having unexpected return values. MarkdownSectionInformation.text seems to contain the text of the entire document instead of just the current section. For tables MarkdownSectionInformation.lineStart and MarkdownSectionInformation.lineEnd seem to include all rows of the table, so splicing the text according to those values also doesn't seem to solve the issue.
The only solution that I found while looking through this is to check whether the value of the inline field can be interpreted as HTML. That fixes both the original issue as well as this one, but I doubt it's the best solution for this (also the first time I looked into Dataview code, so I have no clue if it breaks something somewhere else).

const isHTMLString = (str: string) => {
    const document = new DOMParser().parseFromString(str, "text/html");
    return Array.from(document.body.childNodes).some((node: ChildNode) => node.nodeType === 1);
};
if (inlineFieldsFromText &&
    inlineFieldsFromText[index].key == inlineFields[index].key &&
    isHTMLString(inlineFields[index].value)
    ) { ... }

DQL

No response

JS

No response

Dataview Version

0.5.64

Obsidian Version

1.5.3

OS

Windows

@AliceLeyou AliceLeyou added the bug Something isn't working. label Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

1 participant