Skip to content

Commit

Permalink
feature(dingus) nicer tabs, now displays TemplateMark AST
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <[email protected]>
  • Loading branch information
jeromesimeon committed Aug 6, 2020
1 parent 7c345b6 commit e86c42c
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"version": "0.12.2",
"private": true,
"scripts": {
"dingus": "lerna exec --scope dingus -- npm run demo",
"dingus": "lerna exec --scope dingus -- npm run dingus",
"build": "lerna run build",
"postinstall": "npm run models:get && lerna bootstrap",
"models:get": "node ./scripts/external/getExternalModels.js",
Expand Down
15 changes: 12 additions & 3 deletions packages/dingus/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/*global $, _*/

const markdownit = require('markdown-it');
const tokensToUntypedTemplateMark = require('@accordproject/markdown-template').templatemarkutil.tokensToUntypedTemplateMark;

var mdurl = require('mdurl');

Expand Down Expand Up @@ -72,7 +73,7 @@ var defaults = {
// options below are for demo only
_highlight: true,
_strict: false,
_view: 'html' // html / src / debug
_view: 'html' // html / src / debug / ast
};

defaults.highlight = function (str, lang) {
Expand Down Expand Up @@ -117,6 +118,7 @@ function setResultView(val) {
$('body').removeClass('result-as-html');
$('body').removeClass('result-as-src');
$('body').removeClass('result-as-debug');
$('body').removeClass('result-as-ast');
$('body').addClass('result-as-' + val);
defaults._view = val;
}
Expand Down Expand Up @@ -172,7 +174,7 @@ function updateResult() {
var source = $('.source').val();

// Update only active view to avoid slowdowns
// (debug & src view with highlighting are a bit slow)
// (debug & ast & src view with highlighting are a bit slow)
if (defaults._view === 'src') {
setHighlightedlContent('.result-src-content', mdSrc.render(source), 'html');

Expand All @@ -183,6 +185,13 @@ function updateResult() {
'json'
);

} else if (defaults._view === 'ast') {
setHighlightedlContent(
'.result-ast-content',
JSON.stringify(tokensToUntypedTemplateMark(mdSrc.parse(source, { references: {} }),'contract'), null, 2),
'json'
);

} else { /*defaults._view === 'html'*/
$('.result-html').html(mdHtml.render(source));
}
Expand Down Expand Up @@ -377,7 +386,7 @@ function loadPermalink() {
});

// sanitize for sure
if ([ 'html', 'src', 'debug' ].indexOf(defaults._view) === -1) {
if ([ 'html', 'src', 'debug', 'ast' ].indexOf(defaults._view) === -1) {
defaults._view = 'html';
}
}
Expand Down
9 changes: 6 additions & 3 deletions packages/dingus/lib/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ html
textarea.source.full-height= s.source
section.col-xs-6.full-height
.demo-control
a(href='#' data-result-as='html') html
a(href='#' data-result-as='src') source
a(href='#' data-result-as='debug') debug
a(href='#' data-result-as='html') preview
a(href='#' data-result-as='src') html
a(href='#' data-result-as='debug') tokens
a(href='#' data-result-as='ast') ast
.result-html.full-height
pre.hljs.result-src.full-height
code.result-src-content.full-height
pre.hljs.result-debug.full-height
code.result-debug-content.full-height
pre.hljs.result-ast.full-height
code.result-ast-content.full-height
12 changes: 12 additions & 0 deletions packages/dingus/lib/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,41 @@ body

.result-src
.result-debug
.result-ast
display none

.result-src-content
.result-debug-content
.result-ast-content
white-space pre

.result-as-html
.result-html
display block
.result-src
.result-debug
.result-ast
display none
.result-as-src
.result-src
display block
.result-html
.result-debug
.result-ast
display none
.result-as-debug
.result-debug
display block
.result-html
.result-src
.result-ast
display none
.result-as-ast
.result-ast
display block
.result-html
.result-src
.result-debug
display none

.demo-control
Expand Down
3 changes: 2 additions & 1 deletion packages/dingus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"repository": "accordproject/markdown-transform",
"license": "Apache-2.0",
"scripts": {
"demo": "node scripts/build_demo.js"
"dingus": "node scripts/build_dingus.js"
},
"files": [],
"dependencies": {},
"devDependencies": {
"@accordproject/markdown-it-template": "0.12.2",
"@accordproject/markdown-template": "0.12.2",
"autoprefixer-stylus": "^0.14.0",
"browserify": "^16.3.0",
"highlight.js": "^10.0.3",
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions packages/markdown-template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

module.exports.util = require('./lib/util');
module.exports.templatemarkutil = require('./lib/templatemarkutil');
module.exports.datetimeutil = require('./lib/datetimeutil');
module.exports.normalizeNLs = require('./lib/normalize').normalizeNLs;
module.exports.ParserManager = require('./lib/parsermanager');
Expand Down

0 comments on commit e86c42c

Please sign in to comment.