Browse Source

Fix demo build

pull/979/head
Vitaly Puzrin 6 months ago
parent
commit
737c95a129
  1. 2
      lib/index.mjs
  2. 7
      package.json
  3. 26
      support/build_demo.js
  4. 28
      support/build_demo.mjs
  5. 155
      support/demo_template/index.css
  6. 97
      support/demo_template/index.html
  7. 6
      support/demo_template/index.js
  8. 105
      support/demo_template/index.pug
  9. 143
      support/demo_template/index.styl
  10. 2
      support/demo_template/rollup.config.mjs
  11. 17
      support/demodata.js

2
lib/index.mjs

@ -8,7 +8,7 @@ import ParserBlock from './parser_block.mjs';
import ParserInline from './parser_inline.mjs';
import LinkifyIt from 'linkify-it';
import mdurl from 'mdurl';
import punycode from 'punycode';
import punycode from 'punycode.js';
import cfg_default from './presets/default.mjs';
import cfg_zero from './presets/zero.mjs';

7
package.json

@ -21,7 +21,7 @@
"report-coveralls": "c8 --reporter=lcov mocha",
"doc": "node support/build_doc.mjs",
"gh-doc": "npm run doc && gh-pages -d apidoc -f",
"demo": "npm run lint && node support/build_demo.js",
"demo": "npm run lint && node support/build_demo.mjs",
"gh-demo": "npm run demo && gh-pages -d demo -f -b master -r git@github.com:markdown-it/markdown-it.github.io.git",
"browserify": "rollup -c support/rollup.config.js",
"benchmark-deps": "npm install --prefix benchmark/extra/ -g marked@0.3.6 commonmark@0.26.0 markdown-it/markdown-it.git#2.2.1",
@ -40,7 +40,7 @@
"entities": "^4.4.0",
"linkify-it": "^4.0.1",
"mdurl": "^1.0.1",
"punycode": "^2.3.1",
"punycode.js": "^2.3.1",
"uc.micro": "^1.0.5"
},
"devDependencies": {
@ -49,7 +49,6 @@
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"ansi": "^0.3.0",
"autoprefixer-stylus": "^1.0.0",
"benchmark": "~2.1.0",
"c8": "^8.0.1",
"chai": "^4.2.0",
@ -73,10 +72,8 @@
"mocha": "^10.2.0",
"ndoc": "^6.0.0",
"needle": "^3.0.0",
"pug-cli": "^1.0.0-alpha6",
"rollup": "^4.5.0",
"shelljs": "^0.8.4",
"stylus": "^0.62.0",
"supertest": "^6.0.1"
},
"mocha": {

26
support/build_demo.js

@ -1,26 +0,0 @@
#!/usr/bin/env node
'use strict';
/* eslint-env es6 */
const shell = require('shelljs');
shell.rm('-rf', 'demo');
shell.mkdir('demo');
shell.exec('support/demodata.js > support/demo_template/sample.json');
shell.exec('node_modules/.bin/pug support/demo_template/index.pug --pretty \
--obj support/demo_template/sample.json \
--out demo');
shell.exec('node_modules/.bin/stylus -u autoprefixer-stylus \
< support/demo_template/index.styl \
> demo/index.css');
shell.rm('-rf', 'support/demo_template/sample.json');
shell.exec('node_modules/.bin/rollup -c support/demo_template/rollup.config.js');
shell.cp('support/demo_template/README.md', 'demo/');

28
support/build_demo.mjs

@ -0,0 +1,28 @@
#!/usr/bin/env node
import shell from 'shelljs';
import { readFileSync, writeFileSync } from 'fs';
function escape(input) {
return input
.replaceAll('&', '&amp;')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('"', '&quot;');
//.replaceAll("'", '&#039;');
}
shell.rm('-rf', 'demo');
shell.mkdir('demo');
shell.cp('support/demo_template/README.md', 'demo/');
shell.cp('support/demo_template/index.css', 'demo/');
// Read html template and inject escaped sample
const html = readFileSync('support/demo_template/index.html', 'utf8');
const sample = readFileSync('support/demo_template/sample.md', 'utf8');
const output = html.replace('<!--SAMPLE-->', escape(sample));
writeFileSync('demo/index.html', output);
shell.exec('node_modules/.bin/rollup -c support/demo_template/rollup.config.mjs');

155
support/demo_template/index.css

@ -0,0 +1,155 @@
html,
body,
.full-height {
height: 100%;
}
body {
overflow-x: hidden;
padding-bottom: 160px;
background-color: #fbfbfb;
}
/* hack to allign emojies to line height */
.emoji {
height: 1.2em;
}
.demo-options {
margin-bottom: 30px;
}
.opt__strict .not-strict {
opacity: 0.3;
}
.checkbox {
margin-right: 10px;
}
.source {
width: 100%;
font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
font-size: 13px;
padding: 2px;
}
.result-html {
padding: 2px 10px;
overflow: auto;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 4px;
}
.result-html img {
max-width: 35%;
}
.result-src,
.result-debug {
display: none;
}
.result-src-content,
.result-debug-content {
white-space: pre;
}
.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; }
.result-as-debug .result-html,
.result-as-debug .result-src { display: none; }
.demo-control {
position: absolute;
right: 15px;
top: -17px;
border-radius: 6px 6px 0 0;
font-size: 12px;
background-color: #ddd;
}
.demo-control a {
padding: 0 20px;
}
.demo-control a:first-child {
padding-left: 30px;
}
.demo-control a:last-child {
padding-right: 30px;
}
/* twbs fix */
.hljs {
padding: 9.5px;
}
.hljs code {
white-space: pre;
}
.footnotes {
-moz-column-count: 2;
column-count: 2;
}
.footnotes-list {
padding-left: 2em;
}
/* custom container */
.warning {
background-color: #ff8;
padding: 20px;
border-radius: 6px;
}
.gh-ribbon {
display: block;
position: absolute;
right: -60px;
top: 44px;
transform: rotate(45deg);
width: 230px;
z-index: 10000;
white-space: nowrap;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
background-color: #686868;
box-shadow: 0 0 2px rgba(102,102,102,0.4);
padding: 1px 0;
}
.gh-ribbon a {
text-decoration: none !important;
border: 1px solid #ccc;
color: #fff;
display: block;
font-size: 13px;
font-weight: 700;
outline: medium none;
padding: 4px 50px 2px;
text-align: center;
}
/* Override default responsiveness */
.form-inline .radio,
.form-inline .checkbox {
display: inline-block;
margin-bottom: 0;
margin-top: 0;
}
.form-inline .form-group {
display: inline-block;
margin-bottom: 0;
vertical-align: middle;
}
.form-inline .form-control {
display: inline-block;
vertical-align: middle;
width: auto;
}

