CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
association.js34 linesDownload Raw Back to util
1/**2 * @import {AssociationId} from '../types.js'3 */4 5import {decodeString} from 'micromark-util-decode-string'6 7/**8 * Get an identifier from an association to match it to others.9 *10 * Associations are nodes that match to something else through an ID:11 * <https://github.com/syntax-tree/mdast#association>.12 *13 * The `label` of an association is the string value: character escapes and14 * references work, and casing is intact.15 * The `identifier` is used to match one association to another:16 * controversially, character escapes and references don’t work in this17 * matching: `&copy;` does not match `©`, and `\+` does not match `+`.18 *19 * But casing is ignored (and whitespace) is trimmed and collapsed: ` A\nb`20 * matches `a b`.21 * So, we do prefer the label when figuring out how we’re going to serialize:22 * it has whitespace, casing, and we can ignore most useless character23 * escapes and all character references.24 *25 * @type {AssociationId}26 */27export function association(node) {28  if (node.label || !node.identifier) {29    return node.label || ''30  }31 32  return decodeString(node.identifier)33}34