WordPress代码高亮插件推荐——Enlighter
不管是普通的Wordpress用户还是专业的开发者,许多人都喜欢将自己的用过代码记录在博客中,但是众所周知WordPress自身的代码功能非常简陋的,甚至没有高亮效果,难以阅读,如果我们想要展示漂亮的代码效果,必须安装一款合适的代码高亮插件
文章目录
一、Enlighter插件介绍
Enlighter具有现代设计的简洁风格,采用小字体非常的漂亮,支持代码块高亮和行内代码高亮,不管是前台的展示还是后台设计,都是非常用心的设计。
Enlighter这款插件非常好用,只需要点开输入框,复制进代码保存就行了,不需要进行任何额外的设置就能做出漂亮的代码显示
二、Enlighter插件安装
在WordPress插件平台上输入Enlighter搜索后进行安装,然后启用插件
启用后,一级菜单项里面会多出一个Enlighter菜单,如下图所示:
此时古腾堡编辑器的工具栏上也多一个插入代码模块,如下图所示:
这样就可以插入代码了,这里以插入java代码为例:
展示效果如下:
package com.itgacl.magic4j; import cn.hutool.core.io.FileUtil; import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; import com.itgacl.cloud.storage.annotation.EnableCos; import com.itgacl.cloud.storage.annotation.EnableKodo; import com.itgacl.cloud.storage.annotation.EnableOss; import com.itgacl.fastdfs.annotation.EnableFastDFS; import com.itgacl.magic4j.common.config.MvcCorsProperties; import com.itgacl.magic4j.libcommon.SpringBeanNameGenerator; import com.itgacl.magic4j.libcommon.filter.RequestDecryptFilter; import com.itgacl.magic4j.libcommon.util.RemotingUtil; import com.itgacl.minio.annotation.EnableMinio; import com.itgacl.mqtt.client.annotation.EnableMqttClient; import com.itgacl.ssh2.jsch.annotation.EnableSFTP; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.http.HttpMessageConverters; import org.springframework.boot.web.servlet.MultipartConfigFactory; import org.springframework.context.annotation.AnnotationBeanNameGenerator; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; import javax.servlet.Filter; import javax.servlet.MultipartConfigElement; import java.util.ArrayList; import java.util.List; /** * 注:为了避免扫描路径不一致,将启动类放在Root Package 即 com.itgacl */ //@EnableCos //@EnableKodo //@EnableOss //@EnableSFTP //@EnableFastDFS //@EnableMqttClient @EnableMinio @EnableTransactionManagement //在启动类上加注解@ComponentScan(nameGenerator = SpringBeanNameGenerator.class)使刚才自定义的BeanName生成策略生效 @ComponentScan(nameGenerator = SpringBeanNameGenerator.class) @SpringBootApplication public class Magic4jApplication { //文件上传临时存放目录 @Value("${magic4j.fileUpload.tempSavePath}") private String tempSavePath; @Bean//使用@Bean注入fastJsonHttpMessageConvert public HttpMessageConverters fastJsonHttpMessageConverters(){ //1.需要定义一个Convert转换消息的对象 FastJsonHttpMessageConverter fastConverter=new FastJsonHttpMessageConverter(); //2.添加fastjson的配置信息,比如是否要格式化返回的json数据 FastJsonConfig fastJsonConfig=new FastJsonConfig(); fastJsonConfig.setSerializerFeatures( SerializerFeature.PrettyFormat, SerializerFeature.WriteNullStringAsEmpty,//字符类型字段如果为null,输出为"",而非null SerializerFeature.WriteNullListAsEmpty,//List字段如果为null,输出为[],而非null SerializerFeature.DisableCircularReferenceDetect //避免循环引用 ); fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); //3.在convert中添加配置信息 fastConverter.setFastJsonConfig(fastJsonConfig); //处理中文乱码问题(不然出现中文乱码) List<MediaType> fastMediaTypes = new ArrayList<MediaType>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); fastConverter.setSupportedMediaTypes(fastMediaTypes); HttpMessageConverter<?> converter=fastConverter; return new HttpMessageConverters(converter); } /** * 文件上传临时路径 */ @Bean MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); //设置一个临时目录,解决:java.io.IOException: The temporary upload location [/tmp/tomcat.3541620039171925702.8092/work/Tomcat/localhost/ROOT] is not valid问题 if(RemotingUtil.isLinuxPlatform()){//如果是Linux平台 if(!FileUtil.exist(tempSavePath)){ FileUtil.mkdir(tempSavePath); } factory.setLocation(tempSavePath); } return factory.createMultipartConfig(); } /** * 创建一个bean * @return */ @Bean public Filter requestDecryptFilter() { return new RequestDecryptFilter(); } /** * C0RS跨域过滤器 * @param mvcCorsProperties * @return */ @Bean @ConditionalOnMissingBean(CorsFilter.class) public CorsFilter corsFilter(@Autowired MvcCorsProperties mvcCorsProperties) { if (mvcCorsProperties.getMappings().size() == 0) { return new CorsFilter(new UrlBasedCorsConfigurationSource()); } else { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.setCorsConfigurations(mvcCorsProperties.getMappings()); return new CorsFilter(source); } } public static void main(String[] args) { SpringApplication.run(Magic4jApplication.class, args); } }
声明:
本站大部分下载资源收集于网络,只做学习和交流使用,版权归原作者所有。若您需要使用非免费的软件或服务,请购买正版授权并合法使用。本站发布的内容若侵犯到您的权益,请联系站长删除,我们将及时处理。
资源无忧(res51) » WordPress代码高亮插件推荐——Enlighter
资源无忧(res51) » WordPress代码高亮插件推荐——Enlighter