Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: micromark/micromark-extension-directive
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.1.0
Choose a base ref
...
head repository: micromark/micromark-extension-directive
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
Showing with 2,389 additions and 1,558 deletions.
  1. +4 −4 .editorconfig
  2. +6 −6 .github/workflows/bb.yml
  3. +8 −8 .github/workflows/main.yml
  4. +6 −3 .gitignore
  5. +1 −0 .npmrc
  6. +156 −0 dev/index.d.ts
  7. +1 −5 dev/index.js
  8. +69 −40 dev/lib/directive-container.js
  9. +15 −9 dev/lib/directive-leaf.js
  10. +21 −13 dev/lib/directive-text.js
  11. +63 −51 dev/lib/factory-attributes.js
  12. +45 −52 dev/lib/factory-label.js
  13. +30 −20 dev/lib/factory-name.js
  14. +100 −77 dev/lib/html.js
  15. +6 −2 dev/lib/syntax.js
  16. +1 −1 license
  17. +74 −45 package.json
  18. +222 −86 readme.md
  19. +1,551 −1,126 test/index.js
  20. +10 −10 tsconfig.json
8 changes: 4 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
12 changes: 6 additions & 6 deletions .github/workflows/bb.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: bb
on:
issues:
types: [opened, reopened, edited, closed, labeled, unlabeled]
pull_request_target:
types: [opened, reopened, edited, closed, labeled, unlabeled]
jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: unifiedjs/beep-boop-beta@main
with:
repo-token: ${{secrets.GITHUB_TOKEN}}
name: bb
on:
issues:
types: [closed, edited, labeled, opened, reopened, unlabeled]
pull_request_target:
types: [closed, edited, labeled, opened, reopened, unlabeled]
16 changes: 8 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: main
on:
- pull_request
- push
jobs:
main:
name: ${{matrix.node}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dcodeIO/setup-node-nvm@master
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{matrix.node}}
- run: npm install
- run: npm test
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v5
strategy:
matrix:
node:
- lts/erbium
- lts/hydrogen
- node
name: main
on:
- pull_request
- push
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.DS_Store
*.d.ts
*.log
*.map
*.tsbuildinfo
.DS_Store
/index.js
/lib/
coverage/
node_modules/
/lib/
/index.js
yarn.lock
!dev/index.d.ts
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ignore-scripts=true
package-lock=false
156 changes: 156 additions & 0 deletions dev/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import type {CompileContext} from 'micromark-util-types'

export {directive} from './lib/syntax.js'
export {directiveHtml} from './lib/html.js'

/**
* Internal tuple representing an attribute.
*/
type AttributeTuple = [key: string, value: string]

/**
* Directive attribute.
*/
interface Attributes {
/**
* Key to value.
*/
[key: string]: string
}

/**
* Structure representing a directive.
*/
export interface Directive {
/**
* Private :)
*/
_fenceCount?: number | undefined
/**
* Object w/ HTML attributes.
*/
attributes?: Attributes | undefined
/**
* Compiled HTML content inside container directive.
*/
content?: string | undefined
/**
* Compiled HTML content that was in `[brackets]`.
*/
label?: string | undefined
/**
* Name of directive.
*/
name: string
/**
* Kind.
*/
type: 'containerDirective' | 'leafDirective' | 'textDirective'
}

/**
* Handle a directive.
*
* @param this
* Current context.
* @param directive
* Directive.
* @returns
* Signal whether the directive was handled.
*
* Yield `false` to let the fallback (a special handle for `'*'`) handle it.
*/
export type Handle = (
this: CompileContext,
directive: Directive
) => boolean | undefined

/**
* Configuration.
*
* > 👉 **Note**: the special field `'*'` can be used to specify a fallback
* > handle to handle all otherwise unhandled directives.
*/
export interface HtmlOptions {
[name: string]: Handle
}

