feat: Rename fallback option and option section
Options now reside under the 'plugins.bbt' section (instead of 'plugins.bbt-formatter'). The 'fallback' option has been renamed 'default-formatter' to signify its purpose a little better - even if it will be rarely changed in all likelihood.
This commit is contained in:
parent
a076880913
commit
39ba0f5508
2 changed files with 28 additions and 28 deletions
33
README.md
33
README.md
|
|
@ -1,7 +1,8 @@
|
|||
# papis-bbt-formatter
|
||||
|
||||
Formats reference keys in papis similarly to the (zotero plugin) `better-bibtex` keys, in the format `Name2008TitleShort`.
|
||||
## Installation:
|
||||
|
||||
## Installation
|
||||
|
||||
<!-- TODO set up pypi repository / explain git install path -->
|
||||
You can install from pypi with `pip install git+https://git.martyoeh.me/Marty/papis-bbt-formatter.git`.
|
||||
|
|
@ -16,14 +17,14 @@ In your papis configuration file (usually `~/.config/papis/config`), add the fol
|
|||
```cfg
|
||||
[settings]
|
||||
formater = bbt
|
||||
ref-format = bbt
|
||||
ref-format = bbt:
|
||||
```
|
||||
|
||||
For now, the ref-format also *has* to start with `bbt`.
|
||||
For now, the ref-format also *has* to start with `bbt`.
|
||||
|
||||
Formatted reference keys by default will look like:
|
||||
|
||||
`Harvey05briefhistoryneoliberalism` (for Harvey, D. (2005). A brief history of neoliberalism. Oxford New York: Oxford University Press.)
|
||||
`Harvey05briefhistoryneoliberalism` (for Harvey, D. (2005). A brief history of neoliberalism. Oxford New York: Oxford University Press.)
|
||||
|
||||
or `Harvey22reflectionsacademiclife` (for Harvey, D. (2022). Reflections on an academic life. Human Geography, 15, 14–24. doi:10.1177/19427786211046291)
|
||||
|
||||
|
|
@ -38,8 +39,8 @@ Listed below are all options with their defaults:
|
|||
formater = bbt
|
||||
ref-format = bbt
|
||||
|
||||
[plugins.bbt-formatter]
|
||||
fallback = python
|
||||
[plugins.bbt]
|
||||
default-formatter = python
|
||||
full-year = False
|
||||
title-words = 4
|
||||
title-chars = -1
|
||||
|
|
@ -50,7 +51,7 @@ title-chars = -1
|
|||
You can specifiy whether the reference should contain the full 4-digit year representation (i.e. `1997`, `2018`) or just a shortened 2-digit version (`97`, `18`):
|
||||
|
||||
```cfg
|
||||
[plugins.bbt-formatter]
|
||||
[plugins.bbt]
|
||||
full-year = True
|
||||
```
|
||||
|
||||
|
|
@ -59,12 +60,12 @@ This will insert the full 4-digit publication year instead of the (default) shor
|
|||
### Title length
|
||||
|
||||
You can change the length that the `TitleShort` in `Name2008TitleShort` will be cut down to by setting
|
||||
the maximum length in words `title-words=4` or in characters `title-chars=20` under the `[plugins.bbt-formatter]` section in your papis configuration file (usually located at `~/.config/papis/config`).
|
||||
the maximum length in words `title-words=4` or in characters `title-chars=20` under the `[plugins.bbt]` section in your papis configuration file (usually located at `~/.config/papis/config`).
|
||||
|
||||
To set a maximum word length, do:
|
||||
|
||||
```cfg
|
||||
[plugins.bbt-formatter]
|
||||
[plugins.bbt]
|
||||
title-words = 4
|
||||
```
|
||||
|
||||
|
|
@ -73,7 +74,7 @@ change the number to shorten/lengthen to your preference.
|
|||
Same idea for maximum character length:
|
||||
|
||||
```cfg
|
||||
[plugins.bbt-formatter]
|
||||
[plugins.bbt]
|
||||
title-chars = 10
|
||||
```
|
||||
|
||||
|
|
@ -81,7 +82,7 @@ This will allow a maximum of 10 characters for the title.
|
|||
Using both:
|
||||
|
||||
```cfg
|
||||
[plugins.bbt-formatter]
|
||||
[plugins.bbt]
|
||||
title-words = 4
|
||||
title-chars = 20
|
||||
```
|
||||
|
|
@ -90,22 +91,22 @@ This will ensure a maximum of 4 words, however if they go more than 20 character
|
|||
You can set either option to `-1` to turn it off:
|
||||
|
||||
```cfg
|
||||
[plugins.bbt-formatter]
|
||||
[plugins.bbt]
|
||||
title-words = 4
|
||||
title-chars = -1
|
||||
```
|
||||
|
||||
This will ensure that a maximum of 4 words will be placed in the ref, but they do not have a maximum character length,
|
||||
This will ensure that a maximum of 4 words will be placed in the ref, but they do not have a maximum character length,
|
||||
so will always be fully written out (the default behavior if no title length options are provided).
|
||||
|
||||
### Fallback formatter
|
||||
|
||||
For anything that is not a reference, use this formatter.
|
||||
For anything that is not a reference, use this formatter.
|
||||
Basically, put the formatter you had before switching to bbt here:
|
||||
|
||||
```cfg
|
||||
[plugins.bbt-formatter]
|
||||
fallback = jinja2
|
||||
[plugins.bbt]
|
||||
default-formatter = jinja2
|
||||
```
|
||||
|
||||
Can be any of the installed papis formatters, including custom ones
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@ import papis.logging
|
|||
|
||||
logger = papis.logging.get_logger(__name__)
|
||||
|
||||
OPTIONS_SECTION = "plugins.bbt"
|
||||
DEFAULT_OPTIONS = {
|
||||
"plugins.bbt-formatter": {
|
||||
"fallback": "python",
|
||||
OPTIONS_SECTION: {
|
||||
"default-formatter": "python",
|
||||
"title-words": 3,
|
||||
"title-chars": -1,
|
||||
}
|
||||
|
|
@ -30,13 +31,8 @@ class BBTFormatter(papis.format.Formatter):
|
|||
additional: dict[str, Any] | None = None,
|
||||
default: str | None = None,
|
||||
) -> str:
|
||||
if fmt.startswith("bbt"):
|
||||
formatted = self.use_bbt(doc)
|
||||
return formatted
|
||||
else:
|
||||
fallback_formatter = papis.config.getstring(
|
||||
"fallback", "plugins.bbt-formatter"
|
||||
)
|
||||
if not fmt.startswith("bbt:"):
|
||||
fallback_formatter = papis.config.getstring("default-formatter", OPTIONS_SECTION)
|
||||
|
||||
# NOTE sure would be nice to have a less hacky way of calling another formatter
|
||||
_saved = papis.format.FORMATTER
|
||||
|
|
@ -49,6 +45,9 @@ class BBTFormatter(papis.format.Formatter):
|
|||
papis.format.FORMATTER = _saved
|
||||
return fallback_formatted
|
||||
|
||||
formatted = self.use_bbt(doc)
|
||||
return formatted
|
||||
|
||||
def use_bbt(self, doc: papis.document.DocumentLike) -> str:
|
||||
author_unfmt = (
|
||||
doc["author_list"][0]["family"]
|
||||
|
|
@ -67,7 +66,7 @@ class BBTFormatter(papis.format.Formatter):
|
|||
|
||||
Returns either the full 4-digit year or a shortened 2-digit
|
||||
version depending on the plugin year options."""
|
||||
if papis.config.getboolean("full-year", "plugins.bbt-formatter"):
|
||||
if papis.config.getboolean("full-year", OPTIONS_SECTION):
|
||||
return str(year)
|
||||
return str(year)[-2:]
|
||||
|
||||
|
|
@ -83,8 +82,8 @@ class BBTFormatter(papis.format.Formatter):
|
|||
filter(lambda word: word and word not in SKIP_WORDS, title.split()),
|
||||
)
|
||||
)
|
||||
wlen = papis.config.getint("title-words", "plugins.bbt-formatter")
|
||||
clen = papis.config.getint("title-chars", "plugins.bbt-formatter")
|
||||
wlen = papis.config.getint("title-words", OPTIONS_SECTION)
|
||||
clen = papis.config.getint("title-chars", OPTIONS_SECTION)
|
||||
wlen = None if wlen == -1 else wlen
|
||||
clen = None if clen == -1 else clen
|
||||
title = "".join(title_words[:wlen])[:clen]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue