UNPKG

markdown-it-git-graph

Version:

一个markdown-it插件,用于生成git提交图

31 lines (30 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GitGraphPlugin = void 0; const git_js_1 = require("./git.js"); const options_js_1 = require("./options.js"); const table_js_1 = require("./table.js"); const GitGraphPlugin = (md, options) => { const gitGraphOptions = (0, options_js_1.getOptions)(options); const fence = md.renderer.rules.fence; md.renderer.rules.fence = (tokens, idx, options, env, self) => { const token = tokens[idx]; const language = token.info.trim(); if (language.startsWith('git-graph')) { return parse(idx, token.content, { ...gitGraphOptions, theme: { ...gitGraphOptions.theme, ...(0, options_js_1.parseTheme)(language.slice(9)), }, }); } return fence?.(tokens, idx, options, env, self) ?? ''; }; }; exports.GitGraphPlugin = GitGraphPlugin; function parse(idx, content, options) { const branches = (0, git_js_1.getBranches)(content, options.defaultBranchName); const table = (0, table_js_1.getTable)(idx, branches, options); return table.draw(idx.toString(), options.theme); }