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

🖲 [Spike] Add button role #1773

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions packages/myst-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"myst-common": "^1.7.6",
"myst-config": "^1.7.6",
"myst-execute": "^0.1.2",
"myst-ext-button": "^0.0.0",
"myst-ext-card": "^1.0.9",
"myst-ext-exercise": "^1.0.9",
"myst-ext-grid": "^1.0.9",
Expand Down
6 changes: 5 additions & 1 deletion packages/myst-cli/src/process/myst.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mystParse } from 'myst-parser';
import { buttonRole } from 'myst-ext-button';
import { cardDirective } from 'myst-ext-card';
import { gridDirectives } from 'myst-ext-grid';
import { proofDirective } from 'myst-ext-proof';
Expand Down Expand Up @@ -47,7 +48,10 @@ export function parseMyst(
extensions: {
frontmatter: !opts?.ignoreFrontmatter,
},
roles: [...(session.plugins?.roles ?? [])],
roles: [
buttonRole,
...(session.plugins?.roles ?? [])
],
vfile,
});
logMessagesFromVFile(session, vfile);
Expand Down
37 changes: 0 additions & 37 deletions packages/myst-directives/src/button.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/myst-directives/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { admonitionDirective } from './admonition.js';
import { buttonDirective } from './button.js';
import { bibliographyDirective } from './bibliography.js';
import { codeDirective, codeCellDirective } from './code.js';
import { dropdownDirective } from './dropdown.js';
Expand All @@ -22,7 +21,6 @@ import { divDirective } from './div.js';

export const defaultDirectives = [
admonitionDirective,
buttonDirective,
bibliographyDirective,
csvTableDirective,
codeDirective,
Expand Down Expand Up @@ -52,7 +50,6 @@ export const defaultDirectives = [

export * from './utils.js';
export { admonitionDirective } from './admonition.js';
export { buttonDirective } from './button.js';
export { bibliographyDirective } from './bibliography.js';
export { codeDirective } from './code.js';
export { dropdownDirective } from './dropdown.js';
Expand Down
4 changes: 4 additions & 0 deletions packages/myst-ext-button/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['curvenote'],
};
125 changes: 125 additions & 0 deletions packages/myst-ext-button/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# myst-ext-card
jnywong marked this conversation as resolved.
Show resolved Hide resolved

## 1.0.9

### Patch Changes

- ce3c11c: Update inter-version deps

## 1.0.8

### Patch Changes

- c758f1b5: Directive option flag is always a boolean
- 0a516e5: Add documentation and an alias for url/link in cards.

## 1.0.7

### Patch Changes

- b3e9df9d: Update to Project Jupyter and change all URLs
- Updated dependencies [b3e9df9d]
- myst-common@1.5.1

## 1.0.6

### Patch Changes

- 69457615: Update dependencies
- Updated dependencies [e0cd47e3]
- myst-common@1.3.0

## 1.0.5

### Patch Changes

- 6354420: Update versions of myst packages

## 1.0.4

### Patch Changes

- 4183c05c: Change to use String/Number/Boolean instead of ParsedEnumType
- d35e02bc: Change from alias as string to alias as a string-list.
- Updated dependencies [d35e02bc]
- Updated dependencies [b74fb3c1]
- Updated dependencies [ed7b430f]
- Updated dependencies [239ae762]
- Updated dependencies [b74fb3c1]
- Updated dependencies [86c78957]
- Updated dependencies [d35e02bc]
- Updated dependencies [d35e02bc]
- Updated dependencies [99659250]
- myst-common@1.1.7

## 1.0.3

### Patch Changes

- 7752cb70: Bump dependency versions
- Updated dependencies [7752cb70]
- myst-common@1.1.5

## 1.0.2

### Patch Changes

- Updates to internal dependencies
- Updated dependencies [44ff6917]
- Updated dependencies
- myst-common@1.1.0

## 1.0.1

### Patch Changes

- b0a2a34b: Move repositories from mystjs --> mystmd
- Updated dependencies [b0a2a34b]
- myst-common@1.0.2

## 1.0.0

### Major Changes

- 00c05fe9: Migrate to ESM modules

## 0.0.7

### Patch Changes

- Updated dependencies [79e24fd7]
- myst-common@0.0.17

## 0.0.6

### Patch Changes

- Updated dependencies [d28b5e9d]
- myst-common@0.0.16

## 0.0.5

### Patch Changes

- Updated dependencies [c832b38e]
- myst-common@0.0.15

## 0.0.4

### Patch Changes

- Updated dependencies [9105d991]
- myst-common@0.0.14

## 0.0.3

### Patch Changes

- Updated dependencies
- myst-common@0.0.13

## 0.0.2

### Patch Changes

- a22fafa0: Separate packages for card/tab/grid/reactive roles/directives
3 changes: 3 additions & 0 deletions packages/myst-ext-button/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# myst-ext-button

`mystmd` extension for `button` role
41 changes: 41 additions & 0 deletions packages/myst-ext-button/package.json
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"
}
}
30 changes: 30 additions & 0 deletions packages/myst-ext-button/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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',
Comment on lines +20 to +21
Copy link
Member

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.

url,
children: [],
};
if (modified) node.children = [{ type: 'text', value: modified.trim() }];
return [
node
];
},
};
Empty file.
8 changes: 8 additions & 0 deletions packages/myst-ext-button/tsconfig.json
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"]
}
Loading