Comments (9)
@mcDevnagh @julio-lopez @jurica
Would it be a case of manually sanitizing the note titles pre-json output? e.g, in the internal/core/note_format.go file?
I had a look at the go json.Marshal
documentation.
It states something about a syntax like below being possible?
Filename string `json:"filename,string"`
Which should format it appropriately for wrapping in double quotes, but it didn't work on first try.
from zk.
We shouldn't have to sanitize.
encoding/json does the sanitation for us.
For example,
package main
import "encoding/json"
type Test struct {
Title string
}
func main() {
json, err := json.Marshal(Test{
Title: `"`,
})
if err != nil {
panic(err)
}
print(string(json))
}
outputs
{"Title":"\""}
Is json.Marshal
outputting everything in zk graph --json
? This would be an upstream issue, but I'd find that very surprising. More likely we're calling json.Marshal
for each note, and ignoring errors (or simply logging them). If that is the case, the best place to start fixing this would be to look at that error.
from zk.
Ok great, thanks for this. As a heads up, I won't be able to look at this (or anything else) until March 17. I'll be on holiday 🏝️
from zk.
note: narrowed this down a little bit and it actually looks like the culprit is osEnv()
call in newNoteFormatter
.
When it's getting called in graph.go, line 70, something about the double quoted title is breaking it. This is why it spits out the entire shell env variables to stdout
. The double quotes in the file name is not the culprit as I'm using ids as file names.
Changing the file title from: what does "this" mean?
to what does 'this' mean?
executes without error.
from zk.
It's actually due to the quotes not being escaped in link_format.go.
These functions are used to render the links within documents as well. So escaping the double quotes here will render links within notes with the backslashes: [[a linked \"note\"]]
. This of course breaks the links.
from zk.
Does that mean that the true culprit is links to titles with quotes and not titles with quotes themselves?
from zk.
In other words, quotes are being escaped properly everywhere in json output except the string for the filename's own link.
If I hardcode the problem field output to foo
, the call to zk graph --format json
returns json without error.
{
"filename": "another \"test\" note.md",
"filenameStem": "another \"test\" note",
"path": "another \"test\" note.md",
"absPath": "/Users/tjex/.local/src/zk-org/workbench/test-vault/another \"test\" note.md",
"title": "another \"test\" note",
"link": "foo",
"lead": "",
"body": "",
"snippets": [],
"rawContent": "# another \"test\" note\n\n\n",
"wordCount": 4,
"tags": [],
"metadata": {},
"created": "2024-04-01T03:11:03.540446352Z",
"modified": "2024-04-01T03:11:05.217630323Z",
"checksum": "a121f8d06da1bff78c5e5eb4816d0417ab2ec22317bad43baedb51a20c60df68"
}
Otherwise it would in effect return this invalid json:
{
"filename": "another \"test\" note.md",
"filenameStem": "another \"test\" note",
"path": "another \"test\" note.md",
"absPath": "/Users/tjex/.local/src/zk-org/workbench/test-vault/another \"test\" note.md",
"title": "another \"test\" note",
+ "link": "[[another "test" note]]", <- the quotes around test are not escaped
"lead": "",
"body": "",
"snippets": [],
"rawContent": "# another \"test\" note\n\n\n",
"wordCount": 4,
"tags": [],
"metadata": {},
"created": "2024-04-01T03:11:03.540446352Z",
"modified": "2024-04-01T03:11:05.217630323Z",
"checksum": "a121f8d06da1bff78c5e5eb4816d0417ab2ec22317bad43baedb51a20c60df68"
}
With the initial idea for the fix in #400 , the output looks like this:
{
"filename": "another \"test\" note.md",
"filenameStem": "another \"test\" note",
"path": "another \"test\" note.md",
"absPath": "/Users/tjex/.local/src/zk-org/workbench/test-vault/another \"test\" note.md",
"title": "another \"test\" note",
"link": "[[another \"test\" note]]",
"lead": "",
"body": "",
"snippets": [],
"rawContent": "# another \"test\" note\n\n\n",
"wordCount": 4,
"tags": [],
"metadata": {},
"created": "2024-04-01T03:11:03.540446352Z",
"modified": "2024-04-01T03:11:05.217630323Z",
"checksum": "a121f8d06da1bff78c5e5eb4816d0417ab2ec22317bad43baedb51a20c60df68"
}
Links are still rendered correctly within documents:
# note title
[another "test" note](another%20%22test%22%20note)
[[another "test" note]]
from zk.
Related Issues (20)
- LSP Link doesn't support non-Markdown HOT 7
- TestCollectionDAOFindOrCreate fails HOT 3
- update brew formula HOT 1
- Switch to Pretty Upstream HOT 7
- zk list --created date, returns notes from one day after if YAML date does not have timestamp HOT 10
- glob not addressing all folders within ignore pattern HOT 3
- GitHub Pages site does not have a homepage HOT 1
- global template ignored HOT 5
- zk cli cannot search note modified or created at the same time HOT 4
- open notes in nvim quickfix from telelescope HOT 2
- zk list outputs redundant end of buffer characters HOT 3
- `musl` systems not supported HOT 8
- `zk init` generates ambigous LSP section in config HOT 2
- v0.14.1 homebrew release action failed HOT 4
- `zk tag` doesn't shows numeric tags HOT 11
- Use GitHub Actions for building the project HOT 2
- Links not detected when using timestamps as IDs with `link-format = "markdown"` HOT 8
- Titles inside markdown links breaks LSP link completion HOT 2
- Markdown links render as wikilinks when inserted via completion HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zk.