97
support/demo_template/index.html

@ -0,0 +1,97 @@
<!DOCTYPE html>
<html>
<head>
<title>markdown-it demo</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.0.5/es5-shim.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/lodash/2.4.1/lodash.js"></script>
<script src="https://cdn.jsdelivr.net/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/bootstrap/3.2.0/css/bootstrap.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/highlight.js/9.1.0/styles/github.min.css">
<script src="markdown-it.js"></script>
<script src="https://twemoji.maxcdn.com/twemoji.min.js"></script>
<link rel="stylesheet" href="index.css">
<script src="index.js"></script>
<!-- Ancient IE support - load shiv & kill broken highlighter--><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script>window.hljs = null;</script>
<![endif]-->
<!-- GA counter-->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(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)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-26895916-4', 'auto');
ga('require', 'displayfeatures');
ga('require', 'linkid', 'linkid.js');
ga('send', 'pageview');
</script>
</head>
<body>
<div class="container">
<h1>
markdown-it <small>demo</small></h1>
<div class="form-inline demo-options">
<div class="checkbox not-strict">
<label class="_tip" title="enable html tags in source text">
<input id="html" type="checkbox"> html
</label>
</div>
<div class="checkbox not-strict">
<label class="_tip" title="produce xtml output (add / to single tags (&lt;br /&gt; instead of &lt;br&gt;)">
<input id="xhtmlOut" type="checkbox"> xhtmlOut
</label>
</div>
<div class="checkbox not-strict">
<label class="_tip" title="newlines in paragraphs are rendered as &lt;br&gt;">
<input id="breaks" type="checkbox"> breaks
</label>
</div>
<div class="checkbox not-strict">
<label class="_tip" title="autoconvert link-like texts to links">
<input id="linkify" type="checkbox"> linkify
</label>
</div>
<div class="checkbox not-strict">
<label class="_tip" title="do typographic replacements, (c) → © and so on">
<input id="typographer" type="checkbox"> typographer
</label>
</div>
<div class="checkbox not-strict">
<label class="_tip" title="enable output highlight for fenced blocks">
<input id="_highlight" type="checkbox"> highlight
</label>
</div>
<div class="form-group not-strict">
<input class="form-control _tip" id="langPrefix" type="input" placeholder="language prefix" title="css class language prefix for fenced code blocks">
</div>
<div class="checkbox">
<label class="_tip" title="force strict CommonMark mode - output will be equal to reference parser">
<input id="_strict" type="checkbox"> CommonMark strict
</label>
</div>
</div>
</div>
<div class="container full-height">
<div class="row full-height">
<div class="col-xs-6 full-height">
<div class="demo-control"><a class="source-clear" href="#">clear</a><a id="permalink" href="./" title="Share this snippet as link"><strong>permalink</strong></a></div>
<textarea class="source full-height"><!--SAMPLE--></textarea>
</div>
<section class="col-xs-6 full-height">
<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-html full-height"></div>
<pre class="hljs result-src full-height"><code class="result-src-content full-height"></code></pre>
<pre class="hljs result-debug full-height"><code class="result-debug-content full-height"></code></pre>
</section>
</div>
</div>
<div class="gh-ribbon"><a href="https://github.com/markdown-it/markdown-it" target="_blank">Fork me on GitHub</a></div>
</body>
</html>

