[doc] Add syntax highlighting for code examples
This commit is contained in:
parent
f918249eda
commit
23d947b4bf
@ -1,4 +1,4 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem 'github-pages', group: :jekyll_plugins
|
||||
gem 'wdm', '>= 0.1.0' if Gem.win_platform?
|
||||
gem 'jekyll'
|
||||
gem 'github-pages'
|
||||
|
@ -16,21 +16,21 @@ GEM
|
||||
ethon (0.10.1)
|
||||
ffi (>= 1.3.0)
|
||||
execjs (2.7.0)
|
||||
faraday (0.12.2)
|
||||
faraday (0.13.0)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
ffi (1.9.18)
|
||||
forwardable-extended (2.6.0)
|
||||
gemoji (3.0.0)
|
||||
github-pages (146)
|
||||
github-pages (151)
|
||||
activesupport (= 4.2.8)
|
||||
github-pages-health-check (= 1.3.5)
|
||||
jekyll (= 3.4.5)
|
||||
jekyll (= 3.5.1)
|
||||
jekyll-avatar (= 0.4.2)
|
||||
jekyll-coffeescript (= 1.0.1)
|
||||
jekyll-default-layout (= 0.1.4)
|
||||
jekyll-feed (= 0.9.2)
|
||||
jekyll-gist (= 1.4.0)
|
||||
jekyll-github-metadata (= 2.5.1)
|
||||
jekyll-gist (= 1.4.1)
|
||||
jekyll-github-metadata (= 2.6.0)
|
||||
jekyll-mentions (= 1.2.0)
|
||||
jekyll-optional-front-matter (= 0.2.0)
|
||||
jekyll-paginate (= 1.1.0)
|
||||
@ -41,23 +41,23 @@ GEM
|
||||
jekyll-seo-tag (= 2.2.3)
|
||||
jekyll-sitemap (= 1.0.0)
|
||||
jekyll-swiss (= 0.4.0)
|
||||
jekyll-theme-architect (= 0.0.4)
|
||||
jekyll-theme-cayman (= 0.0.4)
|
||||
jekyll-theme-dinky (= 0.0.4)
|
||||
jekyll-theme-hacker (= 0.0.4)
|
||||
jekyll-theme-leap-day (= 0.0.4)
|
||||
jekyll-theme-merlot (= 0.0.4)
|
||||
jekyll-theme-midnight (= 0.0.4)
|
||||
jekyll-theme-minimal (= 0.0.4)
|
||||
jekyll-theme-modernist (= 0.0.4)
|
||||
jekyll-theme-primer (= 0.3.1)
|
||||
jekyll-theme-slate (= 0.0.4)
|
||||
jekyll-theme-tactile (= 0.0.4)
|
||||
jekyll-theme-time-machine (= 0.0.4)
|
||||
jekyll-titles-from-headings (= 0.2.0)
|
||||
jekyll-theme-architect (= 0.1.0)
|
||||
jekyll-theme-cayman (= 0.1.0)
|
||||
jekyll-theme-dinky (= 0.1.0)
|
||||
jekyll-theme-hacker (= 0.1.0)
|
||||
jekyll-theme-leap-day (= 0.1.0)
|
||||
jekyll-theme-merlot (= 0.1.0)
|
||||
jekyll-theme-midnight (= 0.1.0)
|
||||
jekyll-theme-minimal (= 0.1.0)
|
||||
jekyll-theme-modernist (= 0.1.0)
|
||||
jekyll-theme-primer (= 0.4.0)
|
||||
jekyll-theme-slate (= 0.1.0)
|
||||
jekyll-theme-tactile (= 0.1.0)
|
||||
jekyll-theme-time-machine (= 0.1.0)
|
||||
jekyll-titles-from-headings (= 0.4.0)
|
||||
jemoji (= 0.8.0)
|
||||
kramdown (= 1.13.2)
|
||||
liquid (= 3.0.6)
|
||||
liquid (= 4.0.0)
|
||||
listen (= 3.0.6)
|
||||
mercenary (~> 0.3)
|
||||
minima (= 2.1.1)
|
||||
@ -73,13 +73,13 @@ GEM
|
||||
activesupport (>= 2)
|
||||
nokogiri (>= 1.4)
|
||||
i18n (0.8.6)
|
||||
jekyll (3.4.5)
|
||||
jekyll (3.5.1)
|
||||
addressable (~> 2.4)
|
||||
colorator (~> 1.0)
|
||||
jekyll-sass-converter (~> 1.0)
|
||||
jekyll-watch (~> 1.1)
|
||||
kramdown (~> 1.3)
|
||||
liquid (~> 3.0)
|
||||
liquid (~> 4.0)
|
||||
mercenary (~> 0.3.3)
|
||||
pathutil (~> 0.9)
|
||||
rouge (~> 1.7)
|
||||
@ -92,9 +92,9 @@ GEM
|
||||
jekyll (~> 3.0)
|
||||
jekyll-feed (0.9.2)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-gist (1.4.0)
|
||||
jekyll-gist (1.4.1)
|
||||
octokit (~> 4.2)
|
||||
jekyll-github-metadata (2.5.1)
|
||||
jekyll-github-metadata (2.6.0)
|
||||
jekyll (~> 3.1)
|
||||
octokit (~> 4.0, != 4.4.0)
|
||||
jekyll-mentions (1.2.0)
|
||||
@ -117,33 +117,46 @@ GEM
|
||||
jekyll-sitemap (1.0.0)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-swiss (0.4.0)
|
||||
jekyll-theme-architect (0.0.4)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-theme-cayman (0.0.4)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-theme-dinky (0.0.4)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-theme-hacker (0.0.4)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-theme-leap-day (0.0.4)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-theme-merlot (0.0.4)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-theme-midnight (0.0.4)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-theme-minimal (0.0.4)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-theme-modernist (0.0.4)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-theme-primer (0.3.1)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-theme-slate (0.0.4)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-theme-tactile (0.0.4)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-theme-time-machine (0.0.4)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-titles-from-headings (0.2.0)
|
||||
jekyll-theme-architect (0.1.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-cayman (0.1.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-dinky (0.1.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-hacker (0.1.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-leap-day (0.1.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-merlot (0.1.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-midnight (0.1.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-minimal (0.1.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-modernist (0.1.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-primer (0.4.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.2)
|
||||
jekyll-theme-slate (0.1.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-tactile (0.1.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-theme-time-machine (0.1.0)
|
||||
jekyll (~> 3.5)
|
||||
jekyll-seo-tag (~> 2.0)
|
||||
jekyll-titles-from-headings (0.4.0)
|
||||
jekyll (~> 3.3)
|
||||
jekyll-watch (1.5.0)
|
||||
listen (~> 3.0, < 3.1)
|
||||
@ -153,7 +166,7 @@ GEM
|
||||
html-pipeline (~> 2.2)
|
||||
jekyll (>= 3.0)
|
||||
kramdown (1.13.2)
|
||||
liquid (3.0.6)
|
||||
liquid (4.0.0)
|
||||
listen (3.0.6)
|
||||
rb-fsevent (>= 0.9.3)
|
||||
rb-inotify (>= 0.9.7)
|
||||
@ -198,6 +211,7 @@ PLATFORMS
|
||||
|
||||
DEPENDENCIES
|
||||
github-pages
|
||||
jekyll
|
||||
|
||||
BUNDLED WITH
|
||||
1.13.6
|
||||
|
@ -46,15 +46,16 @@ feedback_disable: true
|
||||
# feedback_link: "http://helpy.io/"
|
||||
# if you uncomment the previous line, it changes where the feedback link points to
|
||||
|
||||
highlighter: rouge
|
||||
# library used for syntax highlighting
|
||||
|
||||
markdown: kramdown
|
||||
highlighter: rouge
|
||||
kramdown:
|
||||
input: GFM
|
||||
auto_ids: true
|
||||
hard_wrap: false
|
||||
syntax_highlighter: rouge
|
||||
input: GFM
|
||||
auto_ids: true
|
||||
hard_wrap: false
|
||||
syntax_highlighter: rouge
|
||||
syntax_highlighter_opts:
|
||||
css_class: 'highlight'
|
||||
# filter used to process markdown. note that kramdown differs from github-flavored markdown in some subtle ways
|
||||
|
||||
collections:
|
||||
|
@ -87,6 +87,9 @@ entries:
|
||||
- title: PLSQL Rules
|
||||
url: /pmd_rules_plsql.html
|
||||
output: web, pdf
|
||||
- title: Maven POM Rules
|
||||
url: /pmd_rules_pom.html
|
||||
output: web, pdf
|
||||
- title: VisualForce Rules
|
||||
url: /pmd_rules_vf.html
|
||||
output: web, pdf
|
||||
@ -165,4 +168,3 @@ entries:
|
||||
- title: Adding metrics support to a language
|
||||
url: /pmd_devdocs_adding_metrics_support_to_language.html
|
||||
output: web, pdf
|
||||
|
||||
|
@ -48,6 +48,16 @@ public class RuleDocGenerator {
|
||||
private final Path root;
|
||||
private final FileWriter writer;
|
||||
|
||||
/** Maintains mapping from pmd terse language name to rouge highlighter language */
|
||||
private static final Map<String, String> LANGUAGE_HIGHLIGHT_MAPPER = new HashMap<>();
|
||||
|
||||
static {
|
||||
LANGUAGE_HIGHLIGHT_MAPPER.put("ecmascript", "javascript");
|
||||
LANGUAGE_HIGHLIGHT_MAPPER.put("pom", "xml");
|
||||
LANGUAGE_HIGHLIGHT_MAPPER.put("apex", "java");
|
||||
LANGUAGE_HIGHLIGHT_MAPPER.put("plsql", "sql");
|
||||
}
|
||||
|
||||
public RuleDocGenerator(FileWriter writer, Path root) {
|
||||
this.root = Objects.requireNonNull(root, "Root directory must be provided");
|
||||
this.writer = Objects.requireNonNull(writer, "A file writer must be provided");
|
||||
@ -313,7 +323,7 @@ public class RuleDocGenerator {
|
||||
lines.add("**Example(s):**");
|
||||
lines.add("");
|
||||
for (String example : rule.getExamples()) {
|
||||
lines.add("```");
|
||||
lines.add("``` " + mapLanguageForHighlighting(languageTersename));
|
||||
lines.add(StringUtils.stripToEmpty(example));
|
||||
lines.add("```");
|
||||
lines.add("");
|
||||
@ -348,6 +358,20 @@ public class RuleDocGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply maps PMD languages to rouge languages
|
||||
*
|
||||
* @param languageTersename
|
||||
* @return
|
||||
* @see <a href="https://github.com/jneen/rouge/wiki/List-of-supported-languages-and-lexers">List of supported languages</a>
|
||||
*/
|
||||
private static String mapLanguageForHighlighting(String languageTersename) {
|
||||
if (LANGUAGE_HIGHLIGHT_MAPPER.containsKey(languageTersename)) {
|
||||
return LANGUAGE_HIGHLIGHT_MAPPER.get(languageTersename);
|
||||
}
|
||||
return languageTersename;
|
||||
}
|
||||
|
||||
private String getRuleSetKeywords(RuleSet ruleset) {
|
||||
List<String> ruleNames = new LinkedList<>();
|
||||
for (Rule rule : ruleset.getRules()) {
|
||||
|
@ -40,7 +40,7 @@ Avoid jumbled loop incrementers - its usually a mistake, and is confusing even i
|
||||
|
||||
**Example(s):**
|
||||
|
||||
```
|
||||
``` java
|
||||
public class JumbledIncrementerRule1 {
|
||||
public void foo() {
|
||||
for (int i = 0; i < 10; i++) { // only references 'i'
|
||||
@ -81,7 +81,7 @@ Avoid jumbled loop incrementers - its usually a mistake, and is confusing even i
|
||||
|
||||
**Example(s):**
|
||||
|
||||
```
|
||||
``` java
|
||||
public class JumbledIncrementerRule1 {
|
||||
public void foo() {
|
||||
for (int i = 0; i < 10; i++) { // only references 'i'
|
||||
@ -109,7 +109,7 @@ delegating to your superclass.
|
||||
|
||||
**Example(s):**
|
||||
|
||||
```
|
||||
``` java
|
||||
public class Bar { // poor, missing a hashcode() method
|
||||
public boolean equals(Object o) {
|
||||
// do some comparison
|
||||
@ -155,7 +155,7 @@ Avoid jumbled loop incrementers - its usually a mistake, and is confusing even i
|
||||
|
||||
**Example(s):**
|
||||
|
||||
```
|
||||
``` java
|
||||
public class JumbledIncrementerRule1 {
|
||||
public void foo() {
|
||||
for (int i = 0; i < 10; i++) { // only references 'i'
|
||||
|
Loading…
x
Reference in New Issue
Block a user