Open TomBener opened 3 years ago
Hi,
I ran into the same issue, and it seems that the problem is related to the bibtex parser library used by the plugin, which only returns the zotero link, and not the associated text.
The issue is here (noted in comments !) :
// just take the URL? Not the label?
case 'href':
if (arg = this.argument(node, 2)) return this.clean(arg[0] as Node)
break
A definitive fix would require that this library modify the parser’s logic, which currently doesn’t handle links :
const markup_defaults: Record<string, { open: string, close: string}> = {
enquote: { open: '\u201c', close: '\u201d' },
sub: { open: '<sub>', close: '</sub>' },
sup: { open: '<sup>', close: '</sup>' },
bold: { open: '<b>', close: '</b>' },
italics: { open: '<i>', close: '</i>' },
smallCaps: { open: '<span style="font-variant:small-caps;">', close: '</span>' },
caseProtect: { open: '<span class="nocase">', close: '</span>' },
roman: { open: '', close: '' },
fixedWidth: { open: '', close: '' },
}
(no <a href="">…</a>
kind of stuff), see also here for the conversion logic.
But you can make a quick workaround (it’s working for me) by modifying this plugin’s code in your vault folder : (.obsidian/plugins/obsidian-citation-plugin/main.js
).
First, search in the file case 'href':
to find this code:
// just take the URL? Not the label?
case 'href':
if (arg = this.argument(node, 2))
return this.clean(arg[0]);
break;
and replace with
// just take the URL? Not the label?
case 'href':
// Workaround for getting a markdown link
const block = this.argument(node, 2);
if (block) {
// block: [ {value: [{ value: "zotero://…"}]}, {…} ]
const link = block[0].value[0].value;
// block: [ {…}, { value: [ {value: "note on page…"} ]} ]
const text = block[1] ? block[1].value[0].value : "Link";
block[0].value[0].value = `[${text}](${link})`;
}
if (arg = this.argument(node, 2))
return this.clean(arg[0]);
break;
Be aware that for some reason, the plugin’s code is duplicate in the js file, so make the modifications twice (for me it was at line 48939 and line 84530)
[Link]
to find this code:
get: function () {
var _a;
return (_a = this._note) === null || _a === void 0 ? void 0 : _a.map(function (el) { return el.replace(/(zotero:\/\/.+)/g, '[Link]($1)'); }).join('\n\n');
},
Replace the part
_a.map(function (el) { return el.replace(/(zotero:\/\/.+)/g, '[Link]($1)'); }).join('\n\n');
with
_a.map(function (el) { return el; }).join('\n\n');
(this part is also duplicate, make sure to replace this in the two locations).
Note: thoses changes will be erased when updating the plugin, but it’s a simple workaround to do until the problem is fixed. Feel free to open an issue on the bibtex-parser repo also
@abdullahibnnadjo Great! It works as expected. Huge thanks for your workaround!
The parser has been updated to 6.0.1 to convert links to <a>
markup.
Be aware that for some reason, the plugin’s code is duplicate in the js file, so make the modifications twice (for me it was at line 48939 and line 84530)
In what sense is it duplicate? And there isn't a source file in the parser that has more than 4527 lines of code; you're probably looking at something that bundles the parser into a larger javascript source.
Hi, @retorquere, the duplicated lines are in main.js
of obsidian-citation-plugin. It is available at https://github.com/hans/obsidian-citation-plugin/releases/download/0.4.4/main.js
The parser has been updated to 6.0.1 to convert links to
<a>
markup.Be aware that for some reason, the plugin’s code is duplicate in the js file, so make the modifications twice (for me it was at line 48939 and line 84530)
In what sense is it duplicate? And there isn't a source file in the parser that has more than 4527 lines of code; you're probably looking at something that bundles the parser into a larger javascript source.
Yes, I was refering to the plugin's bundle to apply the workaround, in which the code is duplicate. Your code is completely fine đź‘Ť
@TomBener @abdullahibnnadjo with the release of the update to bibtex parser in v6.0.0 is this now resolved? If not could you maybe add more here: https://github.com/retorquere/bibtex-parser/issues/19
Thanks for the great plugin.
PDF annotations extracted by Zotfile has the URL, which links to the specific page:
In the
.bib
file, which looks similar, but with LaTeX format:However, after importing into Obsidian, the plugin replaces the hypertext as the unified
Link
:I do hope to use
Morrison 2020:366
instead ofLink
. Please consider this feature. Thank you 🙏️