Skip to content

Commit 0769ce1

Browse files
authored
Merge pull request #165 from Jenesius/issue_162
update readme example.
2 parents fe8778d + ba58bcc commit 0769ce1

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

examples/simple-form/App.vue

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="container">
3-
<div>
4-
<pre class="container-values">{{ JSON.stringify(values, undefined, 4) }}</pre>
3+
<div class = "container-values">
4+
<pre style = "margin: 0"><code v-html = "prettyPrint.call(values)"></code></pre>
55
</div>
66

77
<div class="wrap-app">
@@ -59,6 +59,26 @@ const programLanguageOptions = {
5959
py: 'Python'
6060
}
6161
62+
63+
function prettyPrint(this: object){
64+
var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg;
65+
var replacer = function(match, pIndent, pKey, pVal, pEnd) {
66+
var key = '<span class="json-key" style="color: brown">',
67+
val = '<span class="json-value" style="color: navy">',
68+
str = '<span class="json-string" style="color: olive">',
69+
r = pIndent || '';
70+
if (pKey)
71+
r = r + key + pKey.replace(/[": ]/g, '') + '</span>: ';
72+
if (pVal)
73+
r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>';
74+
return r + (pEnd || '');
75+
};
76+
77+
return JSON.stringify(this, null, 3)
78+
.replace(/&/g, '&amp;').replace(/\\"/g, '&quot;')
79+
.replace(/</g, '&lt;').replace(/>/g, '&gt;')
80+
.replace(jsonLine, replacer);
81+
}
6282
</script>
6383

6484
<style>

readme-example.gif

106 KB
Loading

0 commit comments

Comments
 (0)