Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #16300: Static html for syntax highlight in web site #16334

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

smita1078
Copy link
Contributor

Issue: #16300

  • modified css, skin automatically applies this by converting nowrap->pre-wrap
  • removed unuseful js libraries that were earlier used to syntax highlighting
  • also removed that code block that added newlines, as this is also handled by Skin itself

Output:

image

@Zopsss
Copy link
Member

Zopsss commented Feb 15, 2025

github, generate site

@@ -143,7 +143,6 @@ th {
.prettyprint {
padding: 0.5em !important;
overflow: auto;
white-space: nowrap;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this was removed? 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already taken care through skin, if not removed it was giving all code in single line with horizontal scroll

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default was pre-wrap? I'm referring to:

modified css, skin automatically applies this by converting nowrap->pre-wrap

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default was nowrap, but this was overriding skins inbuilt css and giving all code in a single line, when removed it got fixed and skins pre-wrap was applied instead

@smita1078
Copy link
Contributor Author

GitHub, generate website

Copy link
Contributor

Copy link
Contributor

Comment on lines -47 to -56
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="$relativePath/js/anchors.js"></script>
<script type="text/javascript" src="$relativePath/js/google-analytics.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prettify/1.0.0/prettify.min.js"></script>
<script type="text/javascript"
src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/google/code-prettify@master/styles/prettify.css" type="text/css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prettify/1.0.0/prettify.min.css">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we removed the external JS library and syntax highlighting is still working. In this comment, you said we just needed to use following in our site.xml:

<skin>
   <groupId>org.apache.maven.skins</groupId>
   <artifactId>maven-fluido-skin</artifactId>
   <version>2.0.1</version>
 </skin>

And we needed to add prettyprint class to the <pre> tag. You added it in your previous PR:

https://github.com/smita1078/checkstyle/blob/2b7fd3535f42cce05f33408f96fbc892fc5650da/src/main/java/com/puppycrawl/tools/checkstyle/site/ExampleMacro.java#L193

Apache also does something similar:

https://github.com/apache/maven-fluido-skin/blob/f090098cd12a3ff361471ae5d915a540dbfb8d22/src/main/resources/META-INF/maven/site.vm#L242

this if condition adds the prettyprint class to their code snippets so their code snippets also gets highlighted, on top of it, they also adds linenums class with prettyprint so they also get line numbers in their snippets:

https://github.com/apache/maven-fluido-skin/blob/f090098cd12a3ff361471ae5d915a540dbfb8d22/src/main/resources/META-INF/maven/site.vm#L236-L240

Am I going in right direction? If I'm correct then I think we didn't needed to add external JS library, we only needed to add prettyprint class to the <pre> tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this if condition adds the prettyprint class to their code snippets so their code snippets also gets highlighted, on top of it, they also adds linenums class with prettyprint so they also get line numbers in their snippets:

Yes, exactly, we don't need any external js library just prettyprint class and pre tags

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants