博文

Go语言实现拼音转汉字

图片
预先说明:以项目名为 x 作为示例 第一步:在GitHub找个汉字拼音字典(随便找了一个输入法项目的字典) https://github.com/MobtgZhang/LingJian-Pinyin/blob/main/data/pinyin_dict.txt 第二步:把字典下载下来放在项目里,例如:data/pinyin_dict.txt x/data/pinyin_dict.txt 第三步:创建 com/pinyin_han.go 文件,把代码复制进去 x/com/pinyin_han.go go 复制代码 package com import ( "bufio" "os" "strings" "sync" ) type PinyinHan struct { pyToHan map [ string ][] string abbrToHan map [ string ][] string // 简拼映射 noToneToHan map [ string ][] string // 无声调映射 mutex sync.RWMutex } func NewPinyinHan () *PinyinHan { return &PinyinHan{ pyToHan: make ( map [ string ][] string ), abbrToHan: make ( map [ string ][] string ), noToneToHan: make ( map [ string ][] string ), } } func (p *PinyinHan) LoadDictionary(filename string ) error { p.mutex.Lock() ...

Go语言实现汉字繁体、简体互相转换

图片
预先说明:以项目名为 x 作为示例 第一步:先获取库 复制代码 go get github.com /siongui/ gojianfan 第二步:封装函数(调用gojianfan库) x/com/str.go go 复制代码 package com import ( "github.com/siongui/gojianfan" "strings" ) type Str struct {} func NewStr () *Str { return &Str{} } func (*Str) HantHans(str string ) [] string { if strings.Trim(str, " " ) == "" { return nil } wds := make ( map [ string ] string ) original := str wds[original] = original // 简体转繁体 traditional := gojianfan.S2T(original) wds[traditional] = traditional // 繁体转简体 simplified := gojianfan.T2S(traditional) wds[simplified] = simplified result := make ([] string , 0 ) for ...

md-editor-v3(版本:5.8.5)插件自定义工具栏增加嵌入YouTube视频功能

图片
先看效果 第一步:先引入 utils/youtube.ts 文件 ts 复制代码 // utils/youtube.ts /** * YouTube 链接解析结果 */ export interface YouTubeParseResult { videoId : string | null type : 'watch' | 'youtu.be' | 'embed' | 'short' | 'invalid' timestamp?: number // 时间戳(秒) playlistId?: string | null } /** * 从 YouTube 链接中提取视频 ID * 支持格式: * - https://www.youtube.com/watch?v=VIDEO_ID * - https://youtu.be/VIDEO_ID * - https://www.youtube.com/embed/VIDEO_ID * - https://www.youtube.com/shorts/VIDEO_ID * - https://www.youtube.com/watch?v=VIDEO_ID&t=30s * * @param url YouTube 链接 * @returns 视频 ID,如果无法解析则返回 null */ export function getYouTubeVideoId ( url : string ): string | null { if (!url || typeof url !== 'string' ) return null try { const parsedUrl = new URL (url) ...

如何修改md-editor-v3(版本:5.8.5)插件上传图片后返回的Markdown格式?

md-editor-v3 上传图片返回的md文本原本是 ![](https://xxxx.com/img.png) ,想修改成 [![](https://xxxx.com/img.png)](https://xxxx.com/img.png) 的方法 vue 复制代码 < template > < MdEditor ref = "mdEditorRef" v-model = "content" :onUploadImg = "handleUploadImage" preview-theme = "github" /> </ template > < script setup lang = "ts" > import {ref} from 'vue' import { MdEditor } from 'md-editor-v3' import 'md-editor-v3/lib/style.css' import { ElLoading , ElMessage } from "element-plus" ; const content = ref ( '' ) const mdEditorRef = ref<any>() // 文件上传(未实现) const uploadFile = async ( file : File ): Promise <string> => { let url : string = '' // 这里是文件上传逻辑 return url } const...

如何巧妙地利用css让iframe嵌入视频/地图(固定比例自适应)

宽度随屏幕 100% 变宽时,高度也按比例(比如 16:9)自动变高。那么不需要任何 JavaScript,纯 CSS 就可以完美实现。 html 复制代码 < div class = "iframe-wrapper" > < iframe src = "//player.bilibili.com/player.html?aid=386733968" allowfullscreen = "allowfullscreen" > </ iframe > </ div > css 复制代码 .iframe-wrapper { width : 100% ; aspect-ratio: 16 / 9 ; /* 核心:让容器始终保持 16:9 的高宽比 */ } .iframe-wrapper iframe { border : 0 ; width : 100% ; height : 100% ; /* iframe 完美填满这个 16:9 的格子 */ } 举个例子

本地http文件下载服务——golocaldownload 部署方式、二次开发文档

仓库 地址 GitHub https://github.com/kite88/golocaldownload GitCode https://gitcode.com/kite88/golocaldownload Gitee https://gitee.com/kite88/golocaldownload 方式一:本地源码部署、二次开发 Step 1 代码拉下来 (以GitCode为例) 复制代码 git clone https://gitcode.com/kite88/golocaldownload.git Step 2 把config文件下的env.ini.local改为env.ini 说明: env.ini文件是配置文件,例如,端口配置、存放下载资源目录配置 方式二:本地主机 运行可执行文件 Step 1 下载发行版,找到对应自己系统平台架构的压缩包下载 github下载地址 gitcode下载地址 gitee下载地址 Step 2 解压后会有可执行程序跟启动脚本 说明: 访问地址就是 http://本地服务器IP:9801/ , 提供下载的资源就放在当前程序执行的路径 download_lib 目录下 方式三:docker部署(得有docker环境) Step 1 代码拉下来 (以GitCode为例) 复制代码 git clone https://gitcode.com/kite88/golocaldownload.git Step 2 进入到项目根目录直...