在Markdown中为Maven网站(Fluido)突出显示语法 [英] Have Syntax Highlighting in Markdown for Maven Site (Fluido)
问题描述
我在Maven项目中尝试了以下方法:
I have tried the following in my Maven project:
- 添加包含内容的降价文件
content.md
```java
int a = 4;
```
在src/main/site/markdown
中.
-
写一个带有内容的
site.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<project>
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.7</version>
</skin>
<body>
<menu name="Dokumentation">
<item name="Benutzerhandbuch" href="content.html" />
</menu>
<menu ref="reports" />
</body>
</project>
用
Write a pom.xml
with
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.continentale.testsvn</groupId>
<artifactId>site-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-module-xhtml</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-module-markdown</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
现在我从mvn site
获取文件content.html
.在此文件中,int a = 4
的语法是 not 突出显示.
Now I get a file content.html
from mvn site
. In this file, the int a = 4
is not syntax highlighted.
我需要怎么做才能突出显示语法?
What do I need to do to get syntax highlighting?
推荐答案
我也无法使其与Maven一起使用,但是我找到了一种解决方法:使用
I couldn't get it to work with Maven either but I found a workaround: Do the highlighting client-side in Javascript with highligh.js.
下载highlight.js并将其放置在src/site/resources/highlightjs.pack.js
下以及CSS主题下,例如src/site/resources/styles/atom-one-light.css
.
Download highlight.js and place it under src/site/resources/highlightjs.pack.js
, as well as a CSS theme, e.g. src/site/resources/styles/atom-one-light.css
.
在您的网站描述符中:
<project>
<body>
<head>
<![CDATA[
<link rel="stylesheet" href="styles/foundation.css" />
<script src="highlight.pack.js"></script>
<script>
document.addEventListener('DOMContentLoaded', (event) => {
document.querySelectorAll('pre.source').forEach((block) => {
hljs.highlightBlock(block);
});
});
</script>
]]>
</head>
</body>
</project>
Maven为代码块生成<pre class="source" />
块,因此我们需要将其标记为Highlight.js.不幸的是,Maven并没有提供与该语言相对应的类名(在您的示例中为Java),但是Highlight.js会自动检测语言,并且在大多数情况下都可以使用.
Maven generate <pre class="source" />
blocks for code blocks so we need to tell that to highlight.js. Unfortunately Maven doesn't put a class name corresponding to the language (Java in your example) but highlight.js auto-detects languages and that works in most cases.
这篇关于在Markdown中为Maven网站(Fluido)突出显示语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!