Purpose
Pretty Diff is a language aware code comparison tool, beautifier, minifier, and parser for a variety of languages.
Pretty Diff was created to compare code samples for various languages regardless of differences in comments, white space, and other factors. Currently, the project operates by beautifying code and then comparing the beautified product of the code samples. The goal in a future version is to introduce the comparison step directly into the beautifiers between the parse step and the beautification step to become a truely language aware code comparison and analysis tool.
Goals
- portability
- The project should be immediately available cross platform, across various interfaces, and without a build process. All documentation and required supporting artifacts are included with the project code.
- productivity
- The project should save a developer substantial time by making code easier to read against a variety of settings and reduce the steps to complete a given code analysis task.
- reproducibility
- Code pushed through the project in any one mode should be equally restorable to its previous state using a different mode.
- simplicity
- The project should do more with less code. The intended audience of this project are software developers, who may need to modify the project code to fit custom needs. Less code means increased portability. Clearer simple code allows separation of concerns, and cleaner organization.
Supported Operations (modes)
Pretty Diff currently supports these four operations:
- diff
- The code comparison mode. This is the default mode and the only mode to require two code samples.
- beautify
- Pretty Diff has progressively moved from community driven dependencies to custom parsers to accomplish code beautification for a diversity of features and requests.
- minify
- Each of Pretty Diff's beautification libraries has a minify feature. The goal is to reduce code size but only to such an extent that the code can be restored to its prior state through beautification, excluding code comments.
- parse
- Most code parsers generate a final product called an Abstract Syntax Tree (AST). Pretty Diff, instead, leans on the sparser project which produces parse output as a data table.
Supported Languages
- markup
- Apache Velocity
- ASP Inline Expression
- CFML (ColdFusion Markup Language)
- Django Inline HTML
- Dust.js
- EEX Elixir Templates
- EJS (Embedded JavaScript) Templates
- ERB (Embedded Ruby)
- FreeMarker
- Genshi
- Handlebars
- HTL (HTML Templating Language)
- HTML
- Jekyll
- Jinja
- JSTL (Java Standard Tag Library)
- Liquid
- Mustache
- Nunjucks
- SGML
- SilverStripe
- Spacebars templates
- ThymeLeaf
- Underscore Templates (TPL)
- Twig
- Vapor Leaf
- Vash
- Volt
- XML
- XSLT
- script
- style
45 total languages
Key of terms
- Environment
- Describes where the option is available, such as whether exclusively used with Node or in a browser.
- Type
- The data type of the option's value, such as string, number, or boolean.
- Mode
- Some options are only available in certain modes, such as beautification or minification.
- Lexer
- Some options are only available to certain language groups. Markup specific options, for example, will not work with JavaScript language.
- Default
- The option's default value.
attribute_sort
Description
Alphanumerically sort markup attributes. Attribute sorting is ignored on tags that contain attributes template attributes.Environment
anyType
booleanMode
anyLexer
markupDefault
falseAs labeled in the HTML tool
Sort Attributes
attribute_sort_list
Description
A comma separated list of attribute names. Attributes will be sorted according to this list and then alphanumerically. This option requires 'attribute_sort' have a value of true.Environment
anyType
stringMode
anyLexer
markupDefault
As labeled in the HTML tool
Sort Attribute List
brace_line
Description
If true an empty line will be inserted after opening curly braces and before closing curly braces.Environment
anyType
booleanMode
beautifyLexer
scriptDefault
falseAs labeled in the HTML tool
Brace Lines
brace_padding
Description
Inserts a space after the start of a container and before the end of the container if the contents of that container are not indented; such as: conditions, function arguments, and escaped sequences of template strings.Environment
anyType
booleanMode
beautifyLexer
scriptDefault
falseAs labeled in the HTML tool
Brace Padding
brace_style
Description
Emulates JSBeautify's brace_style option using existing Pretty Diff options.Environment
anyType
stringMode
beautifyLexer
scriptAccepted Values
- collapse
- Sets options.format_object to 'indent' and options.neverflatten to true.
- collapse-preserve-inline
- Sets options.bracepadding to true and options.format_object to 'inline'.
- expand
- Sets options.braces to true, options.format_object to 'indent', and options.neverflatten to true.
- none
- Ignores this option
Default
noneAs labeled in the HTML tool
Brace Style
braces
Description
Determines if opening curly braces will exist on the same line as their condition or be forced onto a new line. (Allman style indentation).Environment
anyType
booleanMode
beautifyLexer
scriptDefault
falseAs labeled in the HTML tool
Style of Indent
case_space
Description
If the colon separating a case's expression (of a switch/case block) from its statement should be followed by a space instead of indentation, thereby keeping the case on a single line of code.Environment
anyType
booleanMode
beautifyLexer
scriptDefault
falseAs labeled in the HTML tool
Space Following Case
color
Description
The color scheme of the reports.Environment
anyType
stringMode
anyLexer
anyAccepted Values
- canvas
- A light brown color scheme
- shadow
- A black and ashen color scheme
- white
- A white and pale grey color scheme
Default
whiteAs labeled in the HTML tool
Color
comment_line
Description
If a blank new line should be forced above comments.Environment
anyType
booleanMode
beautifyLexer
markupDefault
falseAs labeled in the HTML tool
Force an Empty Line Above Comments
comments
Description
This will determine whether comments should always start at position 0 of each line or if comments should be indented according to the code.Environment
anyType
booleanMode
beautifyLexer
anyDefault
falseAs labeled in the HTML tool
Indent Comments
complete_document
Description
Allows a preference for generating a complete HTML document instead of only generating content.Environment
anyType
booleanMode
anyLexer
markupDefault
falseAs labeled in the HTML tool
Generate A Complete HTML File
compressed_css
Description
If CSS should be beautified in a style where the properties and values are minifed for faster reading of selectors.Environment
anyType
booleanMode
beautifyLexer
styleDefault
falseAs labeled in the HTML tool
Compressed CSS
conditional
Description
If true then conditional comments used by Internet Explorer are preserved at minification of markup.Environment
anyType
booleanMode
minifyLexer
markupDefault
falseAs labeled in the HTML tool
IE Comments (HTML Only)
config
Description
By default Pretty Diff will look into the directory structure contain the value of option 'source' for a file named `.prettydiffrc` for saved option settings. This option allows a user to specify any file at any location in the local file system for configuration settings. A value of 'none' tells the application to bypass reading any configuration file.Environment
nodeType
stringMode
anyLexer
anyDefault
As labeled in the HTML tool
Custom Config File Location
content
Description
This will normalize all string content to 'text' so as to eliminate some differences from the output.Environment
anyType
booleanMode
diffLexer
anyDefault
falseAs labeled in the HTML tool
Ignore Content
correct
Description
Automatically correct some sloppiness in code.Environment
anyType
booleanMode
anyLexer
anyDefault
falseAs labeled in the HTML tool
Fix Sloppy Code
crlf
Description
If line termination should be Windows (CRLF) format. Unix (LF) format is the default.Environment
anyType
booleanMode
anyLexer
anyDefault
falseAs labeled in the HTML tool
Line Termination
css_insert_lines
Description
Inserts new line characters between every CSS code block.Environment
anyType
booleanMode
beautifyLexer
styleDefault
falseAs labeled in the HTML tool
Insert Empty Lines
diff
Description
The code sample to be compared to 'source' option. This is required if mode is 'diff'.Environment
anyType
stringMode
diffLexer
anyDefault
As labeled in the HTML tool
Code to Compare
diff_comments
Description
If true then comments will be preserved so that both code and comments are compared by the diff engine.Environment
anyType
booleanMode
diffLexer
anyDefault
falseAs labeled in the HTML tool
Code Comments
diff_context
Description
This shortens the diff output by allowing a specified number of equivalent lines between each line of difference. This option is only used with diff_format:html.Environment
anyType
numberMode
diffLexer
anyDefault
-1As labeled in the HTML tool
Context Size
diff_format
Description
The format of the output. The command line output format is text, similar to Unix 'diff'.Environment
anyType
stringMode
diffLexer
anyAccepted Values
- html
- An HTML format for embedding in web pages, or as a complete web page if document_complete is true.
- json
- A JSON format.
- text
- Formatted similar to the Unix 'diff' command line utility.
Default
textAs labeled in the HTML tool
Diff Format
diff_label
Description
This allows for a descriptive label for the diff file code of the diff HTML output.Environment
anyType
stringMode
diffLexer
anyDefault
New SampleAs labeled in the HTML tool
Label for Diff Sample
diff_rendered_html
Description
Compares complete HTML documents and injects custom CSS so that the differences display not in the code, but in the rendered page in a browser. This option is currently confined only to markup languages, read_method file, and mode diff. Option diff_format is ignored.Environment
anyType
booleanMode
diffLexer
markupDefault
falseAs labeled in the HTML tool
Compare Rendered HTML
diff_space_ignore
Description
If white space only differences should be ignored by the diff tool.Environment
anyType
booleanMode
diffLexer
anyDefault
falseAs labeled in the HTML tool
Remove White Space
diff_view
Description
This determines whether the diff HTML output should display as a side-by-side comparison or if the differences should display in a single table column.Environment
anyType
stringMode
diffLexer
anyAccepted Values
- inline
- A single column where insertions and deletions are vertically adjacent.
- sidebyside
- Two column comparison of changes.
Default
sidebysideAs labeled in the HTML tool
Diff View Type
else_line
Description
If else_line is true then the keyword 'else' is forced onto a new line.Environment
anyType
booleanMode
beautifyLexer
scriptDefault
falseAs labeled in the HTML tool
Else On New Line
end_comma
Description
If there should be a trailing comma in arrays and objects. Value "multiline" only applies to modes beautify and diff.Environment
anyType
stringMode
beautifyLexer
scriptAccepted Values
- always
- Always ensure there is a tailing comma
- never
- Remove trailing commas
- none
- Ignore this option
Default
neverAs labeled in the HTML tool
Trailing Comma
end_quietly
Description
A node only option to determine if terminal summary data should be logged to the console.Environment
nodeType
stringMode
anyLexer
anyAccepted Values
- default
- Default minimal summary
- log
- Verbose logging
- quiet
- No extraneous logging
Default
defaultAs labeled in the HTML tool
Log Summary to Console
force_attribute
Description
If all markup attributes should be indented each onto their own line.Environment
anyType
booleanMode
beautifyLexer
markupDefault
falseAs labeled in the HTML tool
Force Indentation of All Attributes
force_indent
Description
Will force indentation upon all content and tags without regard for the creation of new text nodes.Environment
anyType
booleanMode
beautifyLexer
markupDefault
falseAs labeled in the HTML tool
Force Indentation of All Content
format_array
Description
Determines if all array indexes should be indented, never indented, or left to the default.Environment
anyType
stringMode
beautifyLexer
scriptAccepted Values
- default
- Default formatting
- indent
- Always indent each index of an array
- inline
- Ensure all array indexes appear on a single line
Default
defaultAs labeled in the HTML tool
Formatting Arrays
format_object
Description
Determines if all object keys should be indented, never indented, or left to the default.Environment
anyType
stringMode
beautifyLexer
scriptAccepted Values
- default
- Default formatting
- indent
- Always indent each key/value pair
- inline
- Ensure all key/value pairs appear on the same single line
Default
defaultAs labeled in the HTML tool
Formatting Objects
function_name
Description
If a space should follow a JavaScript function name.Environment
anyType
booleanMode
beautifyLexer
scriptDefault
falseAs labeled in the HTML tool
Space After Function Name
help
Description
A node only option to print documentation to the console. The value determines where to wrap text.Environment
nodeType
numberMode
anyLexer
anyDefault
80As labeled in the HTML tool
Help Wrapping Limit
indent_char
Description
The string characters to comprise a single indentation. Any string combination is accepted.Environment
anyType
stringMode
beautifyLexer
anyDefault
As labeled in the HTML tool
Indentation Characters
indent_level
Description
How much indentation padding should be applied to beautification? This option is internally used for code that requires switching between libraries.Environment
anyType
numberMode
beautifyLexer
anyDefault
0As labeled in the HTML tool
Indentation Padding
indent_size
Description
The number of 'indent_char' values to comprise a single indentation.Environment
anyType
numberMode
beautifyLexer
anyDefault
4As labeled in the HTML tool
Indent Size
jsscope
Description
An educational tool to generate HTML output of JavaScript code to identify scope regions and declared references by color. This option is ignored unless the code language is JavaScript or TypeScript.Environment
anyType
stringMode
beautifyLexer
scriptAccepted Values
- html
- generates HTML output with escaped angle braces and ampersands for embedding as code, which is handy in code producing tools
- none
- prevents use of this option
- report
- generates HTML output that renders in web browsers
Default
noneAs labeled in the HTML tool
JavaScript Scope Identification
language
Description
The lowercase single word common name of the source code's programming language. The value 'auto' imposes language and lexer auto-detection, which ignores deliberately specified lexer values. The value 'text' is converted to 'auto' if options 'mode' is not 'diff'. Value 'text' allows literal comparisons.Environment
anyType
stringMode
anyLexer
anyDefault
autoAs labeled in the HTML tool
Language
language_default
Description
The fallback option if option 'lang' is set to 'auto' and a language cannot be detected.Environment
anyType
stringMode
anyLexer
anyDefault
textAs labeled in the HTML tool
Language Auto-Detection Default
language_name
Description
The formatted proper name of the code sample's language for use in reports read by people.Environment
anyType
stringMode
anyLexer
anyDefault
JavaScriptAs labeled in the HTML tool
Formatted Name of the Code's Language
lexer
Description
This option determines which sets of rules to use in the language parser. If option 'language' has a value of 'auto', which is the default value, this option is ignored. The value 'text' is converted to 'auto' if options 'mode' is not 'diff'. Value 'text' allows literal comparisons.Environment
anyType
stringMode
anyLexer
anyAccepted Values
- auto
- The value 'auto' imposes language and lexer auto-detection, which ignores deliberately specified language values.
- markup
- parses languages like XML and HTML
- script
- parses languages with a C style syntax, such as JavaScript
- style
- parses CSS like languages
Default
autoAs labeled in the HTML tool
Parsing Lexer
list_options
Description
A Node.js only option that writes current option settings to the console.Environment
nodeType
booleanMode
anyLexer
anyDefault
falseAs labeled in the HTML tool
Options List
method_chain
Description
When to break consecutively chained methods and properties onto separate lines. A negative value disables this option. A value of 0 ensures method chains are never broken.Environment
anyType
numberMode
beautifyLexer
scriptDefault
3As labeled in the HTML tool
Method Chains
minify_keep_comments
Description
Prevents minification from stripping out comments.Environment
anyType
booleanMode
minifyLexer
anyDefault
falseAs labeled in the HTML tool
Keep Comments
minify_wrap
Description
Whether minified script should wrap after a specified character width. This option requires a value from option 'wrap'.Environment
anyType
booleanMode
minifyLexer
scriptDefault
falseAs labeled in the HTML tool
Minification Wrapping
mode
Description
The operation to be performed.Environment
anyType
stringMode
anyLexer
anyAccepted Values
- beautify
- beautifies code and returns a string
- diff
- returns either command line list of differences or an HTML report
- minify
- minifies code and returns a string
- parse
- using option 'parseFormat' returns an object with shallow arrays, a multidimensional array, or an HTML report
Default
diffAs labeled in the HTML tool
Mode
never_flatten
Description
If destructured lists in script should never be flattend.Environment
anyType
booleanMode
beautifyLexer
scriptDefault
falseAs labeled in the HTML tool
Never Flatten Destructured Lists
new_line
Description
Insert an empty line at the end of output.Environment
anyType
booleanMode
anyLexer
anyDefault
falseAs labeled in the HTML tool
New Line at End of Code
no_case_indent
Description
If a case statement should receive the same indentation as the containing switch block.Environment
anyType
booleanMode
beautifyLexer
scriptDefault
falseAs labeled in the HTML tool
Case Indentation
no_lead_zero
Description
Whether leading 0s in CSS values immediately preceding a decimal should be removed or prevented.Environment
anyType
booleanMode
anyLexer
styleDefault
falseAs labeled in the HTML tool
Leading 0s
no_semicolon
Description
Removes semicolons that would be inserted by ASI. This option is in conflict with option 'correct' and takes precedence over conflicting features. Use of this option is a possible security/stability risk.Environment
anyType
booleanMode
beautifyLexer
scriptDefault
falseAs labeled in the HTML tool
No Semicolons
node_error
Description
A Node.js only option if parse errors should be written to the console.Environment
nodeType
booleanMode
anyLexer
anyDefault
falseAs labeled in the HTML tool
Write Parse Errors in Node
object_sort
Description
Sorts markup attributes and properties by key name in script and style.Environment
anyType
booleanMode
beautifyLexer
anyDefault
falseAs labeled in the HTML tool
Object/Attribute Sort
output
Description
A file path for which to write output. If this option is not specified output will be printed to the shell.Environment
nodeType
stringMode
anyLexer
anyDefault
As labeled in the HTML tool
Output Location
parse_format
Description
Determines the output format for 'parse' mode.Environment
anyType
stringMode
parseLexer
anyAccepted Values
- htmltable
- generates the 'table' type output for the DOM but escapes the HTML tags for rendering as HTML code in a HTML tool
- parallel
- returns an object containing series of parallel arrays
- sequential
- returns an array where each index is a child object containing the parsed token and all descriptive data
- table
- generates a colorful grid of output for either the dom or command line interface
Default
parallelAs labeled in the HTML tool
Parse Format
parse_space
Description
Whether whitespace tokens should be included in markup parse output.Environment
anyType
booleanMode
parseLexer
markupDefault
falseAs labeled in the HTML tool
Retain White Space Tokens in Parse Output
preserve
Description
The maximum number of consecutive empty lines to retain.Environment
anyType
numberMode
beautifyLexer
anyDefault
0As labeled in the HTML tool
Preserve Consecutive New Lines
preserve_comment
Description
Prevent comment reformatting due to option wrap.Environment
anyType
booleanMode
beautifyLexer
anyDefault
falseAs labeled in the HTML tool
Eliminate Word Wrap Upon Comments
preserve_text
Description
If text in the provided markup code should be preserved exactly as provided. This option eliminates beautification and wrapping of text content.Environment
anyType
booleanMode
anyLexer
markupDefault
falseAs labeled in the HTML tool
Preserve Markup Text White Space
quote
Description
If true and mode is 'diff' then all single quote characters will be replaced by double quote characters in both the source and diff file input so as to eliminate some differences from the diff report HTML output.Environment
anyType
booleanMode
diffLexer
anyDefault
falseAs labeled in the HTML tool
Normalize Quotes
quote_convert
Description
If the quotes of script strings or markup attributes should be converted to single quotes or double quotes.Environment
anyType
stringMode
anyLexer
anyAccepted Values
- double
- Converts single quotes to double quotes
- none
- Ignores this option
- single
- Converts double quotes to single quotes
Default
noneAs labeled in the HTML tool
Indent Size
read_method
Description
The option determines how Node.js should receive input. All output will be printed to the shell unless the option 'output' is specified, which will write output to a file.Environment
nodeType
stringMode
anyLexer
anyAccepted Values
- auto
- changes to value subdirectory, file, or screen depending on source resolution
- directory
- process all files in the specified directory only
- file
- reads a file and outputs to a file. file requires option 'output'
- screen
- reads from screen and outputs to screen
- subdirectory
- process all files in a directory and its subdirectories
Default
autoAs labeled in the HTML tool
Read Method
selector_list
Description
If comma separated CSS selectors should present on a single line of code.Environment
anyType
booleanMode
beautifyLexer
styleDefault
falseAs labeled in the HTML tool
Indent Size
semicolon
Description
If true and mode is 'diff' and lang is 'javascript' all semicolon characters that immediately precede any white space containing a new line character will be removed so as to eliminate some differences from the code comparison.Environment
anyType
booleanMode
diffLexer
scriptDefault
falseAs labeled in the HTML tool
Indent Size
source
Description
The source code or location for interpretation. This option is required for all modes.Environment
anyType
stringMode
anyLexer
anyDefault
As labeled in the HTML tool
Source Sample
source_label
Description
This allows for a descriptive label of the source file code for the diff HTML output.Environment
anyType
stringMode
diffLexer
anyDefault
Source SampleAs labeled in the HTML tool
Label for Source Sample
space
Description
Inserts a space following the function keyword for anonymous functions.Environment
anyType
booleanMode
beautifyLexer
scriptDefault
trueAs labeled in the HTML tool
Function Space
space_close
Description
Markup self-closing tags end will end with ' />' instead of '/>'.Environment
anyType
booleanMode
beautifyLexer
markupDefault
falseAs labeled in the HTML tool
Close Markup Self-Closing Tags with a Space
styleguide
Description
Provides a collection of option presets to easily conform to popular JavaScript style guides.Environment
anyType
stringMode
beautifyLexer
scriptAccepted Values
- airbnb
- https://github.com/airbnb/javascript
- crockford
- http://jslint.com/
- https://google.github.io/styleguide/jsguide.html
- jquery
- https://contribute.jquery.org/style-guide/js/
- jslint
- http://jslint.com/
- mediawiki
- https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript
- mrdoob
- https://github.com/mrdoob/three.js/wiki/Mr.doob's-Code-Style%E2%84%A2
- none
- Ignores this option
- semistandard
- https://github.com/Flet/semistandard
- standard
- https://standardjs.com/
- yandex
- https://github.com/ymaps/codestyle/blob/master/javascript.md
Default
noneAs labeled in the HTML tool
Script Styleguide
summary_only
Description
Node only option to output only number of differences.Environment
nodeType
booleanMode
diffLexer
anyDefault
falseAs labeled in the HTML tool
Output Diff Only Without A Summary
tag_merge
Description
Allows immediately adjacement start and end markup tags of the same name to be combined into a single self-closing tag.Environment
anyType
booleanMode
anyLexer
markupDefault
falseAs labeled in the HTML tool
Merge Adjacent Start and End tags
tag_sort
Description
Sort child items of each respective markup parent element.Environment
anyType
booleanMode
anyLexer
markupDefault
falseAs labeled in the HTML tool
Sort Markup Child Items
ternary_line
Description
If ternary operators in JavaScript ? and : should remain on the same line.Environment
anyType
booleanMode
beautifyLexer
scriptDefault
falseAs labeled in the HTML tool
Keep Ternary Statements On One Line
top_comments
Description
If mode is 'minify' this determines whether comments above the first line of code should be kept.Environment
anyType
booleanMode
minifyLexer
anyDefault
falseAs labeled in the HTML tool
Retain Comment At Code Start
unformatted
Description
If markup tags should have their insides preserved. This option is only available to markup and does not support child tokens that require a different lexer.Environment
anyType
booleanMode
anyLexer
markupDefault
falseAs labeled in the HTML tool
Markup Tag Preservation
variable_list
Description
If consecutive JavaScript variables should be merged into a comma separated list or if variables in a list should be separated.Environment
anyType
stringMode
anyLexer
scriptAccepted Values
- each
- Ensurce each reference is a single declaration statement.
- list
- Ensure consecutive declarations are a comma separated list.
- none
- Ignores this option.
Default
noneAs labeled in the HTML tool
Variable Declaration Lists
version
Description
A Node.js only option to write the version information to the console.Environment
nodeType
booleanMode
anyLexer
anyDefault
falseAs labeled in the HTML tool
Version
vertical
Description
If lists of assignments and properties should be vertically aligned. This option is not used with the markup lexer.Environment
anyType
booleanMode
beautifyLexer
anyDefault
falseAs labeled in the HTML tool
Vertical Alignment
wrap
Description
Character width limit before applying word wrap. A 0 value disables this option. A negative value concatenates script strings.Environment
anyType
numberMode
anyLexer
anyDefault
0As labeled in the HTML tool
Wrap
Get the Code
Various options are available for greater portability
-
Github
git clone https://github.com/prettydiff/prettydiff.git
-
NPM, Pretty Diff
Pretty Diff is available on NPM at https://www.npmjs.com/package/prettydiff.
Setup/Run the Application
Setup as a local application
git clone https://github.com/prettydiff/prettydiff.git
cd prettydiff
npm install typescript -g
npm install eslint -g
npm install
tsc --pretty
node js/services build
Setup as a global NPM package
npm install typescript -g
npm install eslint -g
npm install prettydiff -g
prettydiff build
To get started with the application on the command line try the commands command to see a list of available features and detailed instructions: node js/services commands
To run the application in a web browser with Pretty Diff's HTML execute the server command: node js/services server
or simply navigate your browser to the project's index.xhtml file in the local filesystem.
To run the application in a different browser application simply reference or include the built js/browser.js file. See the third party demo for an example.
The .prettydiffrc File
To ease configuration Pretty Diff provides support for a .prettydiffrc file that stores option settings as a sort of saved preferences. The .prettydiffrc file is only used when the application is executed via Node.js via the supplied js/services.js file, but is checked each time the application executes. This file supports two formats: JavaScript logic and JSON. Options api, diff, and source are not supported in the .prettydiffrc file.
Pretty Diff will look for the .prettydiffrc file starting in the directory specified or the directory containing a specified file. If no .prettydiffrc file is present Pretty Diff will check the next higher directory until reaching root. If the option read_method is value screen or auto and resolves to value screen then the starting location to look for the .prettydiffrc file will be the terminal's current working directory.
JSON Format
In order for the options to be accepted by the application the provided options must match a defined option name and the corresponding value must be the proper data type. In the case where an option is string type and accepts a specified set of values the specified value much match one of the supported value names. Here are some examples:
Good {"indent_size": 6, "format_object": "inline"}
Bad {"indent_size": " ", "format_object": "inline"}
This is bad, because the "indent_size" option is provided a value with the incorrect data type. It will be ignored from the application, but the specified "format_object" option will be accepted.
Bad {"indent_size": 3, "format_object": "never"}
The value for option "format_object" is the correct data type, but that option accepts one of three values and "never" is not a supported value. Pretty Diff will accept the "indent_size" option with value 3, but will ignore the specified "format_object".
JavaScript Format
To give users greater control and flexibility over the application a JavaScript format is also accepted. This will allow users to specify options conditionally. Please start with this following template:
(function rc() {
"use strict";
const rclogic = function rc_logic(options) {
// edit below this line
// edit above this line
return options;
};
module.exports = rclogic;
}());
JavaScript logic that deviates from the template may result in an error causing the Pretty Diff application to no longer run. For security concerns no use of require, import, and no other use of export is permitted. Ignoring these security concerns will cause the file to be ignored. The options must be assigned with conforming value data types exactly as specified under the JSON Format section in order to be accepted. Examples:
(function rc() {
"use strict";
const rclogic = function rc_logic(options) {
// edit below this line
if (options.mode === "beautify" && options.lexer === "style") {
options.indent_size = 6;
}
if (options.source.length > 2500) {
options.indent_size = 2;
}
// edit above this line
return options;
};
module.exports = rclogic;
}());
@documentation
Prettydiff created by Austin Cheney originally on 3 Mar 2009. https://prettydiff.com/
As of version 2.1.17 Pretty Diff is licensed under CC0. Please see license for additional information.
Precedence
Pretty Diff sets option values according to this order of precedence from highest priority to lowest:
- The styleguide option, which is only used in the beautify/script.ts library.
- The Pretty Diff comment.
- User supplied options
- Default option values
Pretty Diff Comment
The Pretty Diff option comment is similar in convention to the JSLint option comment. In the case where multiple Pretty Diff option comments are present in a document only the first will be processed. If in diff mode and an option comment is present in the diff code but not the source code then this option comment will be processed. In order for the option comment to be recognized it must start with prettydiff.com. The options are listed in this comment separated by commas as a colon separated name value pair. The options match the exact value definition for the Pretty Diff application properties above and options that allow abstract values must have their values enclosed in either single or double quotes. The options can be listed in any order. The option comment should be separated from other comments to prevent any possibility of corrupted interpretation. These are examples of appropriate option strings:
-
/*prettydiff.com mode:beautify, language:javascript, indent_char:"abc"*/
-
<!--prettydiff.com mode: beautify, language: javascript, indent_char: "abc", html: true -->
Web Tool URI Parameters
- ace
- If this parameter is provided with a false value the Ace code editor will be discarded in favor of regular HTML textarea elements.
- localstorage
- Disables or enables all storage in the browser.
Any defined option name is also supported as a parameter.
Here is an example:
https://prettydiff.com/?source=https://duckduckgo.com&mode=beautify&correct=true&localstorage=false
Contribution Guide
For questions, features, or bug reports please open an issue on Github. If you are executing from the command line insert the debug word at the end of your command and Pretty Diff will generate an issue template in markdown format that you can simply copy and paste into Github.
If you wish to propose code changes then follow these steps:
- Fork the repository on Github and then clone down the fork to your local computer.
- Create a new branch for your changes:
git checkout -b branchName
- Create test units. A pull request will be rejected without tests unless there is a strong expection. The build process employs different kinds of tests.
- The simulation command runs just the simulation tests. These tests validate features of the command line operation. These tests are stored in the file tests/simulations.ts.
- The validation command runs the code unit tests that validate the beautification and minification functions. These tests are stored in the tests/formatted and tests/raw directories. A file in the raw directory containing a test unit is compared against a same named file in the formatted directory storing the Pretty Diff output.
- The diff tests are execution as a part of the simulation tests. The code units for the diff tests are stored in the directories tests/diffbase and tests/diffnew.
- The parser has its own unit tests that are part of that project. Please see its Github repository: sparser.
- Run the unit tests to verify if your changes are breaking things:
node js/services test
- Finally, open a pull request on Github or if you are having trouble with the build open a Github issue and ask for help.
Troubleshooting Help
A few helpful tips in case you get stuck.
- If an update to the code breaks the build and the application can no longer build try recompiling from TypeScript and then running the Pretty Diff build again. The command is
tsc --pretty
. - Ensure dependencies are up to date. Try running
npm update
. A version mismatch between Pretty Diff and the parser could result in unpredictable behavior. - If you need help generating the appropriate details for a Github issue try using the debug feature. Simply run your command on the terminal and add debug or prettydiff_debug to generate an issue template in markdown format.
- When everything seems correct on the Pretty Diff side but the result is still wrong there could be a defect in the parser. Clone the parser as a separate project and run its tests by using the validation command. You could also use the parser's server command to run a frontend in your browser that is easier to read. The parser is at sparser
- If you modify the build code you have to rebuild twice to test the changes. This is because the first build compiles the updated code and the second build executes the updated code.