Browse Source

Added debug view to demo

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
a75604569c
  1. 1
      CHANGELOG.md
  2. 35
      demo/assets/index.css
  3. 48
      demo/assets/index.js
  4. 27
      demo/assets/index.styl
  5. 15
      demo/index.html
  6. 8
      demo/index.jade

1
CHANGELOG.md

@ -3,6 +3,7 @@
- Fixed speed degradation when linkifier enabled. - Fixed speed degradation when linkifier enabled.
- Added coverage reports. - Added coverage reports.
- Added debug view to demo (show internal representation)
- Other minor optimizations and cleanup. - Other minor optimizations and cleanup.

35
demo/assets/index.css

@ -23,32 +23,51 @@ body {
font-size: 13px; font-size: 13px;
padding: 2px; padding: 2px;
} }
.result { .result-html {
padding: 2px 10px; padding: 2px 10px;
overflow: auto; overflow: auto;
background-color: #fff; background-color: #fff;
border: 1px solid #ccc;
border-radius: 4px;
} }
.result img { .result-html img {
max-width: 50%; max-width: 50%;
} }
.result-src { .result-src,
.result-debug {
display: none; display: none;
background-color: #fff; background-color: #fff;
} }
.result-src-content { .result-src-content,
.result-debug-content {
white-space: pre; white-space: pre;
} }
.result-as-text .result-src { .result-as-html .result-html {
display: block;
}
.result-as-html .result-src,
.result-as-html .result-debug {
display: none;
}
.result-as-src .result-src {
display: block;
}
.result-as-src .result-html,
.result-as-src .result-debug {
display: none;
}
.result-as-debug .result-debug {
display: block; display: block;
} }
.result-as-text .result { .result-as-debug .result-html,
.result-as-debug .result-src {
display: none; display: none;
} }
.demo-control { .demo-control {
position: absolute; position: absolute;
right: 15px; right: 40px;
top: 0; top: 0;
border-radius: 0 4px; border-radius: 0 0 6px 6px;
font-size: 12px; font-size: 12px;
background-color: #666; background-color: #666;
color: #fff !important; color: #fff !important;

48
demo/assets/index.js

@ -14,7 +14,7 @@
// options below are for demo only // options below are for demo only
_highlight: true, _highlight: true,
_strict: false, _strict: false,
_src: false _view: 'html' // html / src / debug
}; };
defaults.highlight = function (str, lang) { defaults.highlight = function (str, lang) {
@ -42,6 +42,14 @@
} }
} }
function setResultView(val) {
$('body').removeClass('result-as-html');
$('body').removeClass('result-as-src');
$('body').removeClass('result-as-debug');
$('body').addClass('result-as-' + val);
defaults._view = val;
}
function mdInit() { function mdInit() {
if (defaults._strict) { if (defaults._strict) {
mdHtml = new window.Remarkable('commonmark'); mdHtml = new window.Remarkable('commonmark');
@ -59,8 +67,13 @@
function updateResult() { function updateResult() {
var source = $('.source').val(); var source = $('.source').val();
$('.result').html(mdHtml.render(source));
$('.result-html').html(mdHtml.render(source));
$('.result-src-content').html(window.hljs.highlight('html', mdSrc.render(source)).value); $('.result-src-content').html(window.hljs.highlight('html', mdSrc.render(source)).value);
var dump = JSON.stringify(mdSrc.parse(source, { references: {} }), null, 2);
$('.result-debug-content').html(window.hljs.highlight('json', dump).value);
try { try {
if (source) { if (source) {
// serialize state - source and options // serialize state - source and options
@ -107,11 +120,22 @@
_.forOwn(opts, function (val, key) { _.forOwn(opts, function (val, key) {
if (!defaults.hasOwnProperty(key)) { return; } if (!defaults.hasOwnProperty(key)) { return; }
// Legacy, for old links
if (key === '_src') {
defaults._view = val ? 'src' : 'html';
return;
}
if ((_.isBoolean(defaults[key]) && _.isBoolean(val)) || if ((_.isBoolean(defaults[key]) && _.isBoolean(val)) ||
(_.isString(defaults[key]) && _.isString(val))) { (_.isString(defaults[key]) && _.isString(val))) {
defaults[key] = val; defaults[key] = val;
} }
}); });
// sanitize for sure
if ([ 'html', 'src', 'debug' ].indexOf(defaults._view) === -1) {
defaults._view = 'html';
}
} catch (__) {} } catch (__) {}
} }
@ -149,11 +173,7 @@
} }
}); });
// Set display mode for result setResultView(defaults._view);
if (defaults._src) {
$('body').addClass('result-as-text');
}
mdInit(); mdInit();
permalink = document.getElementById('permalink'); permalink = document.getElementById('permalink');
@ -167,12 +187,14 @@
event.preventDefault(); event.preventDefault();
}); });
$('.result-mode').on('click', function (event) { $(document).on('click', '[data-result-as]', function (event) {
defaults._src = !defaults._src; var view = $(this).data('resultAs');
$('body').toggleClass('result-as-text'); if (view) {
// only to update permalink setResultView(view);
updateResult(); // only to update permalink
event.preventDefault(); updateResult();
event.preventDefault();
}
}); });
updateResult(); updateResult();

