Markdown 如何更好的显示日志、提示、警告、错误等消息?

Markdown 官方似乎都没有给出相应的规范。网上也很少有人讨论这些。

Github 使用 Linguist 执行语言检测和语法高亮。我在 Linguist 规范中似乎没有找到答案。于是创建了一个讨论 What is the preferred way to include error messages in Markdown? · Discussion #5927 · github/linguist,期待能得到答案。

与 Linguist 同类的是 highlight.js,但是 highlight.js 上也没有找到用于显示日志、提示、警告、错误等消息的语法高亮。

于是我创建了一些 示例,然后将其放在 GitHub 上,通过对代码块使用不同语言渲染后的效果,我的建议是,使用 markdown 语言标识符仅高亮 Markdown 语法,或者不要添加任何语言标识符,不进行语法高亮显示,因为似乎没有一种语言标识符能满足,杂乱的高亮反而影响阅读。

StackExchange 上也有说用引用,但是引用不会自动换行,它和无语法的文本一样,在 Markdown 中普通换行是不会换行的。没有换行阅读起来更累,因为用引用肯定是不行的。

当然最好的方案就是 Linguist 使用 Jetbrains IDE 使用的语法高亮。你看他们家的 IDE 对输出的信息显示得多好。

想查看以下示例在 GitHub 上的显示效果,请点击 test/code-blocks.md at master · GanZhiXiong/test

示例 1

image-20220531214604065

代码块

basic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Could not find com.android.tools.build:gradle:3.2.1.
Searched in the following locations:
- file:/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/libs/gradle-3.2.1.jar
- file:/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/libs/gradle.jar
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
- http://maven.aliyun.com/nexus/content/repositories/releases/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- http://maven.aliyun.com/nexus/content/repositories/releases/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
Required by:
project :
Add google Maven repository and sync project
Open File

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Could not find com.android.tools.build:gradle:3.2.1.
Searched in the following locations:
- file:/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/libs/gradle-3.2.1.jar
- file:/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/libs/gradle.jar
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
- http://maven.aliyun.com/nexus/content/repositories/releases/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- http://maven.aliyun.com/nexus/content/repositories/releases/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
Required by:
project :
Add google Maven repository and sync project
Open File

java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Could not find com.android.tools.build:gradle:3.2.1.
Searched in the following locations:
- file:/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/libs/gradle-3.2.1.jar
- file:/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/libs/gradle.jar
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
- http://maven.aliyun.com/nexus/content/repositories/releases/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- http://maven.aliyun.com/nexus/content/repositories/releases/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
Required by:
project :
Add google Maven repository and sync project
Open File

bash

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Could not find com.android.tools.build:gradle:3.2.1.
Searched in the following locations:
- file:/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/libs/gradle-3.2.1.jar
- file:/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/libs/gradle.jar
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
- http://maven.aliyun.com/nexus/content/repositories/releases/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- http://maven.aliyun.com/nexus/content/repositories/releases/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
Required by:
project :
Add google Maven repository and sync project
Open File

markdown

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
## test
Could not find com.android.tools.build:gradle:3.2.1.
Searched in the following locations:
- file:/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/libs/gradle-3.2.1.jar
- file:/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/libs/gradle.jar
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
- http://maven.aliyun.com/nexus/content/repositories/releases/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom
- http://maven.aliyun.com/nexus/content/repositories/releases/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.jar
Required by:
project :
Add google Maven repository and sync project
Open File

引用

StackExchange 上也有说用引用,但是引用不会自动换行,它和无语法的文本一样,在 Markdown 中普通换行是不会换行的。

Could not find com.android.tools.build:gradle:3.2.1.
Searched in the following locations:

Could not find com.android.tools.build:gradle:3.2.1.
Searched in the following locations:

image-20220531215017597

代码块

basic

1
2
3
4
5
6
7
8
9
10
11
12
Build file '/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/build.gradle' line: 297

A problem occurred configuring root project 'android-exp-191116'.
> Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=armv7Debug, filters=[], versionCode=50002, versionName=5.0.0}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'android-exp-191116'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:109)
at org.gradle.configuration.project.LifecycleProjectEvaluator.onAfterEvaluateFailure(LifecycleProjectEvaluator.java:105)

markdown

1
2
3
4
5
6
7
8
9
10
11
12
Build file '/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/build.gradle' line: 297

A problem occurred configuring root project 'android-exp-191116'.
> Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=armv7Debug, filters=[], versionCode=50002, versionName=5.0.0}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'android-exp-191116'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:109)
at org.gradle.configuration.project.LifecycleProjectEvaluator.onAfterEvaluateFailure(LifecycleProjectEvaluator.java:105)

1
2
3
4
5
6
7
8
9
10
11
12
Build file '/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/build.gradle' line: 297

A problem occurred configuring root project 'android-exp-191116'.
> Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=armv7Debug, filters=[], versionCode=50002, versionName=5.0.0}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'android-exp-191116'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:109)
at org.gradle.configuration.project.LifecycleProjectEvaluator.onAfterEvaluateFailure(LifecycleProjectEvaluator.java:105)

引用

Build file ‘/Users/gan/Documents/YoSmart/YoSmartApp/android-exp-191116/build.gradle’ line: 297

A problem occurred configuring root project ‘android-exp-191116’.

Cannot set the value of read-only property ‘outputFile’ for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=armv7Debug, filters=[], versionCode=50002, versionName=5.0.0}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

  • Try:
    Run with –info or –debug option to get more log output. Run with –scan to get full insights.

  • Exception is:
    org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project ‘android-exp-191116’.
    at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:109)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.onAfterEvaluateFailure(LifecycleProjectEvaluator.java:105)

Markdown 如何更好的显示日志、提示、警告、错误等消息?

https://ganzhixiong.com/p/16ad4f7a/

Author

干志雄

Posted on

2022-05-31

Updated on

2022-05-31

Licensed under

Comments