Skip to content

Commit

Permalink
✍️ Improve parsing of cite:alp and cite:alps roles (#1495)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 authored Aug 29, 2024
1 parent e0d6e28 commit 63f9265
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/dry-students-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-roles": patch
---

Improve the parsing of `cite:alp`
15 changes: 15 additions & 0 deletions packages/myst-roles/src/cite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ describe('cite roles', () => {
},
],
],
['cite:alp', '1987:nelson', [{ type: 'cite', kind: 'parenthetical', label: '1987:nelson' }]],
['cite:alps', '1987:nelson', [{ type: 'cite', kind: 'parenthetical', label: '1987:nelson' }]],
[
'cite:authorpar',
'1987:nelson',
[
{
type: 'citeGroup',
kind: 'parenthetical',
children: [
{ type: 'cite', kind: 'parenthetical', label: '1987:nelson', partial: 'author' },
],
},
],
],
[
'cite:p',
'1987:nelson,2001:schechter',
Expand Down
7 changes: 6 additions & 1 deletion packages/myst-roles/src/cite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export const citeRole: RoleSpec = {
const content = data.body as string;
const labels = content.split(/[,;]/).map((s) => s.trim());
const kind: CiteKind =
data.name.startsWith('cite:p') || data.name.includes('par') ? 'parenthetical' : 'narrative';
data.name.startsWith('cite:p') || data.name.includes('par') || data.name.includes('cite:alp')
? 'parenthetical'
: 'narrative';
const children = labels.map((c) => {
// {cite:p}`{see}1977:nelson{p. 1166}`
const groups = /^(?:\{([^{]*)\})?([^{]*)(?:\{([^{]*)\})?$/;
Expand All @@ -59,6 +61,9 @@ export const citeRole: RoleSpec = {
if (data.name === 'cite' && children.length === 1) {
return children;
}
if (data.name.includes('cite:alp')) {
return children;
}
return [
{
type: 'citeGroup',
Expand Down

0 comments on commit 63f9265

Please sign in to comment.