├── .github
└── FUNDING.yml
├── LICENSE
├── README.md
├── SECURITY.md
├── index.html
├── logo.png
├── resources
├── css
│ ├── common.css
│ ├── dark.css
│ └── tomorrow.highlight.css
├── images
│ └── toml-to-go.png
└── js
│ ├── common.js
│ ├── expanding.js
│ ├── gofmt.js
│ ├── highlight.min.js
│ ├── jquery.min.js
│ ├── json-to-go.js
│ ├── prefixfree.min.js
│ └── toml.js
└── sw.js
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | patreon: xuri
2 | ko_fi: xurime
3 | liberapay: xuri
4 | issuehunt: xuri
5 | custom: https://www.paypal.me/xuri
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 - 2022 Ri Xu All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # TOML-to-Go
4 |
5 | [](https://app.fossa.io/projects/git%2Bgithub.com%2Fxuri%2Ftoml-to-go?ref=badge_shield)
6 |
7 | Translates TOML into a Go type definition. [Check it out!](https://xuri.me/toml-to-go/)
8 |
9 | Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.
10 |
11 |
12 | ## Credits
13 |
14 | TOML-to-Go is base on JSON-to-go originally by ([Matt Holt](https://github.com/mholt/json-to-go)).
15 |
16 | The Go Gopher is originally by The Go Blog. This artwork is an adaptation.
17 |
18 | The TOML parser for node and the browser is originally by ([Michelle Tilley](https://github.com/BinaryMuse/toml-node)).
19 |
20 | ## License
21 |
22 | [](https://app.fossa.io/projects/git%2Bgithub.com%2Fxuri%2Ftoml-to-go?ref=badge_large)
23 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | ## Supported Versions
4 |
5 | We will dive into any security-related issue as long as your TOML-to-Go version is still supported by us. When reporting an issue, include as much information as possible, but no need to fill fancy forms or answer tedious questions. Just tell us what you found, how to reproduce it, and any concerns you have about it. We will respond as soon as possible and follow up with any missing information.
6 |
7 | ## Reporting a Vulnerability
8 |
9 | Please e-mail us directly at `xuri.me@gmail.com` or use the security issue template on GitHub. In general, public disclosure is made after the issue has been fully identified and a patch is ready to be released. A security issue gets the highest priority assigned and a reply regarding the vulnerability is given within a typical 24 hours. Thank you!
10 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | TOML-to-Go: Convert TOML to Go instantly
5 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
TOML-to-Go
55 |
Convert TOML to Go struct
56 |
57 | This tool instantly converts TOML into a Go type definition. Paste a TOML structure on the left and the equivalent Go type will be generated to the right, which you can paste into your program. The script has to make some assumptions, so double-check the output.
58 |
59 |
60 | For an example, try converting TOML from the SmartyStreets API .
61 |
62 |
63 | Dark mode
64 |
65 |
66 |
67 |
68 |
69 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
92 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuri/toml-to-go/6465e423593101aa0b840525849a0a7bfa7091d2/logo.png
--------------------------------------------------------------------------------
/resources/css/common.css:
--------------------------------------------------------------------------------
1 | /*
2 | Eric Meyer's Reset CSS v2.0
3 |
4 | NOTICE: This copy of the CSS reset has been modified
5 | to make main tag "display: block" because the default in
6 | even IE 11 is "display: inline", which is not correct.
7 | */
8 | html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{border:0;font-size:100%;font:inherit;vertical-align:baseline;margin:0;padding:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:none}table{border-collapse:collapse;border-spacing:0}
9 |
10 | body {
11 | font: 14px/1.25em 'Microsoft YaHei', '微软雅黑', Arial, Tahom, sans-serif;
12 | }
13 |
14 | code {
15 | font-family: 'Consolas', 'Menlo', 'Monaco', 'Courier New', monospace;
16 | padding: 0 3px;
17 | background-color: rgba(0, 0, 0, 0.04);
18 | border-radius: 3px
19 | }
20 |
21 | header {
22 | padding: 1.5%;
23 | }
24 |
25 | .intro {
26 | width: 50%;
27 | float: left;
28 | }
29 |
30 | h1 {
31 | font-size: 34px;
32 | font-weight: bold;
33 | line-height: 1.5em;
34 | }
35 |
36 | h2 {
37 | font-size: 24px;
38 | line-height: 1.3em;
39 | }
40 |
41 | p {
42 | margin-top: 20px;
43 | line-height: 1.5em;
44 | }
45 |
46 | a {
47 | color: #85AA43;
48 | }
49 |
50 | #brand {
51 | width: 40%;
52 | max-width: 400px;
53 | float: right;
54 | margin-left: 5%;
55 | }
56 |
57 | table {
58 | width: 100%;
59 | table-layout: fixed;
60 | }
61 |
62 | th {
63 | padding: 15px;
64 | background: #85AA43;
65 | text-align: center;
66 | color: #FFF;
67 | font-size: 20px;
68 | }
69 |
70 | th label {
71 | margin-left: 1em;
72 | font-size: 14px;
73 | cursor: pointer;
74 | }
75 |
76 | td {
77 | width: 50%;
78 | vertical-align: top;
79 | }
80 |
81 | #input,
82 | #output {
83 | -webkit-box-sizing: border-box;
84 | -moz-box-sizing: border-box;
85 | -o-box-sizing: border-box;
86 | box-sizing: border-box;
87 |
88 | white-space: pre;
89 | width: 100%;
90 | display: block;
91 | padding: 3%;
92 | font: 14px/1.5em 'Consolas', 'Menlo', 'Monaco', 'Courier New', monospace;
93 | outline: none;
94 | border: none;
95 | resize: vertical;
96 | height: 500px;
97 | height: 65vh;
98 | overflow: scroll;
99 | tab-size: 4;
100 | }
101 |
102 | #input {
103 | background: #E8F2C4;
104 | border-right: 2px solid #AAA;
105 | }
106 |
107 | #output {
108 | background: #F7FBE7;
109 | }
110 |
111 | footer {
112 | color: #888;
113 | text-align: center;
114 | padding: 75px 0 50px;
115 | line-height: 2em;
116 | }
117 |
118 | .clr-red {
119 | color: #CC0000;
120 | }
121 | .faulty-line {
122 | color: #C00;
123 | background: #FDD;
124 | font-weight: bold
125 | }
126 | .json-go-faulty-char {
127 | border: 1px solid purple;
128 | }
129 |
130 | .clear {
131 | clear: both;
132 | }
133 |
134 | .copy {
135 | font-size: 14px;
136 | padding: 5px;
137 | background: #80808099;
138 | border-radius: 5px;
139 | cursor: pointer;
140 | }
141 | .copy:hover {
142 | background: #808080cf;
143 | }
144 |
145 | @media (max-width: 1000px) {
146 | header {
147 | padding: 4%;
148 | }
149 |
150 | .intro,
151 | #brand {
152 | float: none;
153 | width: 100%;
154 | }
155 |
156 | #brand {
157 | margin: 40px auto;
158 | display: block;
159 | }
160 | }
--------------------------------------------------------------------------------
/resources/css/dark.css:
--------------------------------------------------------------------------------
1 | body {
2 | background: #222;
3 | color: #eee;
4 | }
5 |
6 | img#brand {
7 | filter: invert(0.867);
8 | }
9 |
10 | textarea#input {
11 | background: #222;
12 | color: #eee;
13 | border-right: 2px solid #E8F2C4;
14 | }
15 |
16 | div#output {
17 | background: #222;
18 | }
19 |
20 | a {
21 | text-decoration: none;
22 | color: #85AA43;
23 | }
--------------------------------------------------------------------------------
/resources/css/tomorrow.highlight.css:
--------------------------------------------------------------------------------
1 | /* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
2 |
3 | /* Tomorrow Comment */
4 | .hljs-comment {
5 | color: #8e908c;
6 | }
7 |
8 |
9 |
10 | /* Tomorrow Red */
11 | .hljs-variable,
12 | .hljs-attribute,
13 | .hljs-tag,
14 | .hljs-regexp,
15 | .ruby .hljs-constant,
16 | .xml .hljs-tag .hljs-title,
17 | .xml .hljs-pi,
18 | .xml .hljs-doctype,
19 | .html .hljs-doctype,
20 | .css .hljs-id,
21 | .css .hljs-class,
22 | .css .hljs-pseudo {
23 | color: #c82829;
24 | }
25 |
26 | /* Tomorrow Orange */
27 | .hljs-number,
28 | .hljs-preprocessor,
29 | .hljs-pragma,
30 | .hljs-built_in,
31 | .hljs-literal,
32 | .hljs-params,
33 | .hljs-constant {
34 | color: #f5871f;
35 | }
36 |
37 | /* Tomorrow Yellow */
38 | .ruby .hljs-class .hljs-title,
39 | .css .hljs-rules .hljs-attribute {
40 | color: #eab700;
41 | }
42 |
43 | /* Tomorrow Green */
44 | .hljs-string,
45 | .hljs-value,
46 | .hljs-inheritance,
47 | .hljs-header,
48 | .ruby .hljs-symbol,
49 | .xml .hljs-cdata {
50 | color: #718c00;
51 | }
52 |
53 | /* Tomorrow Aqua */
54 | .css .hljs-hexcolor {
55 | color: #3e999f;
56 | }
57 |
58 | /* Tomorrow Blue */
59 | .hljs-function,
60 | .python .hljs-decorator,
61 | .python .hljs-title,
62 | .ruby .hljs-function .hljs-title,
63 | .ruby .hljs-title .hljs-keyword,
64 | .perl .hljs-sub,
65 | .javascript .hljs-title,
66 | .coffeescript .hljs-title {
67 | color: #4271ae;
68 | }
69 |
70 | /* Tomorrow Purple */
71 | .hljs-keyword,
72 | .javascript .hljs-function {
73 | color: #8959a8;
74 | }
75 |
76 | .hljs {
77 | display: block;
78 | overflow-x: auto;
79 | /*background: white;
80 | padding: 0.5em;*/
81 | color: #4d4d4c;
82 | -webkit-text-size-adjust: none;
83 | }
84 |
85 | .coffeescript .javascript,
86 | .javascript .xml,
87 | .tex .hljs-formula,
88 | .xml .javascript,
89 | .xml .vbscript,
90 | .xml .css,
91 | .xml .hljs-cdata {
92 | opacity: 0.5;
93 | }
--------------------------------------------------------------------------------
/resources/images/toml-to-go.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuri/toml-to-go/6465e423593101aa0b840525849a0a7bfa7091d2/resources/images/toml-to-go.png
--------------------------------------------------------------------------------
/resources/js/common.js:
--------------------------------------------------------------------------------
1 | function setCookie(key, value) {
2 | var expires = new Date();
3 | expires.setTime(expires.getTime() + (90 * 24 * 60 * 60 * 1000));
4 | document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
5 | }
6 |
7 | function getCookie(key) {
8 | var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
9 | return keyValue ? keyValue[2] : null;
10 | }
11 |
12 | $(function () {
13 | const emptyInputMsg = "";
14 | const emptyOutputMsg = "Go will appear here";
15 | const formattedEmptyInputMsg = emptyInputMsg;
16 | const formattedEmptyOutputMsg = '' + emptyOutputMsg + ' ';
17 |
18 | function doConversion() {
19 | var input = $('#input').val();
20 | if (!input) {
21 | $('#output').html(formattedEmptyOutputMsg);
22 | return;
23 | }
24 | try {
25 | data = JSON.stringify(toml.parse(input), undefined, 2).trim();
26 | let output = jsonToGo(data, "", !$('#inline').is(':checked'), false);
27 |
28 | if (output.error) {
29 | $('#output').html('' + output.error + ' ');
30 | console.log("ERROR:", output, output.error);
31 | var parsedError = output.error.match(/Unexpected token .+ in JSON at position (\d+)/);
32 | if (parsedError) {
33 | try {
34 | var faultyIndex = parsedError.length == 2 && parsedError[1] && parseInt(parsedError[1]);
35 | faultyIndex && $('#output').html(constructJSONErrorHTML(output.error, faultyIndex, input));
36 | } catch (e) {}
37 | }
38 | } else {
39 | var finalOutput = output.go;
40 | if (typeof gofmt === 'function')
41 | finalOutput = gofmt(output.go);
42 | var coloredOutput = hljs.highlight("go", finalOutput);
43 | $('#output').html(coloredOutput.value);
44 | }
45 | } catch (exc) {
46 | if (exc.line && exc.column) {
47 | data = "Error at line " + exc.line + " column " + exc.column + ":\n" + exc.message
48 | $('#output').html('' + data + ' ');
49 | } else {
50 | data = exc.message;
51 | $('#output').html('' + data + ' ');
52 | }
53 | }
54 | }
55 |
56 | // Hides placeholder text
57 | $('#input').on('focus', function () {
58 | var val = $(this).val();
59 | if (!val) {
60 | $(this).html(formattedEmptyInputMsg);
61 | $('#output').html(formattedEmptyOutputMsg);
62 | } else if (val == emptyInputMsg)
63 | $(this).html("");
64 | });
65 |
66 | // Shows placeholder text
67 | $('#input').on('blur', function () {
68 | var val = $(this).val();
69 | if (!val) {
70 | $(this).html(formattedEmptyInputMsg);
71 | $('#output').html(formattedEmptyOutputMsg);
72 | }
73 | }).blur();
74 |
75 | // If tab is pressed, insert a tab instead of focusing on next element
76 | $('#input').keydown(function (e) {
77 | if (e.keyCode == 9) {
78 | document.execCommand('insertHTML', false, ' '); // insert tab
79 | e.preventDefault(); // don't go to next element
80 | }
81 | });
82 |
83 | // Automatically do the conversion on paste or change
84 | $('#input').keyup(function () {
85 | doConversion();
86 | });
87 |
88 | // Also do conversion when inlining preference changes
89 | $('#inline').change(function () {
90 | doConversion();
91 | })
92 |
93 | // Highlights the output for the user
94 | $('#output').click(function () {
95 | if (document.selection) {
96 | var range = document.body.createTextRange();
97 | range.moveToElementText(this);
98 | range.select();
99 | } else if (window.getSelection) {
100 | var range = document.createRange();
101 | range.selectNode(this);
102 | var sel = window.getSelection();
103 | sel.removeAllRanges(); // required as of Chrome 60: https://www.chromestatus.com/features/6680566019653632
104 | sel.addRange(range);
105 | }
106 | });
107 |
108 | // Fill in sample JSON if the user wants to see an example
109 | $('#sample1').click(function () {
110 | $('#input').val(sampleTOML).keyup();
111 | });
112 |
113 | var dark = false;
114 | var dark_mode = getCookie("dark_mode");
115 | if (dark_mode != null) {
116 | dark = (dark_mode === 'true');
117 | if (dark) {
118 | $("head").append(" ");
119 | $("#dark").html("Light mode");
120 | } else {
121 | $("#dark-css").remove();
122 | $("#dark").html("Dark mode");
123 | }
124 | }
125 | $("#dark").click(function () {
126 | if (!dark) {
127 | $("head").append(" ");
128 | $("#dark").html("Light mode");
129 | setCookie("dark_mode", true);
130 | } else {
131 | $("#dark-css").remove();
132 | $("#dark").html("Dark mode");
133 | setCookie("dark_mode", false);
134 | }
135 | dark = !dark;
136 | });
137 |
138 | // Copy contents of the output to clipboard
139 | $("#copy-btn").click(function() {
140 | var elm = document.getElementById("output");
141 |
142 | if(document.body.createTextRange) {
143 | // for ie
144 | var range = document.body.createTextRange();
145 |
146 | range.moveToElementText(elm);
147 | range.select();
148 |
149 | document.execCommand("Copy");
150 | } else if(window.getSelection) {
151 | // other browsers
152 | var selection = window.getSelection();
153 | var range = document.createRange();
154 |
155 | range.selectNodeContents(elm);
156 | selection.removeAllRanges();
157 | selection.addRange(range);
158 |
159 | document.execCommand("Copy");
160 | }
161 | })
162 | });
163 |
164 | function constructJSONErrorHTML(rawErrorMessage, errorIndex, json) {
165 | var errorHeading = '' + rawErrorMessage + '
';
166 | var markedPart = '' + json[errorIndex] + ' ';
167 | var markedJsonString = [json.slice(0, errorIndex), markedPart, json.slice(errorIndex + 1)].join('');
168 | var jsonStringLines = markedJsonString.split(/\n/);
169 | for (var i = 0; i < jsonStringLines.length; i++) {
170 |
171 | if (jsonStringLines[i].indexOf('') > -1) // faulty line
172 | var wrappedLine = '' + jsonStringLines[i] + '
';
173 | else
174 | var wrappedLine = '' + jsonStringLines[i] + '
';
175 |
176 | jsonStringLines[i] = wrappedLine;
177 | }
178 | return (errorHeading + jsonStringLines.join(''));
179 | }
180 |
181 | // Stringifies JSON in the preferred manner
182 | function stringify(json) {
183 | return JSON.stringify(json, null, "\t");
184 | }
185 |
186 | var sampleTOML = `# This is a TOML document. Boom.
187 |
188 | title = "TOML Example"
189 |
190 | [owner]
191 | name = "Tom Preston-Werner"
192 | organization = "GitHub"
193 | bio = "GitHub Cofounder & CEO\nLikes tater tots and beer."
194 | dob = 1979-05-27T07:32:00Z # First class dates? Why not?
195 |
196 | [database]
197 | server = "192.168.1.1"
198 | ports = [ 8001, 8001, 8002 ]
199 | connection_max = 5000
200 | enabled = true
201 |
202 | [servers]
203 |
204 | # You can indent as you please. Tabs or spaces. TOML don't care.
205 | [servers.alpha]
206 | ip = "10.0.0.1"
207 | dc = "eqdc10"
208 |
209 | [servers.beta]
210 | ip = "10.0.0.2"
211 | dc = "eqdc10"
212 |
213 | [clients]
214 |
215 | # Line breaks are OK when inside arrays
216 | hosts = [
217 | "alpha",
218 | "omega"
219 | ]`
220 |
--------------------------------------------------------------------------------
/resources/js/expanding.js:
--------------------------------------------------------------------------------
1 | // Expanding Textareas
2 | // https://github.com/bgrins/ExpandingTextareas
3 |
4 | (function(factory) {
5 | // Add jQuery via AMD registration or browser globals
6 | if (typeof define === 'function' && define.amd) {
7 | define([ 'jquery' ], factory);
8 | }
9 | else {
10 | factory(jQuery);
11 | }
12 | }(function ($) {
13 | $.expandingTextarea = $.extend({
14 | autoInitialize: true,
15 | initialSelector: "textarea.expanding",
16 | opts: {
17 | resize: function() { }
18 | }
19 | }, $.expandingTextarea || {});
20 |
21 | var cloneCSSProperties = [
22 | 'lineHeight', 'textDecoration', 'letterSpacing',
23 | 'fontSize', 'fontFamily', 'fontStyle',
24 | 'fontWeight', 'textTransform', 'textAlign',
25 | 'direction', 'wordSpacing', 'fontSizeAdjust',
26 | 'wordWrap', 'word-break',
27 | 'borderLeftWidth', 'borderRightWidth',
28 | 'borderTopWidth','borderBottomWidth',
29 | 'paddingLeft', 'paddingRight',
30 | 'paddingTop','paddingBottom',
31 | 'marginLeft', 'marginRight',
32 | 'marginTop','marginBottom',
33 | 'boxSizing', 'webkitBoxSizing', 'mozBoxSizing', 'msBoxSizing'
34 | ];
35 |
36 | var textareaCSS = {
37 | position: "absolute",
38 | height: "100%",
39 | resize: "none"
40 | };
41 |
42 | var preCSS = {
43 | visibility: "hidden",
44 | border: "0 solid",
45 | whiteSpace: "pre-wrap"
46 | };
47 |
48 | var containerCSS = {
49 | position: "relative"
50 | };
51 |
52 | function resize() {
53 | $(this).closest('.expandingText').find("div").text(this.value.replace(/\r\n/g, "\n") + ' ');
54 | $(this).trigger("resize.expanding");
55 | }
56 |
57 | $.fn.expandingTextarea = function(o) {
58 |
59 | var opts = $.extend({ }, $.expandingTextarea.opts, o);
60 |
61 | if (o === "resize") {
62 | return this.trigger("input.expanding");
63 | }
64 |
65 | if (o === "destroy") {
66 | this.filter(".expanding-init").each(function() {
67 | var textarea = $(this).removeClass('expanding-init');
68 | var container = textarea.closest('.expandingText');
69 |
70 | container.before(textarea).remove();
71 | textarea
72 | .attr('style', textarea.data('expanding-styles') || '')
73 | .removeData('expanding-styles');
74 | });
75 |
76 | return this;
77 | }
78 |
79 | this.filter("textarea").not(".expanding-init").addClass("expanding-init").each(function() {
80 | var textarea = $(this);
81 |
82 | textarea.wrap("
");
83 | textarea.after("
");
84 |
85 | var container = textarea.parent().css(containerCSS);
86 | var pre = container.find("pre").css(preCSS);
87 |
88 | // Store the original styles in case of destroying.
89 | textarea.data('expanding-styles', textarea.attr('style'));
90 | textarea.css(textareaCSS);
91 |
92 | $.each(cloneCSSProperties, function(i, p) {
93 | var val = textarea.css(p);
94 |
95 | // Only set if different to prevent overriding percentage css values.
96 | if (pre.css(p) !== val) {
97 | pre.css(p, val);
98 | }
99 | });
100 |
101 | textarea.bind("input.expanding propertychange.expanding keyup.expanding", resize);
102 | resize.apply(this);
103 |
104 | if (opts.resize) {
105 | textarea.bind("resize.expanding", opts.resize);
106 | }
107 | });
108 |
109 | return this;
110 | };
111 |
112 | $(function () {
113 | if ($.expandingTextarea.autoInitialize) {
114 | $($.expandingTextarea.initialSelector).expandingTextarea();
115 | }
116 | });
117 |
118 | }));
119 |
--------------------------------------------------------------------------------
/resources/js/highlight.min.js:
--------------------------------------------------------------------------------
1 | var hljs=new function(){function j(v){return v.replace(/&/gm,"&").replace(//gm,">")}function t(v){return v.nodeName.toLowerCase()}function h(w,x){var v=w&&w.exec(x);return v&&v.index==0}function r(w){var v=(w.className+" "+(w.parentNode?w.parentNode.className:"")).split(/\s+/);v=v.map(function(x){return x.replace(/^lang(uage)?-/,"")});return v.filter(function(x){return i(x)||/no(-?)highlight/.test(x)})[0]}function o(x,y){var v={};for(var w in x){v[w]=x[w]}if(y){for(var w in y){v[w]=y[w]}}return v}function u(x){var v=[];(function w(y,z){for(var A=y.firstChild;A;A=A.nextSibling){if(A.nodeType==3){z+=A.nodeValue.length}else{if(A.nodeType==1){v.push({event:"start",offset:z,node:A});z=w(A,z);if(!t(A).match(/br|hr|img|input/)){v.push({event:"stop",offset:z,node:A})}}}}return z})(x,0);return v}function q(w,y,C){var x=0;var F="";var z=[];function B(){if(!w.length||!y.length){return w.length?w:y}if(w[0].offset!=y[0].offset){return(w[0].offset"}function E(G){F+=""+t(G)+">"}function v(G){(G.event=="start"?A:E)(G.node)}while(w.length||y.length){var D=B();F+=j(C.substr(x,D[0].offset-x));x=D[0].offset;if(D==w){z.reverse().forEach(E);do{v(D.splice(0,1)[0]);D=B()}while(D==w&&D.length&&D[0].offset==x);z.reverse().forEach(A)}else{if(D[0].event=="start"){z.push(D[0].node)}else{z.pop()}v(D.splice(0,1)[0])}}return F+j(C.substr(x))}function m(y){function v(z){return(z&&z.source)||z}function w(A,z){return RegExp(v(A),"m"+(y.cI?"i":"")+(z?"g":""))}function x(D,C){if(D.compiled){return}D.compiled=true;D.k=D.k||D.bK;if(D.k){var z={};var E=function(G,F){if(y.cI){F=F.toLowerCase()}F.split(" ").forEach(function(H){var I=H.split("|");z[I[0]]=[G,I[1]?Number(I[1]):1]})};if(typeof D.k=="string"){E("keyword",D.k)}else{Object.keys(D.k).forEach(function(F){E(F,D.k[F])})}D.k=z}D.lR=w(D.l||/\b[A-Za-z0-9_]+\b/,true);if(C){if(D.bK){D.b="\\b("+D.bK.split(" ").join("|")+")\\b"}if(!D.b){D.b=/\B|\b/}D.bR=w(D.b);if(!D.e&&!D.eW){D.e=/\B|\b/}if(D.e){D.eR=w(D.e)}D.tE=v(D.e)||"";if(D.eW&&C.tE){D.tE+=(D.e?"|":"")+C.tE}}if(D.i){D.iR=w(D.i)}if(D.r===undefined){D.r=1}if(!D.c){D.c=[]}var B=[];D.c.forEach(function(F){if(F.v){F.v.forEach(function(G){B.push(o(F,G))})}else{B.push(F=="self"?D:F)}});D.c=B;D.c.forEach(function(F){x(F,D)});if(D.starts){x(D.starts,C)}var A=D.c.map(function(F){return F.bK?"\\.?("+F.b+")\\.?":F.b}).concat([D.tE,D.i]).map(v).filter(Boolean);D.t=A.length?w(A.join("|"),true):{exec:function(F){return null}}}x(y)}function c(T,L,J,R){function v(V,W){for(var U=0;U";V+=aa+'">';return V+Y+Z}function N(){if(!I.k){return j(C)}var U="";var X=0;I.lR.lastIndex=0;var V=I.lR.exec(C);while(V){U+=j(C.substr(X,V.index-X));var W=E(I,V);if(W){H+=W[1];U+=w(W[0],j(V[0]))}else{U+=j(V[0])}X=I.lR.lastIndex;V=I.lR.exec(C)}return U+j(C.substr(X))}function F(){if(I.sL&&!f[I.sL]){return j(C)}var U=I.sL?c(I.sL,C,true,S):e(C);if(I.r>0){H+=U.r}if(I.subLanguageMode=="continuous"){S=U.top}return w(U.language,U.value,false,true)}function Q(){return I.sL!==undefined?F():N()}function P(W,V){var U=W.cN?w(W.cN,"",true):"";if(W.rB){D+=U;C=""}else{if(W.eB){D+=j(V)+U;C=""}else{D+=U;C=V}}I=Object.create(W,{parent:{value:I}})}function G(U,Y){C+=U;if(Y===undefined){D+=Q();return 0}var W=v(Y,I);if(W){D+=Q();P(W,Y);return W.rB?0:Y.length}var X=z(I,Y);if(X){var V=I;if(!(V.rE||V.eE)){C+=Y}D+=Q();do{if(I.cN){D+=" "}H+=I.r;I=I.parent}while(I!=X.parent);if(V.eE){D+=j(Y)}C="";if(X.starts){P(X.starts,"")}return V.rE?0:Y.length}if(A(Y,I)){throw new Error('Illegal lexeme "'+Y+'" for mode "'+(I.cN||"")+'"')}C+=Y;return Y.length||1}var M=i(T);if(!M){throw new Error('Unknown language: "'+T+'"')}m(M);var I=R||M;var S;var D="";for(var K=I;K!=M;K=K.parent){if(K.cN){D=w(K.cN,"",true)+D}}var C="";var H=0;try{var B,y,x=0;while(true){I.t.lastIndex=x;B=I.t.exec(L);if(!B){break}y=G(L.substr(x,B.index-x),B[0]);x=B.index+y}G(L.substr(x));for(var K=I;K.parent;K=K.parent){if(K.cN){D+=""}}return{r:H,value:D,language:T,top:I}}catch(O){if(O.message.indexOf("Illegal")!=-1){return{r:0,value:j(L)}}else{throw O}}}function e(y,x){x=x||b.languages||Object.keys(f);var v={r:0,value:j(y)};var w=v;x.forEach(function(z){if(!i(z)){return}var A=c(z,y,false);A.language=z;if(A.r>w.r){w=A}if(A.r>v.r){w=v;v=A}});if(w.language){v.second_best=w}return v}function g(v){if(b.tabReplace){v=v.replace(/^((<[^>]+>|\t)+)/gm,function(w,z,y,x){return z.replace(/\t/g,b.tabReplace)})}if(b.useBR){v=v.replace(/\n/g," ")}return v}function p(A){var B=r(A);if(/no(-?)highlight/.test(B)){return}var y;if(b.useBR){y=document.createElementNS("http://www.w3.org/1999/xhtml","div");y.innerHTML=A.innerHTML.replace(/\n/g,"").replace(/ /g,"\n")}else{y=A}var z=y.textContent;var v=B?c(B,z,true):e(z);var x=u(y);if(x.length){var w=document.createElementNS("http://www.w3.org/1999/xhtml","div");w.innerHTML=v.value;v.value=q(x,u(w),z)}v.value=g(v.value);A.innerHTML=v.value;A.className+=" hljs "+(!B&&v.language||"");A.result={language:v.language,re:v.r};if(v.second_best){A.second_best={language:v.second_best.language,re:v.second_best.r}}}var b={classPrefix:"hljs-",tabReplace:null,useBR:false,languages:undefined};function s(v){b=o(b,v)}function l(){if(l.called){return}l.called=true;var v=document.querySelectorAll("pre code");Array.prototype.forEach.call(v,p)}function a(){addEventListener("DOMContentLoaded",l,false);addEventListener("load",l,false)}var f={};var n={};function d(v,x){var w=f[v]=x(this);if(w.aliases){w.aliases.forEach(function(y){n[y]=v})}}function k(){return Object.keys(f)}function i(v){return f[v]||f[n[v]]}this.highlight=c;this.highlightAuto=e;this.fixMarkup=g;this.highlightBlock=p;this.configure=s;this.initHighlighting=l;this.initHighlightingOnLoad=a;this.registerLanguage=d;this.listLanguages=k;this.getLanguage=i;this.inherit=o;this.IR="[a-zA-Z][a-zA-Z0-9_]*";this.UIR="[a-zA-Z_][a-zA-Z0-9_]*";this.NR="\\b\\d+(\\.\\d+)?";this.CNR="(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)";this.BNR="\\b(0b[01]+)";this.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";this.BE={b:"\\\\[\\s\\S]",r:0};this.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[this.BE]};this.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[this.BE]};this.PWM={b:/\b(a|an|the|are|I|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such)\b/};this.CLCM={cN:"comment",b:"//",e:"$",c:[this.PWM]};this.CBCM={cN:"comment",b:"/\\*",e:"\\*/",c:[this.PWM]};this.HCM={cN:"comment",b:"#",e:"$",c:[this.PWM]};this.NM={cN:"number",b:this.NR,r:0};this.CNM={cN:"number",b:this.CNR,r:0};this.BNM={cN:"number",b:this.BNR,r:0};this.CSSNM={cN:"number",b:this.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0};this.RM={cN:"regexp",b:/\//,e:/\/[gim]*/,i:/\n/,c:[this.BE,{b:/\[/,e:/\]/,r:0,c:[this.BE]}]};this.TM={cN:"title",b:this.IR,r:0};this.UTM={cN:"title",b:this.UIR,r:0}}();hljs.registerLanguage("bash",function(b){var a={cN:"variable",v:[{b:/\$[\w\d#@][\w\d_]*/},{b:/\$\{(.*?)\}/}]};var d={cN:"string",b:/"/,e:/"/,c:[b.BE,a,{cN:"variable",b:/\$\(/,e:/\)/,c:[b.BE]}]};var c={cN:"string",b:/'/,e:/'/};return{aliases:["sh","zsh"],l:/-?[a-z\.]+/,k:{keyword:"if then else elif fi for break continue while in do done exit return set declare case esac export exec",literal:"true false",built_in:"printf echo read cd pwd pushd popd dirs let eval unset typeset readonly getopts source shopt caller type hash bind help sudo",operator:"-ne -eq -lt -gt -f -d -e -s -l -a"},c:[{cN:"shebang",b:/^#![^\n]+sh\s*$/,r:10},{cN:"function",b:/\w[\w\d_]*\s*\(\s*\)\s*\{/,rB:true,c:[b.inherit(b.TM,{b:/\w[\w\d_]*/})],r:0},b.HCM,b.NM,d,c,a]}});hljs.registerLanguage("cs",function(c){var b="abstract as base bool break byte case catch char checked const continue decimal default delegate do double else enum event explicit extern false finally fixed float for foreach goto if implicit in int interface internal is lock long new null object operator out override params private protected public readonly ref return sbyte sealed short sizeof stackalloc static string struct switch this throw true try typeof uint ulong unchecked unsafe ushort using virtual volatile void while async await protected public private internal ascending descending from get group into join let orderby partial select set value var where yield";var a=c.IR+"(<"+c.IR+">)?";return{aliases:["csharp"],k:b,i:/::/,c:[{cN:"comment",b:"///",e:"$",rB:true,c:[{cN:"xmlDocTag",v:[{b:"///",r:0},{b:""},{b:"?",e:">"}]}]},c.CLCM,c.CBCM,{cN:"preprocessor",b:"#",e:"$",k:"if else elif endif define undef warning error line region endregion pragma checksum"},{cN:"string",b:'@"',e:'"',c:[{b:'""'}]},c.ASM,c.QSM,c.CNM,{bK:"class namespace interface",e:/[{;=]/,i:/[^\s:]/,c:[c.TM,c.CLCM,c.CBCM]},{bK:"new",e:/\s/,r:0},{cN:"function",b:"("+a+"\\s+)+"+c.IR+"\\s*\\(",rB:true,e:/[{;=]/,eE:true,k:b,c:[{b:c.IR+"\\s*\\(",rB:true,c:[c.TM]},{cN:"params",b:/\(/,e:/\)/,k:b,c:[c.ASM,c.QSM,c.CNM,c.CBCM]},c.CLCM,c.CBCM]}]}});hljs.registerLanguage("ruby",function(f){var j="[a-zA-Z_]\\w*[!?=]?|[-+~]\\@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?";var i="and false then defined module in return redo if BEGIN retry end for true self when next until do begin unless END rescue nil else break undef not super class case require yield alias while ensure elsif or include attr_reader attr_writer attr_accessor";var b={cN:"yardoctag",b:"@[A-Za-z]+"};var c={cN:"value",b:"#<",e:">"};var k={cN:"comment",v:[{b:"#",e:"$",c:[b]},{b:"^\\=begin",e:"^\\=end",c:[b],r:10},{b:"^__END__",e:"\\n$"}]};var d={cN:"subst",b:"#\\{",e:"}",k:i};var e={cN:"string",c:[f.BE,d],v:[{b:/'/,e:/'/},{b:/"/,e:/"/},{b:"%[qw]?\\(",e:"\\)"},{b:"%[qw]?\\[",e:"\\]"},{b:"%[qw]?{",e:"}"},{b:"%[qw]?<",e:">"},{b:"%[qw]?/",e:"/"},{b:"%[qw]?%",e:"%"},{b:"%[qw]?-",e:"-"},{b:"%[qw]?\\|",e:"\\|"},{b:/\B\?(\\\d{1,3}|\\x[A-Fa-f0-9]{1,2}|\\u[A-Fa-f0-9]{4}|\\?\S)\b/}]};var a={cN:"params",b:"\\(",e:"\\)",k:i};var h=[e,c,k,{cN:"class",bK:"class module",e:"$|;",i:/=/,c:[f.inherit(f.TM,{b:"[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?"}),{cN:"inheritance",b:"<\\s*",c:[{cN:"parent",b:"("+f.IR+"::)?"+f.IR}]},k]},{cN:"function",bK:"def",e:" |$|;",r:0,c:[f.inherit(f.TM,{b:j}),a,k]},{cN:"constant",b:"(::)?(\\b[A-Z]\\w*(::)?)+",r:0},{cN:"symbol",b:f.UIR+"(\\!|\\?)?:",r:0},{cN:"symbol",b:":",c:[e,{b:j}],r:0},{cN:"number",b:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",r:0},{cN:"variable",b:"(\\$\\W)|((\\$|\\@\\@?)(\\w+))"},{b:"("+f.RSR+")\\s*",c:[c,k,{cN:"regexp",c:[f.BE,d],i:/\n/,v:[{b:"/",e:"/[a-z]*"},{b:"%r{",e:"}[a-z]*"},{b:"%r\\(",e:"\\)[a-z]*"},{b:"%r!",e:"![a-z]*"},{b:"%r\\[",e:"\\][a-z]*"}]}],r:0}];d.c=h;a.c=h;var g=[{b:/^\s*=>/,cN:"status",starts:{e:"$",c:h}},{cN:"prompt",b:/^\S[^=>\n]*>+/,starts:{e:"$",c:h}}];return{aliases:["rb","gemspec","podspec","thor","irb"],k:i,c:[k].concat(g).concat(h)}});hljs.registerLanguage("javascript",function(a){return{aliases:["js"],k:{keyword:"in if for while finally var new function do return void else break catch instanceof with throw case default try this switch continue typeof delete let yield const class",literal:"true false null undefined NaN Infinity",built_in:"eval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError Number Math Date String RegExp Array Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray ArrayBuffer DataView JSON Intl arguments require module console window document"},c:[{cN:"pi",b:/^\s*('|")use strict('|")/,r:10},a.ASM,a.QSM,a.CLCM,a.CBCM,a.CNM,{b:"("+a.RSR+"|\\b(case|return|throw)\\b)\\s*",k:"return throw case",c:[a.CLCM,a.CBCM,a.RM,{b:/,e:/>;/,r:0,sL:"xml"}],r:0},{cN:"function",bK:"function",e:/\{/,eE:true,c:[a.inherit(a.TM,{b:/[A-Za-z$_][0-9A-Za-z$_]*/}),{cN:"params",b:/\(/,e:/\)/,c:[a.CLCM,a.CBCM],i:/["'\(]/}],i:/\[|%/},{b:/\$[(.]/},{b:"\\."+a.IR,r:0}]}});hljs.registerLanguage("xml",function(a){var c="[A-Za-z0-9\\._:-]+";var d={b:/<\?(php)?(?!\w)/,e:/\?>/,sL:"php",subLanguageMode:"continuous"};var b={eW:true,i:/,r:0,c:[d,{cN:"attribute",b:c,r:0},{b:"=",r:0,c:[{cN:"value",v:[{b:/"/,e:/"/},{b:/'/,e:/'/},{b:/[^\s\/>]+/}]}]}]};return{aliases:["html","xhtml","rss","atom","xsl","plist"],cI:true,c:[{cN:"doctype",b:"",r:10,c:[{b:"\\[",e:"\\]"}]},{cN:"comment",b:"",r:10},{cN:"cdata",b:"<\\!\\[CDATA\\[",e:"\\]\\]>",r:10},{cN:"tag",b:"",rE:true,sL:"css"}},{cN:"tag",b:"