当前位置:网站首页>Milkdown 控件图标
Milkdown 控件图标
2022-07-07 11:08:00 【Cliven_】
现象说明
在vite + vue3的项目中,使用Milkdown作为Markdown编辑框
Milkdown.vue
<template>
<VueEditor :editor="editor" />
</template>
<script setup> import {
Editor, rootCtx, defaultValueCtx } from "@milkdown/core"; import {
nord } from "@milkdown/theme-nord"; import {
VueEditor, useEditor } from "@milkdown/vue"; import {
commonmark } from "@milkdown/preset-commonmark"; import {
emoji } from "@milkdown/plugin-emoji"; import {
history } from '@milkdown/plugin-history'; import {
tooltip } from '@milkdown/plugin-tooltip'; import {
menu } from "@milkdown/plugin-menu"; const {
editor } = useEditor((root) => Editor.make() .config((ctx) => {
ctx.set(rootCtx, root); ctx.set(defaultValueCtx, "# Milkdown Vue"); }) .use(nord) .use(emoji) .use(commonmark) .use(history) .use(menu) .use(tooltip) ); </script>
显示效果如图
所有图标区域都变为了文字,并且挤在一起非常难看,这是因为 milkdown/theme-nord
主题使用了google提供的 Google material icons
从 Milkdown官方给出的示例 可以看到
在index.html
文件中是引入了Google图标字体库的。
解决
方式一 在线引入
这里我们的空间没有显示图标的原因就是没有Google图标字体库导致,我们可以和官方一样,直接在index.html
文件中增加一行CSS文件的引用就可以。
index.html
<html>
<head>
...
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons+Outlined" />
...
</head>
...
</html>
该种方式将会使用Google的CSS2 API自动引用并相关字体和配置,该方式有个问题就是在网络条件不不允许时,会导致图标依然无法加载。
方式二 离线引入
根据 Google material icons#setup_method_2_self_hosting 中描述,我们可以下载相关字体文件,然后手动配置css使用字体文件。
我这里简单起见直接访问了Google的
拿到了CSS配置文件以及字体文件。
CSS如下所示
/* fallback */
@font-face {
font-family: 'Material Icons Outlined';
font-style: normal;
font-weight: 400;
src: url(https://fonts.gstatic.com/s/materialiconsoutlined/v106/gok-H7zzDkdnRel8-DQ6KAXJ69wP1tGnf4ZGhUce.woff2) format('woff2');
}
.material-icons-outlined {
font-family: 'Material Icons Outlined';
font-weight: normal;
font-style: normal;
font-size: 24px;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline-block;
white-space: nowrap;
word-wrap: normal;
direction: ltr;
-webkit-font-feature-settings: 'liga';
-webkit-font-smoothing: antialiased;
}
这里还出现了一个字体文件
这里我也手动下载并把该文件放置于项目的public/
目录下。
然后修改了Milkdown.vue,添加了上面的CSS,并且替换了字体文件的地址为本地的地址,修改后的文件如下所示。
<template>
<VueEditor :editor="editor" />
</template>
<script setup> import {
Editor, rootCtx, defaultValueCtx } from "@milkdown/core"; import {
nord } from "@milkdown/theme-nord"; import {
VueEditor, useEditor } from "@milkdown/vue"; import {
commonmark } from "@milkdown/preset-commonmark"; import {
emoji } from "@milkdown/plugin-emoji"; import {
history } from '@milkdown/plugin-history'; import {
tooltip } from '@milkdown/plugin-tooltip'; import {
menu } from "@milkdown/plugin-menu"; const {
editor } = useEditor((root) => Editor.make() .config((ctx) => {
ctx.set(rootCtx, root); ctx.set(defaultValueCtx, "# Milkdown Vue"); }) .use(nord) .use(emoji) .use(commonmark) .use(history) .use(menu) .use(tooltip) ); </script>
<style> @font-face {
font-family: 'Material Icons Outlined'; font-style: normal; font-weight: 400; src: url(./gok-H7zzDkdnRel8-DQ6KAXJ69wP1tGnf4ZGhUce.woff2) format('woff2'); } .material-icons-outlined {
font-family: 'Material Icons Outlined'; font-weight: normal; font-style: normal; font-size: 24px; line-height: 1; letter-spacing: normal; text-transform: none; display: inline-block; white-space: nowrap; word-wrap: normal; direction: ltr; -webkit-font-feature-settings: 'liga'; -webkit-font-smoothing: antialiased; } </style>
在加入了CSS和字体后可以看到控件上的图标已经正常。
参考文献
[1]. milkdown . demo . https://milkdown.dev/online-demo
[2]. milkdown . Integrations vue. https://milkdown.dev/vue
[3]. google . fonts . Material Icons Guide . 2022.03 . https://developers.google.com/fonts/docs/material_icons
边栏推荐
- The difference between cache and buffer
- 基于鲲鹏原生安全,打造安全可信的计算平台
- Talk about four cluster schemes of redis cache, and their advantages and disadvantages
- PACP学习笔记三:PCAP方法说明
- 怎样重置火狐浏览器
- mysql怎么创建,删除,查看索引?
- Day22 deadlock, thread communication, singleton mode
- 达晨与小米投的凌云光上市:市值153亿 为机器植入眼睛和大脑
- xshell评估期已过怎么办
- Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
猜你喜欢
Leetcode skimming: binary tree 20 (search in binary search tree)
[untitled]
DHCP 动态主机设置协议 分析
Leetcode brush question: binary tree 24 (the nearest common ancestor of binary tree)
.Net下極限生產力之efcore分錶分庫全自動化遷移CodeFirst
【学习笔记】AGC010
线程池拒绝策略最佳实践
.Net下极限生产力之efcore分表分库全自动化迁移CodeFirst
自定义线程池拒绝策略
通过Keil如何查看MCU的RAM与ROM使用情况
随机推荐
API query interface for free mobile phone number ownership
国泰君安证券开户怎么开的?开户安全吗?
滑轨步进电机调试(全国海洋航行器大赛)(STM32主控)
Go语言学习笔记-结构体(Struct)
HZOJ #236. Recursive implementation of combinatorial enumeration
AUTOCAD——大于180度的角度标注、CAD直径符号怎么输入?
2022a special equipment related management (boiler, pressure vessel and pressure pipeline) simulated examination question bank simulated examination platform operation
【Presto Profile系列】Timeline使用
Day21 multithreading
处理链中断后如何继续/子链出错removed from scheduling
JNA学习笔记一:概念
《ASP.NET Core 6框架揭秘》样章[200页/5章]
@Resource和@Autowired的区别?
2022 polymerization process test question simulation test question bank and online simulation test
Day26 IP query items
Coscon'22 community convening order is coming! Open the world, invite all communities to embrace open source and open a new world~
[learn wechat from 0] [00] Course Overview
初学XML
[untitled]
Find ID value MySQL in string