Compare commits

..

No commits in common. "2a09c10cad67402c6a0ad535053608091d2de105" and "ebd8ddab078fb85b576fa463ac18b3ee8bbcc780" have entirely different histories.

4 changed files with 7 additions and 19 deletions

View file

@ -2,13 +2,7 @@
<!-- Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. --> <!-- Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. -->
## [0.2.1] ## [0.1.1]
### Added
- Enable on `.mdx` (markdown + React components)
- Reference regex now ignores trailing period, for better matching of inline citation at the end of a sentence.
## [0.2.0]
### Added ### Added
- Added a decorator which shows the links to Zotero on hovering the citerefs. - Added a decorator which shows the links to Zotero on hovering the citerefs.

View file

@ -3,7 +3,7 @@
"publisher": "rubenvandeven", "publisher": "rubenvandeven",
"displayName": "ZoteroLens", "displayName": "ZoteroLens",
"description": "When using Markdown citations, Zoterolens provides quick access to Zotero pdf-attachments.", "description": "When using Markdown citations, Zoterolens provides quick access to Zotero pdf-attachments.",
"version": "0.2.1", "version": "0.2.0",
"engines": { "engines": {
"vscode": "^1.63.0" "vscode": "^1.63.0"
}, },
@ -19,7 +19,6 @@
], ],
"activationEvents": [ "activationEvents": [
"onLanguage:markdown", "onLanguage:markdown",
"onLanguage:mdx",
"onCommand:zoterolens.showInZotero", "onCommand:zoterolens.showInZotero",
"onCommand:zoterolens.openZoteroPDF" "onCommand:zoterolens.openZoteroPDF"
], ],
@ -39,11 +38,11 @@
"commandPalette": [ "commandPalette": [
{ {
"command": "zoterolens.showInZotero", "command": "zoterolens.showInZotero",
"when": "editorLangId == markdown || editorLangId == mdx" "when": "editorLangId == markdown"
}, },
{ {
"command": "zoterolens.openZoteroPDF", "command": "zoterolens.openZoteroPDF",
"when": "editorLangId == markdown || editorLangId == mdx" "when": "editorLangId == markdown"
} }
] ]
}, },

View file

@ -36,8 +36,7 @@ function updateDecorations() {
const uriArguments = `?${encodeURIComponent(JSON.stringify([reference]))}`; const uriArguments = `?${encodeURIComponent(JSON.stringify([reference]))}`;
const pdfCommandUri = Uri.parse(`command:zoterolens.openZoteroPDF`+uriArguments); const pdfCommandUri = Uri.parse(`command:zoterolens.openZoteroPDF`+uriArguments);
const viewCommandUri = Uri.parse(`command:zoterolens.showInZotero`+uriArguments); const viewCommandUri = Uri.parse(`command:zoterolens.showInZotero`+uriArguments);
const pageNr = reference.pagenr === null ? "" : `(${reference.pagenr})`; const contents = new MarkdownString(`${reference.citekey}\n\n[View in Zotero](${viewCommandUri}) | [Open PDF](${pdfCommandUri})`);
const contents = new MarkdownString(`${reference.citekey} ${pageNr}\n\n[View in Zotero](${viewCommandUri}) | [Open PDF](${pdfCommandUri})`);
// To enable command URIs in Markdown content, you must set the `isTrusted` flag. // To enable command URIs in Markdown content, you must set the `isTrusted` flag.
// When creating trusted Markdown string, make sure to properly sanitize all the // When creating trusted Markdown string, make sure to properly sanitize all the

View file

@ -13,20 +13,16 @@ export interface Reference {
range: Range; range: Range;
} }
// TODO match citations in brackets [@citation] inline @cita_tion, // TODO match citations in brackets [@citation] inline @citatinon,
// but also page number in [see @citation p.23] and // but also page number in [see @citation p.23] and
// inlince @citation [p.23] (so brackets after inline) // inlince @citation [p.23] (so brackets after inline)
// [@citation pp.10-20] matches page 10
// [@citation p10] without period is also valid
// accept a period @citation.2022 but NOT ending on a period (e.g. ignore the period in @citation. because of end of a sentence)
// TODO possibly use https://github.com/martinring/markdown-it-citations/blob/ba82a511de047a2438b4ac060c4c71b5a5c82da9/src/index.ts#L43 // TODO possibly use https://github.com/martinring/markdown-it-citations/blob/ba82a511de047a2438b4ac060c4c71b5a5c82da9/src/index.ts#L43
export function findReferences(document: TextDocument): Reference[] { export function findReferences(document: TextDocument): Reference[] {
const matches: Reference[] = []; const matches: Reference[] = [];
for (let lineNr = 0; lineNr < document.lineCount; lineNr++) { for (let lineNr = 0; lineNr < document.lineCount; lineNr++) {
const line = document.lineAt(lineNr); const line = document.lineAt(lineNr);
let match: RegExpExecArray | null; let match: RegExpExecArray | null;
let regex = /(?<=@)([\w\.]+)[, ]*\[?(?:[p]{0,2}\.)?(\d+)?(?:-+\d+)?\]?/g;
let regex = /(?<=@)([\w\.]+)(?<!\.)[, ]*\[?(?:[p]{0,2}\.?)?(\d+)?(?:-+\d+)?\]?/g;
regex.lastIndex = 0; regex.lastIndex = 0;
const text = line.text;//.substring(0, 1000); const text = line.text;//.substring(0, 1000);
while ((match = regex.exec(text))) { while ((match = regex.exec(text))) {