-
Notifications
You must be signed in to change notification settings - Fork 69
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
🖲 [Spike] Add button
role
#1773
Open
jnywong
wants to merge
7
commits into
jupyter-book:main
Choose a base branch
from
jnywong:add-button
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+136
−1
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8910510
Add button directive
jnywong 9a8dae9
Update index.ts
jnywong 413f706
Change from directive to role
jnywong 3a3feea
Delete changelog
jnywong b68fb3b
Fix linting
jnywong 2f73571
Remove test
jnywong 3b0795e
Add buttonRoles test
jnywong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,4 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ['curvenote'], | ||
}; |
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,3 @@ | ||
# myst-ext-button | ||
|
||
`mystmd` extension for `button` role |
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,41 @@ | ||
{ | ||
"name": "myst-ext-button", | ||
"version": "0.0.0", | ||
"sideEffects": false, | ||
"license": "MIT", | ||
"description": "MyST extension for button role", | ||
"author": "Jenny Wong <jwong@2i2c.org>", | ||
"homepage": "https://github.com/jupyter-book/mystmd/tree/main/packages/myst-ext-button", | ||
"type": "module", | ||
"exports": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/jupyter-book/mystmd.git" | ||
}, | ||
"scripts": { | ||
"clean": "rimraf dist", | ||
"lint": "eslint \"src/**/!(*.spec).ts\" -c ./.eslintrc.cjs", | ||
"lint:format": "npx prettier --check \"src/**/*.ts\"", | ||
"test": "vitest run", | ||
"test:watch": "vitest watch", | ||
"build:esm": "tsc", | ||
"build": "npm-run-all -l clean -p build:esm" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/jupyter-book/mystmd/issues" | ||
}, | ||
"dependencies": { | ||
"myst-common": "^1.7.2", | ||
"myst-spec-ext": "^1.7.6" | ||
}, | ||
"devDependencies": { | ||
"myst-parser": "^1.5.7" | ||
} | ||
} |
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,28 @@ | ||
import type { RoleSpec, RoleData, GenericNode } from 'myst-common'; | ||
import type { Link } from 'myst-spec-ext'; | ||
|
||
const REF_PATTERN = /^(.+?)<([^<>]+)>$/; | ||
|
||
export const buttonRole: RoleSpec = { | ||
name: 'button', | ||
doc: 'Button to navigate to external or internal links.', | ||
body: { | ||
type: String, | ||
doc: 'The body of the button.', | ||
required: true, | ||
}, | ||
run(data: RoleData): GenericNode[] { | ||
const body = data.body as string; | ||
const match = REF_PATTERN.exec(body); | ||
const [, modified, rawLabel] = match ?? []; | ||
const url = rawLabel ?? body; | ||
const node: Link = { | ||
type: 'link', | ||
kind: 'button', | ||
url, | ||
children: [], | ||
}; | ||
if (modified) node.children = [{ type: 'text', value: modified.trim() }]; | ||
return [node]; | ||
}, | ||
}; |
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,31 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { buttonRole } from '../src'; | ||
import type { RoleData } from 'myst-common'; | ||
|
||
describe('Button component', () => { | ||
it('should process button role correctly', () => { | ||
const data: RoleData = { body: 'Click me<http://example.com>' }; | ||
const result = buttonRole.run(data); | ||
expect(result).toEqual([ | ||
{ | ||
type: 'link', | ||
kind: 'button', | ||
url: 'http://example.com', | ||
children: [{ type: 'text', value: 'Click me' }], | ||
}, | ||
]); | ||
}); | ||
|
||
it('should process button role without label correctly', () => { | ||
const data: RoleData = { body: 'http://example.com' }; | ||
const result = buttonRole.run(data); | ||
expect(result).toEqual([ | ||
{ | ||
type: 'link', | ||
kind: 'button', | ||
url: 'http://example.com', | ||
children: [], | ||
}, | ||
]); | ||
}); | ||
}); |
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,8 @@ | ||
{ | ||
"extends": "../tsconfig/base.json", | ||
"compilerOptions": { | ||
"outDir": "dist" | ||
}, | ||
"include": ["."], | ||
"exclude": ["dist", "build", "node_modules", "src/**/*.spec.ts", "tests"] | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice - this means there is a good fallback.