整合營銷服務商

          電腦端+手機端+微信端=數據同步管理

          免費咨詢熱線:

          一鍵生成通用高亮代碼塊到剪貼板,可粘貼到在線編輯器

          些在線圖文編輯器不支持直接插入代碼塊,但可以直接粘貼 HTML 格式的高亮代碼塊。

          花了一點時間研究了一下各家的編輯器,規則卻各不相同。有的要求代碼塊被包含于 <code> ... </code> 或者 <pre> <code> ... </code> </pre> , 有些要求 class 屬性里包含 "code" 關鍵詞,或者要求代碼塊里必須包含至少一個 <br> 。如果不符合這些要求,不是變成普通文本,就是丟失換行縮進,或者丟失顏色樣式。

          所以,這就難了。先得找個支持代碼高亮的編輯器,仔細地選擇并復制代碼塊,復制完還得編輯剪貼板里的 HTML 。這就不如干脆寫個轉換工具了。

          因為瀏覽器操作系統剪貼板可能不太方便,下面用 aardio 寫一個工具軟件。

          先看軟件成品演示:

          軟件用法:

          1、輸入編程語言名稱(支持自動完成)。

          2、然后在輸入框中粘貼要轉換的編程代碼。

          3、點擊「復制高亮代碼塊」按鈕。

          然后我們就可以打開在線圖文編輯器直接粘貼生成的高亮代碼塊了。

          下面是這個軟件的 aardio 源代碼:

          import win.ui;
          /*DSG{{*/
          var winform = win.form(text="HTML 代碼塊生成工具 - 本工具使用 aardio 語言編寫";right=1055;bottom=674;bgcolor=16777215)
          winform.add(
          button={cls="button";text="復制高亮代碼塊";left=633;top=609;right=1000;bottom=665;bgcolor=16777215;color=14120960;db=1;dr=1;font=LOGFONT(h=-14);note="可在網頁編輯器直接粘貼";z=4};
          cmbLangs={cls="combobox";left=262;top=625;right=446;bottom=651;db=1;dl=1;edge=1;items={"javascript"};mode="dropdown";z=2};
          editCode={cls="edit";left=1;top=4;right=1052;bottom=599;db=1;dl=1;dr=1;dt=1;edge=1;hscroll=1;multiline=1;vscroll=1;z=5};
          static={cls="static";text="請選擇語言:";left=70;top=629;right=248;bottom=649;align="right";db=1;dl=1;transparent=1;z=3};
          webCtrl={cls="custom";text="自定義控件";left=8;top=10;right=1048;bottom=604;db=1;dl=1;dr=1;dt=1;hide=1;z=1}
          )
          /*}}*/
          
          import web.view;
          var wb = web.view(winform.webCtrl);
          
          import win.clip.html;
          wb.export({ 
              onHighlight = function(html,background,foreground){
                  html = `<pre class="code" style="overflow-x:auto;text-align:left;box-shadow: rgba(216, 216, 216, 0.5) 0px 0px 0px 1px inset;padding:10px;border-radius:3px;background-color:`+background+`;color:`+foreground+`;white-space:pre;word-break:break-all;display:block;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps: normal;font-family: "Consolas", Consolas, "Liberation Mono", Menlo, Courier, monospace"><code>`
                      + html + `</code></pre>`;
          
                  html,count = string.replace(html,'\n',"<br>");
                  if(!count){
                      html = string.replace(html,`\</code\>\</pre\>$`,`<br></code></pre>`);
                  }
                  var cb = win.clip.html();
                  cb.write(html); 
          
                  winform.setTimeout( 
                      function(){
                          winform.editCode.show(true);
                          winform.webCtrl.show(false);
                          winform.text = "HTML 代碼塊生成工具 - 已復制高亮代碼塊到剪貼板,可在網頁直接粘貼";
                      },1000); 
              };
              setLanguages = function(langs){
                  winform.languages = langs;
              }  
          })
          
          
          winform.cmbLangs.onEditChange = function(){ 
          
              var text = string.lower(winform.cmbLangs.text);
              var items = table.filter( winform.languages : {}, lambda(v) string.startWith(v,text) ); 
              winform.cmbLangs.autoComplete(items);  
          }
          winform.cmbLangs.editBox.disableInputMethod();
          
          import web.prism;
          import wsock.tcp.asynHttpServer;
          var httpServer = wsock.tcp.asynHttpServer(); 
          httpServer.run(web.prism,{
              ["/index.html"] = /*****
          <!DOCTYPE html>
          <html>
            <head>
              <meta charset="UTF-8" /> 
              <link href="prism.css" rel="stylesheet" />
            </head>
            <body>
              <pre id="code-pre"><code id="code" class="lang-javascript"></code></pre>
              <script src="prism.js"></script>
              <script>
             function computedColorStyle(element, options = {}) {
          
                  Array.prototype.forEach.call(element.children,child => {
                      computedColorStyle(child, options);
                  });
          
                  const computedStyle = getComputedStyle(element);
                  element.style["color"] = computedStyle.getPropertyValue("color");  
              }
          
              highlight = function(code,language){
                  var html = Prism.highlight(code, Prism.languages[language], language);
          
                  var codeEle = document.getElementById("code");
                  codeEle.innerHTML = html;
                  computedColorStyle(codeEle);
          
                  const computedStyle = getComputedStyle(codeEle);  
                  onHighlight(codeEle.innerHTML
                      ,getComputedStyle(document.getElementById("code-pre")).getPropertyValue("background-color")
                      ,computedStyle.getPropertyValue("color"));
              }
          
              setLanguages( Object.keys(Prism.languages) );
              </script>
            </body> 
          </html> 
              *****/
          });
          
          wb.go( httpServer.getUrl("/index.html"));
          
          winform.button.oncommand = function(id,event){
              winform.text = "HTML 代碼塊生成工具 - 本工具使用 aardio 語言編寫"
              winform.editCode.show(false);
              winform.webCtrl.show(true);
          
              wb.xcall("highlight",winform.editCode.text,winform.cmbLangs.text);
          }
          
          
          winform.show();
          win.loopMessage();

          打開 aardio 創建工程,然后復制粘貼上面的代碼到 main.aardio 里面就可以直接運行,或生成獨立 EXE 文件:

          這個軟件的原理:

          1、首先通過 WebView2 調用 Prism.js 高亮代碼。為了可以內存加載 Prism.js ( 支持生成獨立 EXE ),我寫了一個 aardio 擴展庫 web.prism 。關于 WebView2 請參考:放棄 Electron,擁抱 WebView2!JavaScript 快速開發獨立 EXE 程序

          2、因為 Prism.js 生成的 HTML 代碼塊都是使用 class 屬性指定樣式,所以我們需要調用 getComputedStyle 獲取最終渲染的字體顏色屬性。

          3、最后在 JavaScript 里調用 aardio 函數處理生成的 HTML 代碼塊,aardio 的任務是將 HTML 修改為更合適直接粘貼的格式,并盡可能地處理各圖文編輯器的兼容問題。然后調用 win.clip.html 將處理好的 HTML 復制到系統剪貼板:

          import win.clip.html;
          
          var cb = win.clip.html();
          cb.write(html); 

          然后只要愉快地粘貼代碼塊就可以。

          如果是 aardio 代碼不需要用這個工具,在 aardio 編輯器里右鍵直接點『 復制全部到 HTML 代碼塊 』就可以了:

          定程序員是否加班的關鍵因素之一,是編碼水平。工欲善其事,必先利其器,每一位程序員都有私藏的編程必備工具。今天,緯創軟件的程序員小哥哥給大家分享了5款超好用的代碼比較工具,可以有效提升編碼速度哦!

          一:Beyond Compare

          Beyond Compare這款工具,讓兩份源代碼之間的異同一目了然,字節用不同的顏色顯示,同時可設置多種不同的比較規則,文本文件可以用語法高亮和設置的比較規則進行編輯對比,適用于用于文檔、源代碼和HTML。這種突出顯示異同的方式,讓源代碼的比較工作異常清晰。

          二、Diffuse

          Diffuse這款工具的命令執行速度是非常快的,C++、Python、Java、XML等語言的語法支持高亮顯示,非常直觀的可視化比較,同時支持三者的源代碼比較。

          三、WinMerge

          常用的Windows系統下的文件比較合并工具,最讓人喜歡的地方是可以方便地比較多個文檔內容,適合經常撰寫文稿或者程序員朋友使用。WinMerge會將兩個文件內容不同的地方高亮顯示,比較快速地呈現給使用者,直接讓左方的文件內容覆蓋至右方,反過來覆蓋也是完全沒問題的。

          四、Code Compare

          Code Compare是一款支持的語言比較多,C#、C++、CSS、HTML、Java、JavaScrip等代碼語言都可以再上面做比較,操作簡單。獨特的Visual Studio集成,可以在一個環境內方便程序的開發設計。

          五、AptDiff

          AptDiff這款工具可以對文本和二進制文件進行比較和合并,對于網絡設計,軟件開發和其他專業領域都適用,快捷鍵盤讓這款工具使用起來非常便捷,同步進行橫向和縱向卷動,支持Unicode格式和大于4GB的文件,快速生成HTML格式比較報告。

          那么,希望這些工具可以幫助開發設計的小伙伴們提升效率,你就有更多的時間去學習進步,升職加薪啦!在之后的文章中緯小創會為大家繼續分享一些實用工具,如果你有更好的工具,也歡迎在評論區指教一下哦!

          screw,簡潔好用的數據庫表結構文檔生成工具。

          特點,1、簡潔、輕量、設計良好,2、多數據庫支持,3、多種格式文檔,4、靈活擴展。

          地址:https://gitee.com/leshalv/screw

          工程

          功能說明:

          將某個mysql數據庫中的表生成文檔,文檔格式可以是:html、word、markdown。

          pom.xml

          <!-- screw庫,簡潔好用的數據庫表結構文檔生成器 -->
          <dependency>
              <groupId>cn.smallbun.screw</groupId>
              <artifactId>screw-core</artifactId>
              <version>1.0.5</version>
          </dependency>
          <!-- 數據庫連接 -->
          <dependency>
              <groupId>com.zaxxer</groupId>
              <artifactId>HikariCP</artifactId>
              <version>3.4.5</version>
          </dependency>
          <!-- Mysql Driver -->
          <dependency>
              <groupId>mysql</groupId>
              <artifactId>mysql-connector-java</artifactId>
              <version>8.0.20</version>
          </dependency>

          生成代碼:

          package com.what21.demo.screw;
          
          import cn.smallbun.screw.core.Configuration;
          import cn.smallbun.screw.core.engine.EngineConfig;
          import cn.smallbun.screw.core.engine.EngineFileType;
          import cn.smallbun.screw.core.engine.EngineTemplateType;
          import cn.smallbun.screw.core.execute.DocumentationExecute;
          import cn.smallbun.screw.core.process.ProcessConfig;
          import com.zaxxer.hikari.HikariConfig;
          import com.zaxxer.hikari.HikariDataSource;
          
          import javax.sql.DataSource;
          import java.util.Arrays;
          import java.util.Collections;
          
          public class ScrewMain {
          
              private static final String DB_URL = "jdbc:mysql://127.0.0.1:3306/xxl_job?serverTimezone=GMT";
              private static final String DB_USERNAME = "root";
              private static final String DB_PASSWORD = "root1234";
          
              private static final String FILE_OUTPUT_DIR = "D:/Download";
              // 可以設置 Word 或者 Markdown 格式
              private static final EngineFileType FILE_OUTPUT_TYPE = EngineFileType.MD;
              private static final String DOC_FILE_NAME = "數據庫文檔";
              private static final String DOC_VERSION = "1.0.0";
              private static final String DOC_DESCRIPTION = "文檔描述";
          
              public static void main(String[] args) {
                  // 創建 screw 的配置
                  Configuration config = Configuration.builder()
                          .version(DOC_VERSION)  // 版本
                          .description(DOC_DESCRIPTION) // 描述
                          .dataSource(buildDataSource()) // 數據源
                          .engineConfig(buildEngineConfig()) // 引擎配置
                          .produceConfig(buildProcessConfig()) // 處理配置
                          .build();
                  // 執行 screw,生成數據庫文檔
                  new DocumentationExecute(config).execute();
              }
          
              /**
               * 創建數據源
               */
              private static DataSource buildDataSource() {
                  // 創建 HikariConfig 配置類
                  HikariConfig hikariConfig = new HikariConfig();
                  hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
                  hikariConfig.setJdbcUrl(DB_URL);
                  hikariConfig.setUsername(DB_USERNAME);
                  hikariConfig.setPassword(DB_PASSWORD);
                  // 設置可以獲取 tables remarks 信息
                  hikariConfig.addDataSourceProperty("useInformationSchema", "true");
                  // 創建數據源
                  return new HikariDataSource(hikariConfig);
              }
          
              /**
               * 創建 screw 的引擎配置
               */
              private static EngineConfig buildEngineConfig() {
                  return EngineConfig.builder()
                          .fileOutputDir(FILE_OUTPUT_DIR) // 生成文件路徑
                          .openOutputDir(false) // 打開目錄
                          .fileType(FILE_OUTPUT_TYPE) // 文件類型
                          .produceType(EngineTemplateType.freemarker) // 文件類型
                          .fileName(DOC_FILE_NAME) // 自定義文件名稱
                          .build();
              }
          
              /**
               * 創建 screw 的處理配置,一般可忽略
               * 指定生成邏輯、當存在指定表、指定表前綴、指定表后綴時,將生成指定表,其余表不生成、并跳過忽略表配置
               */
              private static ProcessConfig buildProcessConfig() {
                  return ProcessConfig.builder()
                          .designatedTableName(Collections.<String>emptyList())  // 根據名稱指定表生成
                          .designatedTablePrefix(Collections.<String>emptyList()) //根據表前綴生成
                          .designatedTableSuffix(Collections.<String>emptyList()) // 根據表后綴生成
                          .ignoreTableName(Arrays.asList("test_user", "test_group")) // 忽略表名
                          .ignoreTablePrefix(Collections.singletonList("test_")) // 忽略表前綴
                          .ignoreTableSuffix(Collections.singletonList("_test")) // 忽略表后綴
                          .build();
              }
          
          }

          生成的效果:


          主站蜘蛛池模板: 无码视频一区二区三区| 国产乱子伦一区二区三区| 日韩一区二区三区射精| 国产精品 视频一区 二区三区| V一区无码内射国产| 亚洲AV无码一区二区大桥未久 | 蜜桃传媒视频麻豆第一区| 精品乱码一区二区三区在线| 久久精品无码一区二区无码| 国精品无码一区二区三区在线蜜臀| 精品人妻无码一区二区色欲产成人| 天堂国产一区二区三区| 任你躁国产自任一区二区三区| 国产一区二区三区在线电影| 亚洲欧美国产国产综合一区| 麻豆一区二区三区精品视频 | 在线中文字幕一区| 无码AV中文一区二区三区| 亚洲综合无码精品一区二区三区| 一级毛片完整版免费播放一区 | 日产亚洲一区二区三区| 久久精品一区二区三区日韩| 国产成人精品一区二区三区免费| 久久精品人妻一区二区三区| 国产日韩AV免费无码一区二区| 精品久久久久一区二区三区| 97久久精品午夜一区二区| 精品国产亚洲一区二区在线观看 | 高清国产AV一区二区三区| 国产成人久久精品一区二区三区 | 精品视频一区二区三区在线播放| 日韩视频在线一区| 午夜福利国产一区二区| 精品一区二区三区高清免费观看| 精品国产一区二区三区久久蜜臀| 国产精品一区二区久久不卡| 亚洲视频一区网站| 精品在线一区二区| 内射女校花一区二区三区| 人体内射精一区二区三区| 亚洲综合一区无码精品|