CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
join.js40 linesDownload Raw Back to lib
1/**2 * @import {Join} from 'mdast-util-to-markdown'3 */4 5import {formatCodeAsIndented} from './util/format-code-as-indented.js'6import {formatHeadingAsSetext} from './util/format-heading-as-setext.js'7 8/** @type {Array<Join>} */9export const join = [joinDefaults]10 11/** @type {Join} */12function joinDefaults(left, right, parent, state) {13  // Indented code after list or another indented code.14  if (15    right.type === 'code' &&16    formatCodeAsIndented(right, state) &&17    (left.type === 'list' ||18      (left.type === right.type && formatCodeAsIndented(left, state)))19  ) {20    return false21  }22 23  // Join children of a list or an item.24  // In which case, `parent` has a `spread` field.25  if ('spread' in parent && typeof parent.spread === 'boolean') {26    if (27      left.type === 'paragraph' &&28      // Two paragraphs.29      (left.type === right.type ||30        right.type === 'definition' ||31        // Paragraph followed by a setext heading.32        (right.type === 'heading' && formatHeadingAsSetext(right, state)))33    ) {34      return35    }36 37    return parent.spread ? 1 : 038  }39}40