6
support/demo_template/index.js

@ -5,14 +5,16 @@
var mdurl = require('mdurl');
var hljs = require('highlight.js');
/*
var hljs = require('highlight.js/lib/core');
hljs.registerLanguage('actionscript', require('highlight.js/lib/languages/actionscript'));
hljs.registerLanguage('apache', require('highlight.js/lib/languages/apache'));
hljs.registerLanguage('armasm', require('highlight.js/lib/languages/armasm'));
hljs.registerLanguage('xml', require('highlight.js/lib/languages/xml'));
hljs.registerLanguage('asciidoc', require('highlight.js/lib//languages/asciidoc'));
//hljs.registerLanguage('asciidoc', require('highlight.js/lib//languages/asciidoc'));
hljs.registerLanguage('avrasm', require('highlight.js/lib/languages/avrasm'));
hljs.registerLanguage('bash', require('highlight.js/lib/languages/bash'));
hljs.registerLanguage('clojure', require('highlight.js/lib/languages/clojure'));
@ -62,7 +64,7 @@ hljs.registerLanguage('typescript', require('highlight.js/lib/languages/typesc
hljs.registerLanguage('verilog', require('highlight.js/lib/languages/verilog'));
hljs.registerLanguage('vhdl', require('highlight.js/lib/languages/vhdl'));
hljs.registerLanguage('yaml', require('highlight.js/lib/languages/yaml'));
*/
var mdHtml, mdSrc, permalink, scrollMap;

105
support/demo_template/index.pug

@ -1,105 +0,0 @@
doctype html
html
head
title markdown-it demo
meta(charset='UTF-8')
meta(http-equiv='X-UA-Compatible' content='IE=edge')
meta(name='viewport' content='width=device-width, initial-scale=1')
script(src='https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.0.5/es5-shim.min.js')
script(src='https://cdn.jsdelivr.net/jquery/1.11.1/jquery.min.js')
script(src='https://cdn.jsdelivr.net/lodash/2.4.1/lodash.js')
script(src='https://cdn.jsdelivr.net/bootstrap/3.2.0/js/bootstrap.min.js')
link(rel='stylesheet' href='https://cdn.jsdelivr.net/bootstrap/3.2.0/css/bootstrap.css')
link(rel='stylesheet' href='https://cdn.jsdelivr.net/highlight.js/9.1.0/styles/github.min.css')
script(src='markdown-it.js')
script(src='https://twemoji.maxcdn.com/twemoji.min.js')
link(rel='stylesheet' href='index.css')
script(src='index.js')
// Ancient IE support - load shiv & kill broken highlighter
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script>window.hljs = null;</script>
<![endif]-->
// GA counter
script.
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(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)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-26895916-4', 'auto');
ga('require', 'displayfeatures');
ga('require', 'linkid', 'linkid.js');
ga('send', 'pageview');
body
.container
- var s = self.self.demo;
h1 markdown-it
|
small demo
.form-inline.demo-options
.checkbox.not-strict
label._tip(title='enable html tags in source text')
input#html(type='checkbox')
| html
.checkbox.not-strict
label._tip(title='produce xtml output (add / to single tags (<br /> instead of <br>)')
input#xhtmlOut(type='checkbox')
| xhtmlOut
.checkbox.not-strict
label._tip(title='newlines in paragraphs are rendered as <br>')
input#breaks(type='checkbox')
| breaks
.checkbox.not-strict
label._tip(title='autoconvert link-like texts to links')
input#linkify(type='checkbox')
| linkify
.checkbox.not-strict
label._tip(title='do typographic replacements, (c) → © and so on')
input#typographer(type='checkbox')
| typographer
.checkbox.not-strict
label._tip(title='enable output highlight for fenced blocks')
input#_highlight(type='checkbox')
| highlight
.form-group.not-strict
input#langPrefix.form-control._tip(
type='input'
placeholder='language prefix'
title='css class language prefix for fenced code blocks'
)
.checkbox
label._tip(title='force strict CommonMark mode - output will be equal to reference parser')
input#_strict(type='checkbox')
| CommonMark strict
.container.full-height
.row.full-height
.col-xs-6.full-height
.demo-control
a.source-clear(href='#') clear
a#permalink(href='./' title='Share this snippet as link'): strong permalink
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
.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
.gh-ribbon
a(href='https://github.com/markdown-it/markdown-it' target='_blank') Fork me on GitHub