27
demo/assets/index.styl

@ -22,32 +22,49 @@ body
font-size 13px font-size 13px
padding 2px padding 2px
.result .result-html
padding 2px 10px padding 2px 10px
overflow auto overflow auto
background-color #fff background-color #fff
border 1px solid #ccc
border-radius 4px
img img
max-width 50% max-width 50%
.result-src .result-src
.result-debug
display none display none
background-color #fff background-color #fff
.result-src-content .result-src-content
.result-debug-content
white-space pre white-space pre
.result-as-text .result-as-html
.result-html
display block
.result-src
.result-debug
display none
.result-as-src
.result-src .result-src
display block display block
.result .result-html
.result-debug
display none
.result-as-debug
.result-debug
display block
.result-html
.result-src
display none display none
.demo-control .demo-control
position absolute position absolute
right 15px right 40px
top 0 top 0
//padding 0 10px //padding 0 10px
border-radius 0 4px border-radius 0 0 6px 6px
font-size 12px font-size 12px
background-color #666 background-color #666
color #fff !important color #fff !important

15
demo/index.html

@ -18,12 +18,12 @@
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-26895916-3', 'auto'); ga('create', 'UA-26895916-3', 'auto');
ga('require', 'displayfeatures'); ga('require', 'displayfeatures');
ga('require', 'linkid', 'linkid.js'); ga('require', 'linkid', 'linkid.js');
ga('send', 'pageview'); ga('send', 'pageview');
</script> </script>
</head> </head>
<body> <body>
@ -109,7 +109,7 @@ console.log(md.render('# Remarkable rulezz!'));
<textarea class="source full-height">--- <textarea class="source full-height">---
__Advertisement :)__ __Advertisement :)__
- __[pica](http://nodeca.github.io/pica/demo/)__ - high quality and fast image - __[pica](https://nodeca.github.io/pica/demo/)__ - high quality and fast image
resize in browser. resize in browser.
- __[babelfish](https://github.com/nodeca/babelfish/)__ - developpers friendly - __[babelfish](https://github.com/nodeca/babelfish/)__ - developpers friendly
i18n with plurals support and easy syntax. i18n with plurals support and easy syntax.
@ -254,7 +254,7 @@ Right aligned columns
[link text](http://dev.nodeca.com) [link text](http://dev.nodeca.com)
[link with title](https://nodeca.github.io/pica/demo/ &quot;title text!&quot;) [link with title](http://nodeca.github.io/pica/demo/ &quot;title text!&quot;)
Autoconverted link https://github.com/nodeca/pica (enable linkify to see) Autoconverted link https://github.com/nodeca/pica (enable linkify to see)
@ -275,12 +275,13 @@ With a reference later in the document defining the URL location:
</textarea> </textarea>
</div> </div>
<section class="col-xs-6 full-height"> <section class="col-xs-6 full-height">
<div class="demo-control"><a href="#" class="result-mode">html / source</a></div> <div class="demo-control"><a href="#" data-result-as="html">html</a><a href="#" data-result-as="src">source</a><a href="#" data-result-as="debug">debug</a></div>
<div class="result full-height"></div> <div class="result-html full-height"></div>
<pre class="result-src full-height"><code class="result-src-content full-height"></code></pre> <pre class="result-src full-height"><code class="result-src-content full-height"></code></pre>
<pre class="result-debug full-height"><code class="result-debug-content full-height"></code></pre>
</section> </section>
</div> </div>
</div> </div>
<div class="gh-ribbon"><a href="https://github.com/jonschlinkert/remarkable" target="_blank">Fork me on GitHub</a></div> <div class="gh-ribbon"><a href="https://github.com/jonschlinkert/remarkable" target="_blank">Fork me on GitHub</a></div>
</body> </body>
</html> </html>

8
demo/index.jade

@ -86,10 +86,14 @@ html
textarea.source.full-height= s.source textarea.source.full-height= s.source
section.col-xs-6.full-height section.col-xs-6.full-height
.demo-control .demo-control
a.result-mode(href='#') html / source a(href='#' data-result-as='html') html
.result.full-height a(href='#' data-result-as='src') source
a(href='#' data-result-as='debug') debug
.result-html.full-height
pre.result-src.full-height pre.result-src.full-height
code.result-src-content.full-height code.result-src-content.full-height
pre.result-debug.full-height
code.result-debug-content.full-height
.gh-ribbon .gh-ribbon
a(href='https://github.com/jonschlinkert/remarkable' target='_blank') Fork me on GitHub a(href='https://github.com/jonschlinkert/remarkable' target='_blank') Fork me on GitHub

Loading…
Cancel
Save