Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add field exclusion list to drop-all-caps #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ bibtex-tidy references.bib
Where values are all caps, make them title case. For example, {JOURNAL OF
TEA} will become {Journal of Tea}.

Fields can be excluded.

Examples:
--sort-fields=publisher,volume

--escape, --no-escape
Escape special characters, such as umlaut. This ensures correct typesetting
with latex. Enabled by default.
Expand Down
5 changes: 5 additions & 0 deletions bibtex-tidy.0
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ OPTIONS
Where values are all caps, make them title case. For
example, {JOURNAL OF TEA} will become {Journal of Tea}.

Fields can be excluded.

Examples:
--sort-fields=publisher,volume

--escape, --no-escape
Escape special characters, such as umlaut. This ensures
correct typesetting with latex. Enabled by default.
Expand Down
3 changes: 2 additions & 1 deletion bibtex-tidy.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ export declare type BibTeXTidyOptions = {
* Drop all caps
*
* Where values are all caps, make them title case. For example, {JOURNAL OF TEA} will become {Journal of Tea}.
* Fields can be excluded.
*/
dropAllCaps?: boolean;
dropAllCaps?: boolean | string[];
/**
* Escape special characters
*
Expand Down
13 changes: 9 additions & 4 deletions bibtex-tidy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 17 additions & 4 deletions bin/bibtex-tidy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions docs/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ <h1>BibTeX Tidy</h1>
<label data-option="dropAllCaps">
<input type="checkbox" />
<span class="name"></span>
<div class="suboptions">
Fields to exclude: <br />
<textarea name="excludeDropAllCapsList" spellcheck="false"></textarea>
<br />
Space delimited, e.g: <code>publisher volume</code>
</div>
</label>
<label data-option="escape">
<input type="checkbox" />
Expand Down
7 changes: 6 additions & 1 deletion docs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ function getOptions(): Options {
options.enclosingBracesList.value.length > 0 &&
options.enclosingBracesList.value.split(/[\n\t ,]+/),
stripEnclosingBraces: options.stripEnclosingBraces.checked,
dropAllCaps: options.dropAllCaps.checked,
dropAllCaps:
options.dropAllCaps.checked &&
(options.excludeDropAllCapsList.value.split(/[\n\t ,]+/).filter(Boolean)
.length === 0
? true
: options.excludeDropAllCapsList.value.split(/[\n\t ,]+/)),
sortFields:
options.sortFields.checked &&
options.sortFieldList.value.length > 0 &&
Expand Down
5 changes: 5 additions & 0 deletions src/__generated__/manPage.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/__generated__/optionsType.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ export function formatValue(
}
// if a field's value is all caps, convert it to title case
if (dropAllCaps && !value.match(/[a-z]/)) {
value = titleCase(value);
value =
Array.isArray(dropAllCaps) && dropAllCaps.includes(nameLowerCase)
? value
: titleCase(value);
}
// url encode must happen before escape special characters
if (nameLowerCase === 'url' && encodeUrls) {
Expand Down
11 changes: 9 additions & 2 deletions src/optionDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,19 @@ export const optionDefinitions: OptionDefinition[] = [
{
key: 'dropAllCaps',
cli: { '--drop-all-caps': true },
toCLI: (val) => (val ? '--drop-all-caps' : undefined),
toCLI: (val) => {
if (Array.isArray(val) && val.length > 0)
return `--drop-all-caps=${val.join(',')}`;
if (val === true) return '--drop-all-caps';
return undefined;
},
title: 'Drop all caps',
description: [
'Where values are all caps, make them title case. For example, {JOURNAL OF TEA} will become {Journal of Tea}.',
'Fields can be excluded.',
],
type: 'boolean',
examples: ['--sort-fields=publisher,volume'],
type: 'boolean | string[]',
defaultValue: false,
},
{
Expand Down
2 changes: 2 additions & 0 deletions src/optionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type OptionsNormalized = Omit<
| 'align'
| 'merge'
| 'sort'
| 'dropAllCaps'
| 'sortFields'
| 'wrap'
| 'enclosingBraces'
Expand All @@ -32,6 +33,7 @@ export type OptionsNormalized = Omit<
sort?: string[];
space: number;
sortFields?: string[];
dropAllCaps: string[];
merge?: MergeStrategy;
duplicates?: UniqueKey[];
wrap?: number;
Expand Down