zoukankan      html  css  js  c++  java
  • crd-leetcode-cl: 将 LeetCode 中 AC 的题目转化为 MarkDown 表格

    背景: 写博客的时候每当新增 LeetCode 题解时都需要在 LeetCode/README 手动更新表格, 非常费劲。因此构思了 crd-leetcode-cli 插件实现自动化同步更新 leetcode ac 题解为 markdown table 。

    crd-leetcode-cli

    crd-leetcode-cli 提供将 leetcode 中已 AC 的题目转化为 markdown 表格的能力。

    Install

    执行 yarn add crd-leetcode-cli -g, 国内用户可以执行 cnpm install crd-leetcode-cli -g

    Usage

    leetcode download       // 增量拉取 AC 题目(若无登录, 则会先执行登录逻辑)
    leetcode download -a    // 全量拉取 AC 题目
    leetcode login          // 登录
    leetcode logout         // 登出
    

    接入项目示例

    Render Markdown Table Customly

    插件提供了自定义渲染 markdown table 的能力。

    const transform_markdown_table = (dataArr) => {
      const beforeDescription = `The markdown table is generated by [crd-leetcode-cli](https://github.com/MuYunyun/create-react-doc/tree/master/packages/leetcode-cli)`;
      let result = beforeDescription + '
    ' +
        '| # | Title | Explanation | Difficulty | Type |' +
        '
    ' +
        '|:---:|:---:|:---:|:---:|:---:|';
    
      for (let i = 0; i < dataArr.length; i++) {
        result += `
    | ${dataArr[i].questionId} | [${dataArr[i].title
          }](https://leetcode.com/problems/${dataArr[i].titleSlug
          }/) | [Analyze](https://github.com/MuYunyun/blog/blob/master/LeetCode/${dataArr[i].questionId
          }.${dataArr[i].title.split(' ').join('_')}.md) | ${dataArr[i].difficulty
          } | ${dataArr[i].topicTags} |`;
      }
      return result;
    };
    
    module.exports = { transform_markdown_table }
    

    通过自定义 transform_markdown_table 函数, 便可得到如下 markdown table:

    Technology Details

  • 相关阅读:
    MMoE论文笔记
    李宏毅-ELMO, BERT, GPT
    vue 手写一个时间选择器
    this 的几种使用场景
    如何使用markdown编辑器编写文章
    sublime text 3 入门技巧与常见问题解决
    Flex布局介绍
    在github上实现页面托管预览功能
    数据挖掘经典算法——最大期望算法
    数据挖掘经典算法——先验算法
  • 原文地址:https://www.cnblogs.com/MuYunyun/p/13754134.html
Copyright © 2011-2022 走看看