143
support/demo_template/index.styl

@ -1,143 +0,0 @@
html, body, .full-height
height 100%
body
overflow-x hidden
padding-bottom 160px
background-color #fbfbfb
// hack to allign emojies to line height
.emoji
height: 1.2em;
.demo-options
margin-bottom 30px
.opt__strict .not-strict
opacity 0.3
.checkbox
margin-right 10px
.source
width 100%
font-family Menlo, Monaco, Consolas, "Courier New", monospace
font-size 13px
padding 2px
.result-html
padding 2px 10px
overflow auto
background-color #fff
border 1px solid #ccc
border-radius 4px
img
max-width 35%
.result-src
.result-debug
display none
.result-src-content
.result-debug-content
white-space pre
.result-as-html
.result-html
display block
.result-src
.result-debug
display none
.result-as-src
.result-src
display block
.result-html
.result-debug
display none
.result-as-debug
.result-debug
display block
.result-html
.result-src
display none
.demo-control
position absolute
right 15px
top -17px
border-radius 6px 6px 0 0
font-size 12px
background-color #ddd
a
padding 0 20px
a:first-child
padding-left 30px
a:last-child
padding-right 30px
// twbs fix
.hljs
padding 9.5px
code
white-space pre
.footnotes
-moz-column-count 2
-webkit-column-count 2
column-count 2
.footnotes-list
padding-left 2em
// custom container
.warning
background-color #ff8
padding 20px
border-radius 6px
.gh-ribbon
display block
position absolute
right -60px
top 44px
transform rotate(45deg)
width 230px
z-index 10000
white-space nowrap
font-family "Helvetica Neue", Helvetica, Arial, sans-serif
background-color #686868
box-shadow 0 0 2px rgba(102,102,102,0.4)
padding 1px 0
a
text-decoration none !important
border 1px solid #ccc
color #fff
display block
font-size 13px
font-weight 700
outline medium none
padding 4px 50px 2px
text-align center
////////////////////////////////////////////////////////////////////////////////
// Override default responsiveness
//
.form-inline
.radio
.checkbox
display inline-block
margin-bottom 0
margin-top 0
.form-group
display inline-block
margin-bottom 0
vertical-align: middle
.form-control
display inline-block
vertical-align middle
width auto

2
support/demo_template/rollup.config.js → support/demo_template/rollup.config.mjs

@ -22,7 +22,7 @@ const plugins = [
export default [
{
input: 'index.js',
input: 'index.mjs',
output: {
file: 'demo/markdown-it.js',
format: 'umd',

17
support/demodata.js

@ -1,17 +0,0 @@
#!/usr/bin/env node
// Build demo data for embedding into html
/*eslint-disable no-console*/
'use strict';
var fs = require('fs');
var path = require('path');
console.log(JSON.stringify({
self: {
demo: {
source: fs.readFileSync(path.join(__dirname, './demo_template/sample.md'), 'utf8')
}
}
}, null, 2));
Loading…
Cancel
Save