Skip to content

BibTeX language support for the CodeMirror editor.

License

Notifications You must be signed in to change notification settings

citedrive/codemirror-lang-bibtex

Repository files navigation

@citedrive/codemirror-lang-bibtex

[ WEBSITE | ISSUES | FORUM | CHANGELOG | NPM ]

This package implements BibTeX language support for the CodeMirror code editor.

The project page has more information, a number of examples and the documentation.

This code is released under an MIT license.

Usage

import { EditorView, basicSetup } from "codemirror";
import { bibtex } from "@citedrive/codemirror-lang-bibtex";

const view = new EditorView({
    parent: document.body,
    doc: `fmt.Println("hello world")`,
    extensions: [basicSetup, bibtex()],
});

API Reference

bibtex(config⁠?: {biblatex⁠?: boolean, smartSuggest⁠?: boolean, snippetRecs⁠?: boolean, autoCursor⁠?: boolean, syntaxLinter⁠?: boolean, keywords⁠?: readonly string[]} = {}) → LanguageSupport

BibTeX language support with BibLaTeX dialect support, autocompletion configuration, and snippets for both BibTeX and BibLaTeX that are suggested based on the editor context.

There are configuration options for the following:

  • BibTeX vs BibLaTeX language support:
    • default: biblatex: false
    • defaults to BibTeX
  • Snippet Smart-Suggestion:
    • default: smartSuggest: true
    • The smart-suggestion feature only suggests snippets for bibliography entries (i.e. @article = {...}) when the user is not currently editing an entry and only suggests snippets for bibliography fields (i.e. author = {Donald Knuth}) when the user is currently editing an entry.
  • Opinionated Snippets:
    • default: snippetRecs: true
    • Snippets have been scaffolded as per the current BibTeX/BibLaTeX specs. The snippet render config, exclusion of certain snippets, and entry snippets' suggestion of recommendation/optional fields are done in an opinionated manner (suggestions are welcome!).
  • Automatic Cursor Placement:
    • default: autoCursor: true
    • Automatically place the cursor in ideal location(s) when expanding a snippet. This, as well, is opinionated.
    • Please note that this feature relies on the cursor state (which is tracked by EditorState). When overwriting the EditorState (in a non user-input related manner, i.e. via a formatting plugin), the future cursor locations do not always persist, leading to a clunky (or sometimes fully inoperable) experience.
    • Thus, if your CodeMirror implementation relies heavily on modifying/overwriting EditorState, I would recommend testing both with and without this feature, to see which works best for your use-case.
    • (As an aside: I have some ideas on how to fix this issue, but I have just started a new semester at uni and will likely not have much time to work on the plugin for the next few months. - Vai)
  • Syntax Linting:
    • default: syntaxLinter: true
    • Invalid BibTeX (and BibLaTeX) syntax is underlined in red and a warning is issued, thanks to bibtex-tidy.
  • Custom Keywords:
    • default: keywords: []
    • Users can specify custom keywords/values that will be auto-suggested when within a FieldValue syntax node.
bibtexLanguage: LRLanguage

BibTeX Language configuration with syntax highlighting, folding, and indentation.

biblatexLanguage: LRLanguage

BibLaTeX Language configuration as a dialect of BibTeX.

bibtexCompletion: Extension

BibTeX autocompletion configuration.

bibtexLinter: Extension

BibTeX syntax linter.

About

BibTeX language support for the CodeMirror editor.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages