From fbc2284c427067edbfe67b5b2f2141892d14f803 Mon Sep 17 00:00:00 2001 From: Adam Retter Date: Sat, 6 Jun 2020 11:11:50 +0200 Subject: [PATCH] Add code-block syntax highlighting for GFM --- README.md | 372 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 194 insertions(+), 178 deletions(-) diff --git a/README.md b/README.md index 8c227abb9..0a9830175 100755 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ Properties which can be used as placeholder comes from: Properties are built per-document. You can provide a dependency JAR file to the plugin which contains an implementation of `com.mycila.maven.plugin.license.PropertiesProvider`: -``` +```java public interface PropertiesProvider { Map getAdditionalProperties(AbstractLicenseMojo mojo, Properties currentProperties, Document document); } @@ -230,229 +230,231 @@ The plugin has been designed so that it is very easy to add new supports for new - `JAVADOC_STYLE` (Java-like comments): *.java, *.groovy, *.css, *.cs, *.as, *.aj, *.c, *.h, *.cpp -``` + ```java /** * My comment */ -``` + ``` - `JAVAPKG_STYLE` (like Javadoc, but only for files that are in a Java package, skips the first line): not assigned to a file extension by default (see __Java packages__ below for how to enable it) -``` + ```java package com.example; /*- * My comment */ -``` + ``` - `XML_STYLE` (XML-like comments): *.pom, *.xml, *.xhtml, *.mxml, *.dtd, *.xsd, *.jspx, *.fml, *.xsl, *.html, *.htm, *.kml, *.gsp, *.tld -``` - -``` + ```xml + + ``` - `XML_PER_LINE` (alternate XML-like comments) -``` - - -``` + ```xml + + + ``` (automatically right-adjusts the closing comment) - `DOUBLETILDE_STYLE` (APT-like comments): *.apt -``` - ~~ My comment -``` + ``` + ~~ My comment + ``` - `SCRIPT_STYLE` (Property file or shell comments): *.properties, *.sh, *.py, *.rb, *.pl, *.pm, *.yml, *.yaml -``` - # My comment -``` + ```bash + # My comment + ``` - `HAML_STYLE`: *.haml, *.scaml -``` - -# My comment -``` + ```haml + -# My comment + ``` - `BATCH` (Windows batch comments): *.bat, *.cmd -``` - @REM My comment -``` + ```batch + @REM My comment + ``` - `TEXT` (Text like comments): *.txt -``` - ==== - My comment - ==== -``` + ``` + ==== + My comment + ==== + ``` (4 spaces, then the lines of the header) - `DOUBLEDASHES_STYLE` (Sql like comments): *.sql, *.adb, *.ads, *.e -``` - -- - -- test comment - -- -``` + ```sql + -- + -- test comment + -- + ``` - `DYNASCRIPT_STYLE` (JSP like comments): *.jsp -``` - <%-- - comment - --%> -``` + ```jsp + <%-- + comment + --%> + ``` - `FTL` (FreeMarker like comments): *.ftl -``` - <#-- - comment - --> -``` + ``` + <#-- + comment + --> + ``` - `FTL_ALT` (FreeMarker Alternative Syntax comments) -``` - [#ftl ...] - [#-- - comment - --] -``` + ``` + [#ftl ...] + [#-- + comment + --] + ``` - `SHARPSTAR_STYLE` (Velocity templates comments): *.vm -``` - #* - comment - *# -``` + ``` + #* + comment + *# + ``` - `SEMICOLON_STYLE` (Assembler like comments): *.asm -``` - ; - ; comment - ; -``` + ``` + ; + ; comment + ; + ``` - `BRACESSTAR_STYLE` (Delphi like comments): *.pas -``` - {* - * comment - *} -``` + ```pascal + {* + * comment + *} + ``` - `APOSTROPHE_STYLE` (VisualBasic like comments): *.bas -``` - ' - ' comment - ' -``` + ```basic + ' + ' comment + ' + ``` - `EXCLAMATION_STYLE` (Fortran like comments): *.f -``` - ! - ! comment - ! -``` + ```fortran + ! + ! comment + ! + ``` - `SLASHSTAR_STYLE` (JavaScript like comments): *.js -``` - /* - * comment - */ -``` + ```javascript + /* + * comment + */ + ``` - `DYNASCRIPT3_STYLE` (Coldfusion like comments): *.cfc, *.cfm -``` - -``` + ``` + + ``` - `PERCENT_STYLE` (Teχ like comments): *.cls, *.sty, *.tex -``` - % comment -``` + ```tex + % comment + ``` - `PERCENT3_STYLE` (Erlang like comments): *.erl, *.hrl -``` - %%% - %%% comment - %%% -``` + ```erlang + %%% + %%% comment + %%% + ``` - `EXCLAMATION3_STYLE` (Lisp like comments): *.el -``` - !!! - !!! comment - !!! -``` + ```elisp + !!! + !!! comment + !!! + ``` - `LUA` (Lua like comments): *.lua -``` - --[[ - comment - ]] -``` + ```lua + --[[ + comment + ]] + ``` - `ASP` (Asp like comments): *.asp -``` - <% - ' comment - %> -``` + ```asp + <% + ' comment + %> + ``` - `PHP` (PHP comments): *.php -``` - /* - * comment - */ -``` + ```php + /* + * comment + */ + ``` (inserted after the tag) - `DOUBLESLASH_STYLE` (often used comments style) -``` - // - // comment - // -``` + ```php + // + // comment + // + ``` __Custom mapping__ The plugin enables you to add any other mapping you want.* I.e., if you are developing a Tapestry web application, you may need to add license header in .jwc files and .application files. since these files are xml files, you only need to add in your project pom the following mapping for the license-maven-plugin: - - XML_STYLE - XML_STYLE - DOUBLETILDE_STYLE - SHARPSTAR_STYLE - DOUBLETILDE_STYLE - +```xml + + XML_STYLE + XML_STYLE + DOUBLETILDE_STYLE + SHARPSTAR_STYLE + DOUBLETILDE_STYLE + +``` You can use composed-extensions like *.apt.vm and redefine them, but you will have to nake sure that the mapping of `apt.vm` is _before_ the mapping of the `vm` extension. The order in the mapping section is important: extensions seen first take precedence. @@ -460,47 +462,53 @@ __Java packages__ Another use case for custom mappings is when writing Java code in packages; the licence header should come *after* the package declaration line in this case. Simply add this to the plugin configuration: - - JAVAPKG_STYLE - +```xml + + JAVAPKG_STYLE + +``` ### Changing header style definitions ### In license-maven-plugin, each header style is defined by patterns to detect it and also strings to insert it correctly in files. If we take for example the Javadoc style header definition. It is defined as follow: - - - - /** - * - */ - - - (\s|\t)*/\*.*$ - .*\*/(\s|\t)*$ - false - true - false - - +```xml + + + + /** + * + */ + + + (\s|\t)*/\*.*$ + .*\*/(\s|\t)*$ + false + true + false + + +``` And for XML: - - - - - - ]]> - - $]]> - - (\s|\t)*$]]> - false - true - false - - +```xml + + + + + + ]]> + + $]]> + + (\s|\t)*$]]> + false + true + false + + +``` With the `headerDefinitions` option, you can redefine existing header styles and also add some if we do not support the styles you want yet. You just have to provide a list of `headerDefinition` containing a resource name. Like the header, the resource is searched on the file system, in the classpath of the project, the plugin and also as a URL. @@ -509,18 +517,20 @@ __Full Example__ This page will show you how you can define extended header definitions to fit your needs. The next example will define headers in a _region_ area allowed in C# source files: - - - - #region LicenseEOL/** - * - */EOL#endregion - #region.*^EOL/\*\*.*$ - \*/EOL#endregion" - true - true - - +```xml + + + + #region LicenseEOL/** + * + */EOL#endregion + #region.*^EOL/\*\*.*$ + \*/EOL#endregion" + true + true + + +``` * The `EOL` string will be replaced with the proper end of line depending the file format your are processing. * We also have defined the _skipLine_ attribute to skip the region tags (which starts with a '#') @@ -529,18 +539,23 @@ This page will show you how you can define extended header definitions to fit yo You now have to add this new header definition file to the plugin configuration. It is done as the following in your pom: - - yourdefinition.xml - +```xml + + yourdefinition.xml + +``` You now have to add the new mapping for `*.cs` files to use this new header definition. It is done as the following in your pom: - - CSREGION_STYLE - +```xml + + CSREGION_STYLE + +``` And it should generate headers like: +```csharp #region License /** * Copyright (C) 2008 http://code.google.com/p/license-maven-plugin/ @@ -558,3 +573,4 @@ And it should generate headers like: * limitations under the License. */ #endregion +``` \ No newline at end of file