Skip to content

Commit

Permalink
fixes #64
Browse files Browse the repository at this point in the history
  • Loading branch information
prettydiff committed Dec 28, 2018
1 parent 4ff63d7 commit 14f7210
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 21 deletions.
1 change: 1 addition & 0 deletions lexers/markup.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ The markup lexer uses tag names, even if the tag is a template tag, as the stack

## markup options
* **preserve_text** - Preserves text content from formatting or word wrapping.
* **quote_convert** - Values: *none*, *double*, *single*. Whether quotes should be converted to double quote or single quote characters of standard quoteed XML/HTML attributes. The *none* value disables this option.
* **tag_merge** - Merges start and end tag pairs, if these tags are adjacent or separated only by white space, into a single singleton tag.
* **tagSort** - Sorts tags by tag name alphabetically amongst siblings under the same parent.
78 changes: 70 additions & 8 deletions lexers/markup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,55 @@
],
store:string[] = [];
const len:number = attstore.length,
qc:"none"|"double"|"single" = (options.lexerOptions.markup.quote_convert === undefined)
? "none"
: options.lexerOptions.markup.quote_convert,
begin:number = parse.count,
stack:string = tname.replace(/\/$/, ""),
syntax:string = "<{\"'=/",
convertQ = function lexer_markup_tag_attributeRecord_convertQ():void {
if (ignoreme === true || qc === "none" || record.types !== "attribute" || (qc === "single" && record.token.indexOf("\"") < 0) || (qc === "double" && record.token.indexOf("'") < 0)) {
recordPush(data, record, "");
} else {
let ee:number = 0,
inner:boolean = false;
const chars:string[] = record.token.split(""),
eq:number = record.token.indexOf("="),
len:number = chars.length - 1;
if (chars[eq + 1] !== "\"" && qc === "single" && chars[chars.length - 1] !== "\"") {
recordPush(data, record, "");
} else if (chars[eq + 1] !== "'" && qc === "double" && chars[chars.length - 1] !== "'") {
recordPush(data, record, "");
} else {
ee = eq + 2;
if (qc === "double") {
if (record.token.slice(eq + 2, len).indexOf("\"") > -1) {
inner = true;
}
chars[eq + 1] = "\"";
chars[chars.length - 1] = "\"";
} else {
if (record.token.slice(eq + 2, len).indexOf("'") > -1) {
inner = true;
}
chars[eq + 1] = "'";
chars[chars.length - 1] = "'";
}
if (inner === true) {
do {
if (chars[ee] === "'" && qc === "single") {
chars[ee] = "\"";
} else if (chars[ee] === "\"" && qc === "double") {
chars[ee] = "'";
}
ee = ee + 1;
} while (ee < len);
}
record.token = chars.join("");
recordPush(data, record, "");
}
}
},
templateAtt = function lexer_markup_tag_attributeRecord_templateAtt(sample:string, token:string):void {
if (sample.charAt(0) === "{" && "{%#@:/?^<+~=".indexOf(sample.charAt(1)) > -1) {
record.types = "template_attribute";
Expand All @@ -360,17 +406,33 @@
record.types = "template_attribute";
} else {
record.token = token;
recordPush(data, record, "");
convertQ();
return;
}
record.token = token;
recordPush(data, record, "");
convertQ();
record.types = "attribute";
};

if (attstore.length < 1) {
return;
}

/*if (ignoreme === false && (qc === "double" || qc === "single")) {
if (c[ee - 1] === "\\") {
if (slashes(ee - 1) === true) {
if (qc === "double" && c[ee] === "'") {
build.pop();
} else if (qc === "single" && c[ee] === "\"") {
build.pop();
}
}
} else if (qc === "double" && c[ee] === "\"" && c[a] === "'") {
c[ee] = "\\\"";
} else if (qc === "single" && c[ee] === "'" && c[a] === "\"") {
c[ee] = "\\'";
}
}*/

