out-of-cheese-error / gooseberry

A command line utility to generate a knowledge base from Hypothesis annotations
Apache License 2.0
152 stars 9 forks source link

{{incontext}} is rendering as empty #50

Closed HEmile closed 3 years ago

HEmile commented 3 years ago

Bug description

I have {{incontext}}| in my annotation template, however, it's being parsed as an empty string.

Ninjani commented 3 years ago

Is this happening for all your annotations or a specific one?

HEmile commented 3 years ago

Seems to be happening to all of them!

Ninjani commented 3 years ago

Hmm, I'm not sure what's causing this. Could you make an example annotation on this page (on the Public group) and let me know if it's still empty? (you'd have to change the gooseberry config group to Public) I can then download the annotation with the hypothesis CLI as JSON and see if I can spot what's happening.

HEmile commented 3 years ago

I made an annotation here. My template is

annotation_template = '''
{{#each highlight}}> [{{this}}]({{incontext}}){{/each}}

{{text}}

{{#each tags}}#{{this}}{{#unless @last}}, {{/unless}}{{/each}}
'''
Ninjani commented 3 years ago

I can't see it, are you sure it's Public?

HEmile commented 3 years ago

Sorry, I think I set it to show only for me. Should work now?

Ninjani commented 3 years ago

Still can't see it I'm afraid

HEmile commented 3 years ago

I tried creating a new one: (I'm an hypothes.is noob, tbh) image

Ninjani commented 3 years ago

Yes, works now! Here is the JSON:

{"id":"fFRTYFsGEeueWGsAsPNqoQ","created":"2021-01-20T10:01:37.786553Z","updated":"2021-01-20T10:01:37.786553Z","user":"acct:HEmile@hypothes.is","uri":"https://github.com/out-of-cheese-error/gooseberry/issues/50","text":"An annotation","tags":[],"group":"__world__","permissions":{"read":["group:__world__"],"delete":["acct:HEmile@hypothes.is"],"admin":["acct:HEmile@hypothes.is"],"update":["acct:HEmile@hypothes.is"]},"target":[{"source":"https://github.com/out-of-cheese-error/gooseberry/issues/50","selector":[{"type":"RangeSelector","endOffset":60,"endContainer":"/div[5]/div[1]/main[1]/div[2]/div[1]/div[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[2]/div[8]/div[1]/div[2]/div[1]/div[2]/task-lists[1]/table[1]/tbody[1]/tr[1]/td[1]/p[1]","startOffset":0,"startContainer":"/div[5]/div[1]/main[1]/div[2]/div[1]/div[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[2]/div[8]/div[1]/div[2]/div[1]/div[2]/task-lists[1]/table[1]/tbody[1]/tr[1]/td[1]/p[1]"},{"type":"TextPositionSelector","start":27977,"end":28037},{"type":"TextQuoteSelector","exact":"Sorry, I think I set it to show only for me. Should work now","prefix":"    \n\n\n  \n    \n      \n          ","suffix":"?\n      \n    \n  \n\n\n\n\n          \n"}]}],"links":{"incontext":"https://hyp.is/fFRTYFsGEeueWGsAsPNqoQ/github.com/out-of-cheese-error/gooseberry/issues/50","html":"https://hypothes.is/a/fFRTYFsGEeueWGsAsPNqoQ","json":"https://hypothes.is/api/annotations/fFRTYFsGEeueWGsAsPNqoQ"},"hidden":false,"flagged":false,"references":[],"user_info":{"display_name":null}}

The incontext link is right there, so I'm not sure what's happening! I'll take a closer look.

Ninjani commented 3 years ago

I could reproduce this now and realized that it's because of the template. For example:

annotation_template = '''
{{#each highlight}}> {{this}}{{/each}}

{{incontext}}
{{text}}

{{#each tags}}#{{this}}{{#unless @last}}, {{/unless}}{{/each}}
'''

works fine but using incontext within the each doesn't work. I guess this is a problem with the Handlebars templating language - maybe there's a different syntax for it? I don't know the syntax well enough but it should be described somewhere in the docs

HEmile commented 3 years ago

Ahh, you're right. It should've been {{#each highlight}}> [{{this}}]({{../incontext}}){{/each}}. Thanks for the help!