vscode-markdown-notes icon indicating copy to clipboard operation
vscode-markdown-notes copied to clipboard

Bibtex citation highlighting not fully functional (Fix proposed)

Open josephgarnier opened this issue 4 years ago • 3 comments

Describe the bug As you can see on the screenshot below, not all @'s are yellow and not all references are red, which means that the highlighting does not cover all use cases identified in the Pandoc documentation. bug

Expected behavior In using the Scope Inspector tool on the bugged citation, the textmate scopes should be punctuation.definition.bibtex or support.function.text.markdown.notes.bibtex.key but it's not.

Versions

  • OS: [Linux]
  • VS Code Version: [the last one]
  • Extension Version: [the last one]

How to fix it This bug is easy to fix:

  1. Open /syntaxes/notes.tmLanguage.json
  2. Go in the scope "name": "text.markdown.notes.bibtex",
  3. Replace match value by "match": "[\\[|\\;]?(\\s?\\-?@)(.*?)(?=$|[\\;\\s\\r\\n\\]{},~#%\\\\'\"=\\(\\)])

This solution is inspired from this extension. You can test this regex here.

The result after the fix result

josephgarnier avatar Jul 01 '21 20:07 josephgarnier

Here is also a proposal to fix the definitions of the cases discussed above:

  1. Open src/BibTeXCitations.ts
  2. Replace the regex line 10 by this one : static _rxBibTeXInNote = /(?<= |,|^|\[|\[-|;|-)@[\p{L}\d\-_]+(?!\(.\S\))/giu;
  3. Open src/test/jest/extension.test.ts
  4. Add these unit tests bellow at the line 224
// inside brackets with name supression and semicolumn separator
expect(("some [;-@reference]".match(rx) || [])[0]).toEqual("@reference")

// inside brackets with name supression and preceded by space
expect(("some [ -@reference]".match(rx) || [])[0]).toEqual("@reference")

// inside brackets with name supression and preceded by space and semicolumn separator
expect(("some [; -@reference]".match(rx) || [])[0]).toEqual("@reference")

// inside brackets and preceded by space
expect(("some [ @reference]".match(rx) || [])[0]).toEqual("@reference")

// inside brackets and preceded by space and semicolumn separator
expect(("some [; @reference]".match(rx) || [])[0]).toEqual("@reference")

// inside brackets
expect(("some [@reference]".match(rx) || [])[0]).toEqual("@reference")

// inside brackets and preceded by semicolumn separator
expect(("some [;@reference]".match(rx) || [])[0]).toEqual("@reference")

josephgarnier avatar Jul 03 '21 05:07 josephgarnier

Hey, sorry, terribly busy with moving and work right now. Anyone able to turn the proposal into a PR? If not, will get to when I can, just swamped right now..

kortina avatar Jul 14 '21 02:07 kortina

Okay, no worries, I'll do a PR.

josephgarnier avatar Jul 17 '21 15:07 josephgarnier