// fix for singleton tags, since "/" at the end of the tag is not an attribute
if (attstore[attstore.length - 1][0] === "/") {
Expand Down Expand Up @@ -425,17 +487,17 @@
if ((/^\/(\/|\*)/).test(attstore[ind][0]) === true && options.language === "jsx") {
record.types = "comment_attribute";
record.token = attstore[ind][0];
recordPush(data, record, "");
convertQ();
} else if (eq > -1 && store.length > 0) {
// put certain attributes together for coldfusion
record.token = store.join(" ");
recordPush(data, record, "");
convertQ();
if (attstore[ind][0].indexOf("=") > 0 && attstore[ind][0].indexOf("//") < 0 && attstore[ind][0].charAt(0) !== ";") {
record.token = attstore[ind][0].replace(/\s$/, "");
} else {
record.token = attstore[ind][0];
}
recordPush(data, record, "");
convertQ();
store = [];
} else if (ltype === "sgml") {
store.push(attstore[ind][0]);
Expand All @@ -459,7 +521,7 @@
} else {
record.token = attstore[ind][0];
}
recordPush(data, record, "");
convertQ();
} else {
// separates out the attribute name from its value
slice = attstore[ind][0].slice(eq + 1);
Expand Down Expand Up @@ -491,7 +553,7 @@
record.stack = parse.structure[parse.structure.length - 1][0];
record.token = "}";
record.types = "jsx_attribute_end";
recordPush(data, record, "");
convertQ();
record.types = "attribute";
record.begin = begin;
record.stack = stack;
Expand All @@ -505,7 +567,7 @@
}
if (store.length > 0) {
record.token = store.join(" ");
recordPush(data, record, "");
convertQ();
}
};
ext = false;
Expand Down
4 changes: 3 additions & 1 deletion lexers/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,9 @@
build:string[] = [starting],
ender:string[] = ending.split("");
const endlen:number = ender.length,
qc:"none"|"double"|"single" = options.lexerOptions.script.quote_convert,
qc:"none"|"double"|"single" = (options.lexerOptions.script.quote_convert === undefined)
? "none"
: options.lexerOptions.script.quote_convert,
base:number = a + starting.length;
if (wordTest > -1) {
word();
Expand Down
4 changes: 3 additions & 1 deletion lexers/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ import { SSL_OP_NETSCAPE_CHALLENGE_BUG } from "constants";
outy:string = "",
mappy:number = 0;
const block:string[] = [],
qc:"none"|"double"|"single" = options.lexerOptions.style.quote_convert,
qc:"none"|"double"|"single" = (options.lexerOptions.style.quote_convert === undefined)
? "none"
: options.lexerOptions.style.quote_convert,
comma:boolean = (
parse.count > -1 && data.token[parse.count].charAt(data.token[parse.count].length - 1) === ","
),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
"start": "node js/services build --browser",
"test": "node js/services validation"
},
"version": "2.4.10"
"version": "2.4.11"
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Greenkeeper badge](https://badges.greenkeeper.io/Unibeautify/parse-framework.svg)](https://greenkeeper.io/)

## Version 2.4.10
## Version 2.4.11
Play around with this application [in your browser](http://prettydiff.com/parse-framework/runtimes/browsertest.xhtml).

### Todo
Expand Down
1 change: 1 addition & 0 deletions runtimes/browsertest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
}
} else if (name === "quote_convert" || name === "quoteconvert") {
if (values === "single" || values === "double") {
options.lexerOptions.markup.quote_convert = values;
options.lexerOptions.script.quote_convert = values;
options.lexerOptions.style.quote_convert = values;
}
Expand Down
2 changes: 1 addition & 1 deletion runtimes/browsertest.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="title">
<h1>
<span>parse-framework experimentation</span>
<span class="version">2.4.10</span>
<span class="version">2.4.11</span>
</h1>
<div>
<ul>
Expand Down
12 changes: 8 additions & 4 deletions runtimes/nodetest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,22 @@ const nodetest = function nodetest_() {
}
if ((/_quoteConvert-/).test(sourcepath) === true) {
if ((/_quoteConvert-double/).test(sourcepath) === true) {
options.lexerOptions.style.quote_convert = "double";
options.lexerOptions.markup.quote_convert = "double";
options.lexerOptions.script.quote_convert = "double";
options.lexerOptions.style.quote_convert = "double";
} else if ((/_quoteConvert-single/).test(sourcepath) === true) {
options.lexerOptions.style.quote_convert = "single";
options.lexerOptions.markup.quote_convert = "single";
options.lexerOptions.script.quote_convert = "single";
options.lexerOptions.style.quote_convert = "single";
} else {
options.lexerOptions.style.quote_convert = "none";
options.lexerOptions.markup.quote_convert = "none";
options.lexerOptions.script.quote_convert = "none";
options.lexerOptions.style.quote_convert = "none";
}
} else {
options.lexerOptions.style.quote_convert = "none";
options.lexerOptions.markup.quote_convert = "none";
options.lexerOptions.script.quote_convert = "none";
options.lexerOptions.style.quote_convert = "none";
}
if ((/_objectSort(\.|_|-)/).test(sourcepath) === true) {
if ((/_objectSort-/).test(sourcepath) === true) {
Expand Down
12 changes: 8 additions & 4 deletions services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,18 +572,22 @@ const services = function services_() {
}
if ((/_quoteConvert-/).test(files.code[a][0]) === true) {
if ((/_quoteConvert-double/).test(files.code[a][0]) === true) {
parse_options.lexerOptions.style.quote_convert = "double";
parse_options.lexerOptions.markup.quote_convert = "double";
parse_options.lexerOptions.script.quote_convert = "double";
parse_options.lexerOptions.style.quote_convert = "double";
} else if ((/_quoteConvert-single/).test(files.code[a][0]) === true) {
parse_options.lexerOptions.style.quote_convert = "single";
parse_options.lexerOptions.markup.quote_convert = "single";
parse_options.lexerOptions.script.quote_convert = "single";
parse_options.lexerOptions.style.quote_convert = "single";
} else {
parse_options.lexerOptions.style.quote_convert = "none";
parse_options.lexerOptions.markup.quote_convert = "none";
parse_options.lexerOptions.script.quote_convert = "none";
parse_options.lexerOptions.style.quote_convert = "none";
}
} else {
parse_options.lexerOptions.style.quote_convert = "none";
parse_options.lexerOptions.markup.quote_convert = "none";
parse_options.lexerOptions.script.quote_convert = "none";
parse_options.lexerOptions.style.quote_convert = "none";
}
if ((/_objectSort(\.|_|-)/).test(files.code[a][0]) === true) {
if ((/_objectSort-/).test(files.code[a][0]) === true) {
Expand Down
42 changes: 42 additions & 0 deletions test/samples_code/markup/html_quoteConvert-single.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.'0" encoding='UTF-"8' ?>
<!DOCTYPE html>
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Pretty Diff - The difference tool</title>
<link href="https://prettydiff.com" rel="canonical" type="application/xhtml+xml"/>
<link href="https://prettydiff.com/images/favicon.ico" rel="icon"
type="image/x-icon"/>
<link href="https://prettydiff.com/labels.rdf" rel="meta" title="ICRA labels"
type="application/rdf+xml"/>
<link href="humans.txt" rel="author" type="text/plain"/>
<link href="css/index.css?1545970643821" media="all" rel="stylesheet" type="text/css"/>
<link href="images/apple-touch-icon-57.png" rel="apple-touch-icon" sizes="57x57"/>
<link href="images/apple-touch-icon-72.png" rel="apple-touch-icon" sizes="72x72"/>
<link href="images/apple-touch-icon-114.png" rel="apple-touch-icon"
sizes="114x114"/>
<link href="images/apple-touch-icon-144.png" rel="apple-touch-icon"
sizes="144x144"/>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<meta content="index, follow" name="robots"/>
<meta content="Pretty Diff - The difference tool" name="DC.title"/>
<meta content="#fff" name="theme-color"/>
<meta
content="(pics-1.1 'http://www.icra.org/pics/vocabularyv03/' l gen true for 'https://prettydiff.com' r (n 0 s 0 v 0 l 0 oa 0 ob 0 oc 0 od 0 oe 0 of 0 og 0 oh 0 c 1) gen true for 'https://www.prettydiff.com' r (n 0 s 0 v 0 l 0 oa 0 ob 0 oc 0 od 0 oe 0 of 0 og 0 oh 0 c 1))"
http-equiv="pics-Label"/>
<meta content="Austin Cheney" name="author"/>
<meta
content="Pretty Diff tool can minify, beautify (pretty-print), or diff between minified and beautified code. This tool can even beautify and minify React JSX and many other languages."
name="description"/>
<meta content="Global" name="distribution"/>
<meta content="en" http-equiv="Content-Language"/>
<meta content="application/xhtml+xml;charset=UTF-8" http-equiv="Content-Type"/>
<meta content="blendTrans(Duration=0)" http-equiv="Page-Enter"/>
<meta content="blendTrans(Duration=0)" http-equiv="Page-Exit"/>
<meta content="text/css" http-equiv="content-style-type"/>
<meta content="application/javascript" http-equiv="content-script-type"/>
<meta content="qL8AV9yjL2-ZFGV9ey6wU3t7pTZdpD4lIetUSiNen7E"
name="google-site-verification"/>
<meta content="#bbbbff" name="msapplication-TileColor"/>
<meta content="images/pdlogo.svg" name="msapplication-TileImage"/>
</head>
</html>
Loading

0 comments on commit 14f7210

Please sign in to comment.