dsebastien / obsidian-dataview-serializer

Obsidian plugin that gives you the power of Dataview, but generates Markdown, making it compatible with Obsidian Publish, and making the links appear on the Graph.
https://developassion.gitbook.io/obsidian-dataview-serializer
MIT License
57 stars 6 forks source link

[Bug] Inconsistent callout handling #13

Open tsievert opened 3 months ago

tsievert commented 3 months ago

I was testing how this works with my workflow and noticed inconsistent behaviors with callouts.

Here the code without trying to serialize it:

> [!Experiments]+
> - # In-Progress
>
> ```dataview
> LIST FROM "01 Research/Lab Notebook" AND #experiment WHERE contains(status, "in-progress")
> ```

Now with serialization that does not get recognized:

> [!Experiments]+
> - # In-Progress
>
><!-- QueryToSerialize: LIST FROM "01 Research/Lab Notebook" AND #experiment WHERE contains(status, "in-progress") -->

Then I tried it outside of the callout, and suddenly the part inside the callout gets recognized:

<!-- QueryToSerialize: LIST FROM "01 Research/Lab Notebook" AND #experiment WHERE contains(status, "in-progress") -->
<!-- SerializedQuery: LIST FROM "01 Research/Lab Notebook" AND #experiment WHERE contains(status, "in-progress") -->
- [[01 Research/Lab Notebook/2023-09-08 Camera calibration.md|2023-09-08 Camera calibration]]
- [[01 Research/Lab Notebook/2023-09-15 Reactions to conspecific and heterospecific bedding in Peromyscus.md|2023-09-15 Reactions to conspecific and heterospecific bedding in Peromyscus]]
<!-- SerializedQuery END -->

> [!Experiments]+
> - # In-Progress
>
><!-- QueryToSerialize: LIST FROM "01 Research/Lab Notebook" AND #experiment WHERE contains(status, "in-progress") -->
<!-- SerializedQuery: LIST FROM "01 Research/Lab Notebook" AND #experiment WHERE contains(status, "in-progress") -->
- [[01 Research/Lab Notebook/2023-09-08 Camera calibration.md|2023-09-08 Camera calibration]]
- [[01 Research/Lab Notebook/2023-09-15 Reactions to conspecific and heterospecific bedding in Peromyscus.md|2023-09-15 Reactions to conspecific and heterospecific bedding in Peromyscus]]
<!-- SerializedQuery END -->

It messes up the callout, but somehow it suddenly kinda works.

dsebastien commented 3 months ago

The replacement logic is a bit finicky, and I'm not a master of Regular expressions, unfortunately. I will keep this ticket open because improvements would be very valuable to make this plugin more versatile.

The first example fails because, for now, the plugin expects the line containing a query to start with <!-- QueryToSerialize: ... The second one is harder to explain. When the plugin processes a file, it first looks for all the queries it can find. Then, it removes existing query outputs, then it serializes the queries and adds the outputs. I suppose that something goes wrong during the removal phase