Compare commits
4 commits
ebd8ddab07
...
2a09c10cad
Author | SHA1 | Date | |
---|---|---|---|
|
2a09c10cad | ||
|
154afcc5ab | ||
|
ee8a1cc681 | ||
|
d9bc42d464 |
4 changed files with 19 additions and 7 deletions
|
@ -2,7 +2,13 @@
|
|||
|
||||
<!-- Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. -->
|
||||
|
||||
## [0.1.1]
|
||||
## [0.2.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 a decorator which shows the links to Zotero on hovering the citerefs.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"publisher": "rubenvandeven",
|
||||
"displayName": "ZoteroLens",
|
||||
"description": "When using Markdown citations, Zoterolens provides quick access to Zotero pdf-attachments.",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"engines": {
|
||||
"vscode": "^1.63.0"
|
||||
},
|
||||
|
@ -19,6 +19,7 @@
|
|||
],
|
||||
"activationEvents": [
|
||||
"onLanguage:markdown",
|
||||
"onLanguage:mdx",
|
||||
"onCommand:zoterolens.showInZotero",
|
||||
"onCommand:zoterolens.openZoteroPDF"
|
||||
],
|
||||
|
@ -38,11 +39,11 @@
|
|||
"commandPalette": [
|
||||
{
|
||||
"command": "zoterolens.showInZotero",
|
||||
"when": "editorLangId == markdown"
|
||||
"when": "editorLangId == markdown || editorLangId == mdx"
|
||||
},
|
||||
{
|
||||
"command": "zoterolens.openZoteroPDF",
|
||||
"when": "editorLangId == markdown"
|
||||
"when": "editorLangId == markdown || editorLangId == mdx"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -36,7 +36,8 @@ function updateDecorations() {
|
|||
const uriArguments = `?${encodeURIComponent(JSON.stringify([reference]))}`;
|
||||
const pdfCommandUri = Uri.parse(`command:zoterolens.openZoteroPDF`+uriArguments);
|
||||
const viewCommandUri = Uri.parse(`command:zoterolens.showInZotero`+uriArguments);
|
||||
const contents = new MarkdownString(`${reference.citekey}\n\n[View in Zotero](${viewCommandUri}) | [Open PDF](${pdfCommandUri})`);
|
||||
const pageNr = reference.pagenr === null ? "" : `(${reference.pagenr})`;
|
||||
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.
|
||||
// When creating trusted Markdown string, make sure to properly sanitize all the
|
||||
|
|
|
@ -13,16 +13,20 @@ export interface Reference {
|
|||
range: Range;
|
||||
}
|
||||
|
||||
// TODO match citations in brackets [@citation] inline @citatinon,
|
||||
// TODO match citations in brackets [@citation] inline @cita_tion,
|
||||
// but also page number in [see @citation p.23] and
|
||||
// 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
|
||||
export function findReferences(document: TextDocument): Reference[] {
|
||||
const matches: Reference[] = [];
|
||||
for (let lineNr = 0; lineNr < document.lineCount; lineNr++) {
|
||||
const line = document.lineAt(lineNr);
|
||||
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;
|
||||
const text = line.text;//.substring(0, 1000);
|
||||
while ((match = regex.exec(text))) {
|
||||
|
|
Loading…
Reference in a new issue