Add improved JSDoc

This commit is contained in:
Titus Wormer 2023-03-30 15:09:23 +02:00
parent 34c7cf81fe
commit 0b9798c48c
No known key found for this signature in database
GPG key ID: E6E581152ED04E2E
3 changed files with 39 additions and 11 deletions

View file

@ -6,22 +6,40 @@
/** /**
* @typedef {[string, string]} Attribute * @typedef {[string, string]} Attribute
* @typedef {'containerDirective' | 'leafDirective' | 'textDirective'} DirectiveType * Internal tuple representing an attribute.
* */
* @typedef Directive
* @property {DirectiveType} type /**
* @property {string} name * @typedef {Record<string, Handle>} HtmlOptions
* @property {string | undefined} [label] * Configuration.
* @property {Record<string, string> | undefined} [attributes]
* @property {string | undefined} [content]
* @property {number | undefined} [_fenceCount]
* *
* @callback Handle * @callback Handle
* Handle a directive.
* @param {CompileContext} this * @param {CompileContext} this
* Current context.
* @param {Directive} directive * @param {Directive} directive
* Directive.
* @returns {boolean | void} * @returns {boolean | void}
* Signal that the directive could not be handled, in which case the fallback
* is used (when given: a special handle for `'*'`).
* *
* @typedef {Record<string, Handle>} HtmlOptions * @typedef Directive
* Structure representing a directive
* @property {DirectiveType} type
* Kind.
* @property {string} name
* Name of directive.
* @property {string | undefined} [label]
* Compiled HTML content that was in `[brackets]`.
* @property {Record<string, string> | undefined} [attributes]
* Object w/ HTML attributes.
* @property {string | undefined} [content]
* Compiled HTML content inside container directive.
* @property {number | undefined} [_fenceCount]
* Private :)
*
* @typedef {'containerDirective' | 'leafDirective' | 'textDirective'} DirectiveType
* Kind.
*/ */
import {ok as assert} from 'uvu/assert' import {ok as assert} from 'uvu/assert'
@ -30,8 +48,14 @@ import {parseEntities} from 'parse-entities'
const own = {}.hasOwnProperty const own = {}.hasOwnProperty
/** /**
* Create an extension for `micromark` to support directives when serializing
* to HTML.
*
* @param {HtmlOptions | null | undefined} [options] * @param {HtmlOptions | null | undefined} [options]
* Configuration.
* @returns {HtmlExtension} * @returns {HtmlExtension}
* Extension for `micromark` that can be passed in `htmlExtensions`, to
* support directives when serializing to HTML.
*/ */
export function directiveHtml(options) { export function directiveHtml(options) {
const options_ = options || {} const options_ = options || {}

View file

@ -8,7 +8,11 @@ import {directiveLeaf} from './directive-leaf.js'
import {directiveText} from './directive-text.js' import {directiveText} from './directive-text.js'
/** /**
* Create an extension for `micromark` to enable directive syntax.
*
* @returns {Extension} * @returns {Extension}
* Extension for `micromark` that can be passed in `extensions`, to
* enable directive syntax.
*/ */
export function directive() { export function directive() {
return { return {

View file

@ -116,7 +116,7 @@ be handled, in which case the fallback is used (when given).
### `Directive` ### `Directive`
An object representing a directive. Structure representing a directive.
###### Fields ###### Fields