package com.jay.monitor.data.server.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.github.hui.quick.plugin.md.Html2ImageWrapper;
import com.github.hui.quick.plugin.md.MarkDown2HtmlWrapper;
import com.github.hui.quick.plugin.md.entity.MarkdownEntity;
import org.junit.Test;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

/**
 * @Module TODO
 * @Description TODO
 * @Author liukaixiong
 * @Date 2020/12/14 18:07
 */
public class MarkDownUtilsTest {


    @Test
    public void testMdToHtml() throws Exception {
//        String mdText = " |  **插件名称**                                                  |  **插件介绍**                                                  |  **官网地址**                                                  | \n" +
//                " |  ------------------------------------------------------------  |  ------------------------------------------------------------  |  ------------------------------------------------------------  | \n" +
//                " |  Key promoter                                                  |  快捷键提示                                                    |  https://plugins.jetbrains.com/plugin/4455?pr=idea             | \n" +
//                " |  CamelCase                                                     |  驼峰式命名和下划线命名交替变化                                |  https://plugins.jetbrains.com/plugin/7160?pr=idea             | \n" +
//                " |  CheckStyle-IDEA                                               |  代码样式检查                                                  |  https://plugins.jetbrains.com/plugin/1065?pr=idea             | \n" +
//                " |  FindBugs-IDEA                                                 |  代码 Bug 检查                                                 |  https://plugins.jetbrains.com/plugin/3847?pr=idea             | \n" +
//                " |  Statistic                                                     |  代码统计                                                      |  https://plugins.jetbrains.com/plugin/4509?pr=idea             | \n" +
//                " |  JRebel Plugin                                                 |  热部署                                                        |  https://plugins.jetbrains.com/plugin/?id=4441                 | \n" +
//                " |  CodeGlance                                                    |  在编辑代码做右侧，显示一块代码小地图                          |  https://plugins.jetbrains.com/plugin/7275?pr=idea             | \n" +
//                " |  Eclipse Code Formatter                                        |  使用 Eclipse 的代码格式化风格，在一个团队中如果公司有规定格式化风格，这个可以使用。  |  https://plugins.jetbrains.com/plugin/6546?pr=idea             | \n" +
//                " |  GsonFormat                                                    |  把 JSON 字符串直接实例化成类                                  |  https://plugins.jetbrains.com/plugin/7654?pr=idea             | \n" +
//                " |  open in github                                                |  集成github的项目点击文件的右键,直接定位到网站github的指定位置  |                                                                | \n" +
//                " |  makedown support                                              |  编辑.md的文件类型,主要用于github中的REDEME.md的编写           |                                                                | \n" +
//                " |  maven helper                                                  |  maven工具的操作,里面包含了可以使用的一些常用命令.其中最大的一个亮点就是能够分析jar包之间的依赖  |                                                                | \n" +
//                " |  Translation                                                   |  idea里面的翻译插件,可以将中文自动切换成英文                   |  http://yiiguxing.github.io/TranslationPlugin/start.html       | \n" +
//                " |  Grep Console                                                  |  日志级别区分颜色插件                                          |                                                                | \n" +
//                " |  IDEOM                                                         |  idea背景色可以是指定的图片                                    |                                                                | \n" +
//                " |  [activate-power-mode](https://github.com/ViceFantasyPlace/activate-power-mode)  |  敲代码的时候,屏幕一闪一闪的..                                 |  https://github.com/ViceFantasyPlace/activate-power-mode       | \n" +
//                " |  Alibaba Java Coding Guidelines                                |  阿里巴巴代码规范检查器,类似于findBug等等,非常棒的一款工具     |                                                                | \n" +
//                " |  **CodeGlance**                                                |  右侧有一个代码预览面板                                        |                                                                | \n" +
//                " |  InnerBuilder                                                  |  生成Build模式的方法                                           |                                                                | \n" +
//                " |  JUnit Generator                                               |  测试用例生成工具                                              |                                                                | \n" +
//                " |  JProfiles                                                     |  代码运行的工具检测，可以查看类方法的执行耗时时间              |  官网 : https://plugins.jetbrains.com/plugin/253-jprofiler 注册码 : https://blog.csdn.net/liyantianmin/article/details/86534544  | \n" +
//                " |  Codota                                                        |  代码使用案例                                                  |                                                                | \n" +
//                " |  .ignore                                                       |  git文件忽略                                                   |                                                                | \n" +
//                " |  Aixcoder code completer                                       |  代码智能补全                                                  |                                                                | \n" +
//                " |  GitToolBox                                                    |  git 工具                                                      |                                                                | \n" +
//                " |  String Manipulation                                           |  驼峰 命名工具                                                 |                                                                | \n" +
//                "\n" +
//                "\n" +
//                "\n" +
//                " |  asd as  |  asd asd  |  ads   | \n" +
//                " |  ------  |  -------  |  ----  | \n" +
//                " |          |           |        | \n" +
//                "\n";

//        MutableDataHolder options = new MutableDataSet();
//        options.setFrom(ParserEmulationProfile.MARKDOWN);
//        options.set(Parser.EXTENSIONS, Arrays.asList(
//                AbbreviationExtension.create(),
//                DefinitionExtension.create(),
//                FootnoteExtension.create(),
//                TablesExtension.create(),
//                TypographicExtension.create()
//        ));
//        Parser parser = Parser.builder(options).build();
//        HtmlRenderer renderer = HtmlRenderer.builder(options).build();
//
//        Node document = parser.parse(mdText);
//        String render = renderer.render(document);// "<p>This is <em>Sparta</em></p>\n"
//        System.out.println(render);


//        String mdText = "| URL        | 请求总数 | 平均值 | 最大值 |\n" +
//                "| ---------- | -------- | ------ | ------ | \n" +
//                " | /elab-marketing-user/miniecrm/standing/book/payProofPdf | 1 | 5668 | 5668 | \n" +
//                " | /elab-marketing-user/miniecrm/standing/book/exportReportList | 1 | 5342 | 5342 | \n" +
//                " | /elab-marketing-user/visit/add | 3 | 5217 | 5272 | \n" +
//                " | /elab-marketing-user/miniecrm/standing/book/payProof | 1 | 5168 | 5168 | \n" +
//                " | /elab-marketing-user/visit/scanVisitQueue | 16 | 5194 | 5385 | \n" +
//                " | /elab-marketing-user/bindAdviser/reportAdviserListNew | 12 | 5156 | 5309 | \n" +
//                " | /elab-marketing-user/report/upgrade/reportCount | 26 | 5370 | 6118 | \n" +
//                " | /elab-marketing-user/miniecrm/standing/book/reportList | 12 | 5341 | 5905 | \n" +
//                " | /elab-marketing-user/organize/v2.0/verification/autoAuthentication | 90 | 5282 | 8997 | \n" +
//                " | /elab-marketing-user/c_report/manualRecord | 20 | 5325 | 6037 | ";
        String json = "[\"## URL请求总数排行-TOP 10 \r\n | URL        | 请求总数   | 平均值  | 最大值  |\\n| ---------- | :--------: | :------: | :------: |\\n|/elab-marketing-system/behavior/brandMiniWeb/upload|82686|22|479|\\n|/elab-marketing-user/visit/scanVisitQueue|43391|39|5385|\\n|/elab-marketing-user/brand/shareSign/generateShareSign|42515|25|2128|\\n|/elab-marketing-content/cityHistory/queryCityData|27759|23|169|\\n|/elab-marketing-user/customer/rules/add|26507|18|1206|\\n|/elab-marketing-content/brand/shareSetting/shareConfDetail|25224|18|163|\\n|/elab-marketing-user/mimiapp/parameter/queryShareConfig|24986|23|1182|\\n|/elab-marketing-user/integrals/userinfo/getUnReadObject|21312|19|1106|\\n|/elab-marketing-user/brandXcx/enterHouse|14000|39|2117|\\n|/elab-marketing-user/organize/v2.0/verification/getAuthenticationStatus|13143|23|211|\\n\",\"## URL请求慢排行 - TOP 10 \r\n | URL        | 请求总数   | 平均值  | 最大值  |\\n| ---------- | :--------: | :------: | :------: |\\n|/elab-marketing-user/miniecrm/standing/book/payProofPdf|1|5668|5668|\\n|/elab-marketing-user/miniecrm/standing/book/exportReportList|1|5342|5342|\\n|/elab-marketing-user/visit/add|3|5217|5272|\\n|/elab-marketing-user/miniecrm/standing/book/payProof|1|5168|5168|\\n|/elab-marketing-user/visit/scanVisitQueue|16|5194|5385|\\n|/elab-marketing-user/bindAdviser/reportAdviserListNew|12|5156|5309|\\n|/elab-marketing-user/report/upgrade/reportCount|26|5370|6118|\\n|/elab-marketing-user/miniecrm/standing/book/reportList|12|5341|5905|\\n|/elab-marketing-user/organize/v2.0/verification/autoAuthentication|90|5282|8997|\\n|/elab-marketing-user/c_report/manualRecord|20|5325|6037|\\n\"]";


        JSONArray objects = JSON.parseArray(json);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < objects.size(); i++) {
            String text = objects.getString(i);
            sb.append(text + "\r\n");
        }


        String parse = MarkDown2HtmlWrapper.parse(sb.toString());
        System.out.println(parse);
//        MarkdownEntity html = MarkDown2HtmlWrapper.ofFile(file);
//        String mdFile = "C:\\Users\\Administrator\\Desktop\\问题汇总.md";
        MarkdownEntity html = MarkDown2HtmlWrapper.ofContent(parse);
        BufferedImage img = Html2ImageWrapper.ofDoc(parse)
//                .setW(1000)
                .setAutoW(true)
                .setAutoH(true)
                .setOutType("jpg")
                .build()
                .asImage();
//        ImageInputStream imageInputStream = ImageIO.createImageInputStream(img);
        System.out.println("");
        boolean jpg = ImageIO.write(img, "jpg", new File("C:\\Users\\Administrator\\Desktop\\md.jpg"));
//        System.out.println("结果:" + jpg);
    }

    @Test
    public void testMdToImage() {


    }

}