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

💬 Fix glossary terms with quotes in labels #1034

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fluffy-geese-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-common": patch
---

Remove quotes from label identifiers
5 changes: 5 additions & 0 deletions .changeset/hungry-ghosts-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-cli": patch
---

Fix term label fixing with typography quote enhancements
17 changes: 16 additions & 1 deletion packages/myst-common/src/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from 'vitest';
import { u } from 'unist-builder';
import { liftChildren, mergeTextNodes, toText } from './utils';
import { liftChildren, mergeTextNodes, normalizeLabel, toText } from './utils';

describe('Test text utils', () => {
test('toText', () => {
Expand Down Expand Up @@ -66,3 +66,18 @@ describe('Test liftChildren', () => {
expect(before).toEqual(after);
});
});

describe('Test normalize labels', () => {
test.each([
['test', 'test', 'test'],
['has spaces', 'has spaces', 'has-spaces'],
['has many spaces', 'has many spaces', 'has-many-spaces'],
['colon:Caps', 'colon:caps', 'colon-caps'],
['“MyST’s” ‘influence’', 'mysts influence', 'mysts-influence'],
])('normalize label "%s" -> "%s" (#%s)', (label, identifier, html_id) => {
const result = normalizeLabel(label);
expect(result?.label).toBe(label);
expect(result?.identifier).toBe(identifier);
expect(result?.html_id).toBe(html_id);
});
});
1 change: 1 addition & 0 deletions packages/myst-common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function normalizeLabel(
if (!label) return undefined;
const identifier = label
.replace(/[\t\n\r ]+/g, ' ')
.replace(/['‘’"“”]+/g, '') // These can make matching difficult, especially in glossaries and terms
.trim()
.toLowerCase();
const html_id = createHtmlId(identifier) as string;
Expand Down