-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✍️ Abbreviations First Time Long (ftl) (#530)
* use `rimraf` instead of `rm -rf` * Adding the First Time Long (`firstTimeLong`) option to abbreviations * Also added some additional testing for abbreviations (moved to tests folder with yaml cases) --------- Co-authored-by: Rowan Cockett <rowanc1@gmail.com>
- Loading branch information
1 parent
fee1eea
commit 30da1da
Showing
16 changed files
with
170 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'myst-transforms': minor | ||
--- | ||
|
||
Add `firstTimeLong` option to the abbreviations transform to expand the abbreviation the first time it is encountered. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import yaml from 'js-yaml'; | ||
import type { Root } from 'mdast'; | ||
import { abbreviationTransform, ReferenceState } from '../src'; | ||
|
||
type TestFile = { | ||
cases: TestCase[]; | ||
}; | ||
type TestCase = { | ||
title: string; | ||
before: Root; | ||
after: Root; | ||
opts?: Record<string, boolean>; | ||
}; | ||
|
||
const fixtures = path.join('tests', 'abbreviations.yml'); | ||
|
||
const testYaml = fs.readFileSync(fixtures).toString(); | ||
const cases = (yaml.load(testYaml) as TestFile).cases; | ||
|
||
describe('abbreviate', () => { | ||
test.each(cases.map((c): [string, TestCase] => [c.title, c]))( | ||
'%s', | ||
(_, { before, after, opts }) => { | ||
abbreviationTransform(before as Root, opts); | ||
|
||
expect(yaml.dump(before)).toEqual(yaml.dump(after)); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
cases: | ||
- title: simple abbreviation replacement | ||
opts: | ||
abbreviations: | ||
MyST: Markedly Structured Text | ||
before: | ||
type: root | ||
children: | ||
- type: blockquote | ||
children: | ||
- type: paragraph | ||
children: | ||
- type: link | ||
children: | ||
- type: text | ||
value: Link with MyST in it | ||
- type: text | ||
value: This is about MyST Markdown | ||
after: | ||
type: root | ||
children: | ||
- type: blockquote | ||
children: | ||
- type: paragraph | ||
children: | ||
- type: link | ||
children: | ||
- type: text | ||
value: Link with MyST in it | ||
- type: text | ||
value: 'This is about ' | ||
- type: abbreviation | ||
title: Markedly Structured Text | ||
children: | ||
- type: text | ||
value: MyST | ||
- type: text | ||
value: ' Markdown' | ||
- title: Abbreviation in heading | ||
opts: | ||
abbreviations: | ||
MyST: Markedly Structured Text | ||
before: | ||
type: root | ||
children: | ||
- type: heading | ||
depth: 1 | ||
children: | ||
- type: text | ||
value: Testing MyST | ||
after: | ||
type: root | ||
children: | ||
- type: heading | ||
depth: 1 | ||
children: | ||
- type: text | ||
value: 'Testing ' | ||
- type: abbreviation | ||
title: Markedly Structured Text | ||
children: | ||
- type: text | ||
value: MyST | ||
- title: Abbreviation first time long | ||
opts: | ||
firstTimeLong: true | ||
abbreviations: | ||
MyST: Markedly Structured Text | ||
before: | ||
type: root | ||
children: | ||
- type: text | ||
value: 'Testing MyST does it render out long? Does MyST now?' | ||
- type: text | ||
value: 'or maybe now: MyST?' | ||
after: | ||
type: root | ||
children: | ||
- type: text | ||
value: 'Testing ' | ||
- type: abbreviation | ||
title: Markedly Structured Text | ||
children: | ||
- type: text | ||
value: Markedly Structured Text (MyST) | ||
- type: text | ||
value: ' does it render out long? Does ' | ||
- type: abbreviation | ||
title: Markedly Structured Text | ||
children: | ||
- type: text | ||
value: MyST | ||
- type: text | ||
value: ' now?' | ||
- type: text | ||
value: 'or maybe now: ' | ||
- type: abbreviation | ||
title: Markedly Structured Text | ||
children: | ||
- type: text | ||
value: MyST | ||
- type: text | ||
value: '?' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters