{"version":3,"file":"prettier-plugin-lint-md.cjs","names":[],"sources":["../src/rules.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["export const CONFIG_FILE = {\n  name: 'configFile',\n  description: '配置文件路径',\n  type: 'string',\n};\n\nexport const SPACE_AROUND_ALPHABET = {\n  name: 'space-around-alphabet',\n  description: '中文与英文之间需要增加空格',\n};\n\nexport const SPACE_AROUND_NUMBER = {\n  name: 'space-around-number',\n  description: '中文与数字之间需要增加空格',\n};\n\nexport const NO_EMPTY_CODE_LANG = {\n  name: 'no-empty-code-lang',\n  description: '代码语言不能为空',\n};\n\nexport const NO_EMPTY_URL = {\n  name: 'no-empty-url',\n  description: '链接和图片地址不能为空',\n};\n\nexport const NO_EMPTY_LIST = {\n  name: 'no-empty-list',\n  description: '列表内容不能为空',\n};\n\nexport const NO_EMPTY_CODE = {\n  name: 'no-empty-code',\n  description: '代码块内容不能为空',\n};\n\nexport const NO_EMPTY_INLINE_CODE = {\n  name: 'no-empty-inline-code',\n  description: '行内代码内容不能为空',\n};\n\nexport const NO_EMPTY_BLOCKQUOTE = {\n  name: 'no-empty-blockquote',\n  description: '引用块内容不能为空',\n};\n\nexport const NO_SPECIAL_CHARACTERS = {\n  name: 'no-special-characters',\n  description: '文本中不能有特殊字符',\n};\n\nexport const USE_STANDARD_ELLIPSIS = {\n  name: 'use-standard-ellipsis',\n  description: '使用标准省略号',\n};\n\nexport const NO_FULL_WIDTH_NUMBER = {\n  name: 'no-full-width-number',\n  description: '不能用全角数字',\n};\n\nexport const NO_HALF_WIDTH_PUNCTUATION = {\n  name: 'no-half-width-punctuation',\n  description: '中文语境下不能使用半角标点符号',\n};\n\nexport const NO_SPACE_IN_LINK = {\n  name: 'no-space-in-link',\n  description: '链接前后不能有空格',\n};\n\nexport const NO_MULTIPLE_SPACE_BLOCKQUOTE = {\n  name: 'no-multiple-space-blockquote',\n  description: '引用块头部和内容间只能有一个空格',\n};\n\nexport const CORRECT_TITLE_TRAILING_PUNCTUATION = {\n  name: 'correct-title-trailing-punctuation',\n  description: '标题末尾只能使用合适的标点符号（允许问号、叹号、省略号）',\n};\n\nexport const NO_SPACE_IN_INLINE_CODE = {\n  name: 'no-space-in-inline-code',\n  description: '行内代码内容前后不能有空格',\n};\n","import path from 'node:path';\nimport fs from 'node:fs';\nimport * as rules from './rules';\nimport type { LintOptions } from './types';\nimport type { SupportOptions } from 'prettier';\n\n/**\n * 读取 JSON 文件\n * 如果异常返回 null\n * @param file JSON 路径，可以为绝对地址也可以为相对地址\n * @returns\n */\nexport const readJson = (file: string) => {\n  if (!file) {\n    return null;\n  }\n  const p = path.isAbsolute(file) ? file : path.join(process.cwd(), file);\n  if (!fs.existsSync(p)) {\n    return null;\n  }\n  try {\n    return JSON.parse(fs.readFileSync(p, 'utf-8'));\n  } catch {\n    return null;\n  }\n};\n\n/**\n * 读取配置文件\n *\n * @param {Partial<LintOptions>} [config={}]\n * @return {*}\n */\nexport const readConfig = (config: Partial<LintOptions> = {}) => {\n  const { configFile = '.lintmdrc', ...rest } = config;\n  const userConfig = readJson(configFile);\n  const lint = {\n    ...userConfig,\n    ...rest,\n  };\n  /*\n   * 对 lint 进行转换\n   * 如果是一个数字，那么表示规则的等级：\n   * 0：忽略（off），不检查该规则\n   * 1：警告（warning），仅出现警告，程序正常退出，不会阻断 CI\n   * 2：错误（error），出现错误，程序异常退出，会阻断 CI\n   */\n  for (const [key, value] of Object.entries(lint)) {\n    if (typeof value === 'boolean') {\n      lint[key] = value ? 1 : 0;\n    }\n  }\n  return lint;\n};\n\nexport const getRules = () => {\n  const obj: SupportOptions = {};\n  for (const rule of Object.values(rules)) {\n    obj[rule.name] =\n      'type' in rule\n        ? {\n            type: 'string',\n            description: rule.description,\n            category: 'Global',\n          }\n        : {\n            type: 'boolean',\n            description: rule.description,\n            category: 'Global',\n          };\n  }\n  return obj;\n};\n\nexport const getPluginOptions = (\n  options: Record<string, unknown>,\n): Partial<LintOptions> => {\n  const pluginOptions: Partial<LintOptions> = {};\n\n  for (const rule of Object.values(rules)) {\n    const value = options[rule.name];\n    const type = 'type' in rule ? 'string' : 'boolean';\n    if (typeof value === type) {\n      Object.assign(pluginOptions, { [rule.name]: value });\n    }\n  }\n\n  return pluginOptions;\n};\n","import type { Plugin } from 'prettier';\nimport markdown from 'prettier/plugins/markdown.js';\nimport { lintMarkdown } from '@lint-md/core';\nimport { getPluginOptions, getRules, readConfig } from './utils';\nimport type { LintOptions } from './types';\n\nexport const PARSER_NAME = 'markdown';\n\nexport const prettierLintMd = (\n  ruleOptions: Partial<LintOptions> = {},\n): Plugin => {\n  return {\n    options: getRules(),\n    parsers: {\n      [PARSER_NAME]: {\n        ...markdown.parsers.markdown,\n        preprocess: (text, options) => {\n          const lint = readConfig({\n            ...ruleOptions,\n            ...getPluginOptions(options),\n          });\n          const result = lintMarkdown(text, lint, true, {\n            ruleErrorPolicy: 'strict',\n          });\n          return result.fixedResult.result;\n        },\n      },\n    },\n  };\n};\n\nexport default prettierLintMd();\n"],"mappings":"6xCAAa,EAAc,CACzB,KAAM,aACN,YAAa,SACb,KAAM,QACR,EAEa,EAAwB,CACnC,KAAM,wBACN,YAAa,eACf,EAEa,EAAsB,CACjC,KAAM,sBACN,YAAa,eACf,EAEa,EAAqB,CAChC,KAAM,qBACN,YAAa,UACf,EAEa,EAAe,CAC1B,KAAM,eACN,YAAa,aACf,EAEa,EAAgB,CAC3B,KAAM,gBACN,YAAa,UACf,EAEa,EAAgB,CAC3B,KAAM,gBACN,YAAa,WACf,EAEa,EAAuB,CAClC,KAAM,uBACN,YAAa,YACf,EAEa,EAAsB,CACjC,KAAM,sBACN,YAAa,WACf,EAEa,EAAwB,CACnC,KAAM,wBACN,YAAa,YACf,EAEa,EAAwB,CACnC,KAAM,wBACN,YAAa,SACf,EAEa,EAAuB,CAClC,KAAM,uBACN,YAAa,SACf,EAEa,EAA4B,CACvC,KAAM,4BACN,YAAa,iBACf,EAEa,EAAmB,CAC9B,KAAM,mBACN,YAAa,WACf,EAEa,EAA+B,C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