/**
* Augment types.
*/
declare module 'micromark-util-types' {
/**
* Compile data.
*/
interface CompileData {
directiveAttributes?: Array<AttributeTuple>
directiveStack?: Array<Directive>
}

/**
* Token types.
*/
interface TokenTypeMap {
directiveContainer: 'directiveContainer'
directiveContainerAttributes: 'directiveContainerAttributes'
directiveContainerAttributesMarker: 'directiveContainerAttributesMarker'
directiveContainerAttribute: 'directiveContainerAttribute'
directiveContainerAttributeId: 'directiveContainerAttributeId'
directiveContainerAttributeIdValue: 'directiveContainerAttributeIdValue'
directiveContainerAttributeClass: 'directiveContainerAttributeClass'
directiveContainerAttributeClassValue: 'directiveContainerAttributeClassValue'
directiveContainerAttributeName: 'directiveContainerAttributeName'
directiveContainerAttributeInitializerMarker: 'directiveContainerAttributeInitializerMarker'
directiveContainerAttributeValueLiteral: 'directiveContainerAttributeValueLiteral'
directiveContainerAttributeValue: 'directiveContainerAttributeValue'
directiveContainerAttributeValueMarker: 'directiveContainerAttributeValueMarker'
directiveContainerAttributeValueData: 'directiveContainerAttributeValueData'
directiveContainerContent: 'directiveContainerContent'
directiveContainerFence: 'directiveContainerFence'
directiveContainerLabel: 'directiveContainerLabel'
directiveContainerLabelMarker: 'directiveContainerLabelMarker'
directiveContainerLabelString: 'directiveContainerLabelString'
directiveContainerName: 'directiveContainerName'
directiveContainerSequence: 'directiveContainerSequence'

directiveLeaf: 'directiveLeaf'
directiveLeafAttributes: 'directiveLeafAttributes'
directiveLeafAttributesMarker: 'directiveLeafAttributesMarker'
directiveLeafAttribute: 'directiveLeafAttribute'
directiveLeafAttributeId: 'directiveLeafAttributeId'
directiveLeafAttributeIdValue: 'directiveLeafAttributeIdValue'
directiveLeafAttributeClass: 'directiveLeafAttributeClass'
directiveLeafAttributeClassValue: 'directiveLeafAttributeClassValue'
directiveLeafAttributeName: 'directiveLeafAttributeName'
directiveLeafAttributeInitializerMarker: 'directiveLeafAttributeInitializerMarker'
directiveLeafAttributeValueLiteral: 'directiveLeafAttributeValueLiteral'
directiveLeafAttributeValue: 'directiveLeafAttributeValue'
directiveLeafAttributeValueMarker: 'directiveLeafAttributeValueMarker'
directiveLeafAttributeValueData: 'directiveLeafAttributeValueData'
directiveLeafLabel: 'directiveLeafLabel'
directiveLeafLabelMarker: 'directiveLeafLabelMarker'
directiveLeafLabelString: 'directiveLeafLabelString'
directiveLeafName: 'directiveLeafName'
directiveLeafSequence: 'directiveLeafSequence'

directiveText: 'directiveText'
directiveTextAttributes: 'directiveTextAttributes'
directiveTextAttributesMarker: 'directiveTextAttributesMarker'
directiveTextAttribute: 'directiveTextAttribute'
directiveTextAttributeId: 'directiveTextAttributeId'
directiveTextAttributeIdValue: 'directiveTextAttributeIdValue'
directiveTextAttributeClass: 'directiveTextAttributeClass'
directiveTextAttributeClassValue: 'directiveTextAttributeClassValue'
directiveTextAttributeName: 'directiveTextAttributeName'
directiveTextAttributeInitializerMarker: 'directiveTextAttributeInitializerMarker'
directiveTextAttributeValueLiteral: 'directiveTextAttributeValueLiteral'
directiveTextAttributeValue: 'directiveTextAttributeValue'
directiveTextAttributeValueMarker: 'directiveTextAttributeValueMarker'
directiveTextAttributeValueData: 'directiveTextAttributeValueData'
directiveTextLabel: 'directiveTextLabel'
directiveTextLabelMarker: 'directiveTextLabelMarker'
directiveTextLabelString: 'directiveTextLabelString'
directiveTextMarker: 'directiveTextMarker'
directiveTextName: 'directiveTextName'
}
}
6 changes: 1 addition & 5 deletions dev/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @typedef {import('./lib/html.js').Handle} Handle
* @typedef {import('./lib/html.js').HtmlOptions} HtmlOptions
*/

// Note: more types exported from `index.d.ts`.
export {directive} from './lib/syntax.js'
export {directiveHtml} from './lib/html.js'
Loading