Browse Source

Added directive

pull/1027/head
Sergey Makhnatkin 2 years ago
parent
commit
f2bcb6c30a
  1. 6
      package.json
  2. 102
      support/demo_template/index.mjs
  3. 2
      support/demo_template/rollup.config.mjs

6
package.json

@ -28,6 +28,7 @@
}, },
"scripts": { "scripts": {
"lint": "eslint .", "lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "npm run lint && CJS_ONLY=1 npm run build && c8 --exclude dist --exclude test -r text -r html -r lcov mocha && node support/specsplit.mjs", "test": "npm run lint && CJS_ONLY=1 npm run build && c8 --exclude dist --exclude test -r text -r html -r lcov mocha && node support/specsplit.mjs",
"doc": "node support/build_doc.mjs", "doc": "node support/build_doc.mjs",
"gh-doc": "npm run doc && gh-pages -d apidoc -f", "gh-doc": "npm run doc && gh-pages -d apidoc -f",
@ -38,7 +39,8 @@
"specsplit": "support/specsplit.mjs good -o test/fixtures/commonmark/good.txt && support/specsplit.mjs bad -o test/fixtures/commonmark/bad.txt && support/specsplit.mjs", "specsplit": "support/specsplit.mjs good -o test/fixtures/commonmark/good.txt && support/specsplit.mjs bad -o test/fixtures/commonmark/bad.txt && support/specsplit.mjs",
"todo": "grep 'TODO' -n -r ./lib 2>/dev/null", "todo": "grep 'TODO' -n -r ./lib 2>/dev/null",
"prepublishOnly": "npm test && npm run build && npm run gh-demo && npm run gh-doc", "prepublishOnly": "npm test && npm run build && npm run gh-demo && npm run gh-doc",
"dev": "node server/server.js" "server": "node server/server.js",
"dev": "npm run lint:fix && node support/build_demo.mjs && npm run server"
}, },
"files": [ "files": [
"index.mjs", "index.mjs",
@ -51,6 +53,7 @@
"entities": "^4.4.0", "entities": "^4.4.0",
"linkify-it": "^5.0.0", "linkify-it": "^5.0.0",
"markdown-it": "^14.1.0", "markdown-it": "^14.1.0",
"markdown-it-directive": "^1.0.1",
"mdurl": "^2.0.0", "mdurl": "^2.0.0",
"node-fetch": "^3.3.2", "node-fetch": "^3.3.2",
"punycode.js": "^2.3.1", "punycode.js": "^2.3.1",
@ -59,6 +62,7 @@
"devDependencies": { "devDependencies": {
"@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-terser": "^0.4.4",
"ansi": "^0.3.0", "ansi": "^0.3.0",

102
support/demo_template/index.mjs

@ -5,15 +5,16 @@ import * as mdurl from 'mdurl'
import hljs from 'highlight.js' import hljs from 'highlight.js'
// plugins // plugins
import md_abbr from 'markdown-it-abbr' // import md_abbr from 'markdown-it-abbr'
import md_container from 'markdown-it-container' // import md_container from 'markdown-it-container'
import md_deflist from 'markdown-it-deflist' // import md_deflist from 'markdown-it-deflist'
import { full as md_emoji } from 'markdown-it-emoji' // import { full as md_emoji } from 'markdown-it-emoji'
import md_footnote from 'markdown-it-footnote' // import md_footnote from 'markdown-it-footnote'
import md_ins from 'markdown-it-ins' // import md_ins from 'markdown-it-ins'
import md_mark from 'markdown-it-mark' // import md_mark from 'markdown-it-mark'
import md_sub from 'markdown-it-sub' // import md_sub from 'markdown-it-sub'
import md_sup from 'markdown-it-sup' // import md_sup from 'markdown-it-sup'
import md_directive from 'markdown-it-directive'
let mdHtml, mdSrc, permalink, scrollMap let mdHtml, mdSrc, permalink, scrollMap
@ -31,13 +32,13 @@ const defaults = {
langPrefix: 'language-', langPrefix: 'language-',
// autoconvert URL-like texts to links // autoconvert URL-like texts to links
linkify: true, linkify: false,
// Enable smartypants and other sweet transforms // Enable smartypants and other sweet transforms
typographer: true, typographer: false,
// options below are for demo only // options below are for demo only
_highlight: true, _highlight: false,
_strict: false, _strict: false,
_view: 'html' // html / src / debug _view: 'html' // html / src / debug
} }
@ -91,25 +92,66 @@ function mdInit () {
mdSrc = window.markdownit('commonmark') mdSrc = window.markdownit('commonmark')
} else { } else {
mdHtml = window.markdownit(defaults) mdHtml = window.markdownit(defaults)
.use(md_abbr) // .use(md_abbr)
.use(md_container, 'warning') // .use(md_container, 'warning')
.use(md_deflist) // .use(md_deflist)
.use(md_emoji) // .use(md_emoji)
.use(md_footnote) // .use(md_footnote)
.use(md_ins) // .use(md_ins)
.use(md_mark) // .use(md_mark)
.use(md_sub) // .use(md_sub)
.use(md_sup) // .use(md_sup)
.use(md_directive)
// .use((md) => {
// md.inlineDirectives['directive-name'] = (state, content, dests, attrs, contentStart, contentEnd, directiveStart, directiveEnd) => {
// const token = state.push('html_inline', '', 0)
// token.content = JSON.stringify({ directive: 'directive-name', content, dests, attrs }) + '\n'
// }
// md.blockDirectives['directive-name'] = (
// state, content, contentTitle, inlineContent, dests, attrs,
// contentStartLine, contentEndLine,
// contentTitleStart, contentTitleEnd,
// inlineContentStart, inlineContentEnd,
// directiveStartLine, directiveEndLine
// ) => {
// const token = state.push('html_block', '', 0)
// token.map = [directiveStartLine, directiveEndLine]
// token.content = JSON.stringify({
// directive: 'directive-name (block)', content, contentTitle, inlineContent, dests, attrs
// }) + '\n'
// }
// })
mdSrc = window.markdownit(defaults) mdSrc = window.markdownit(defaults)
.use(md_abbr) // .use(md_abbr)
.use(md_container, 'warning') // .use(md_container, 'warning')
.use(md_deflist) // .use(md_deflist)
.use(md_emoji) // .use(md_emoji)
.use(md_footnote) // .use(md_footnote)
.use(md_ins) // .use(md_ins)
.use(md_mark) // .use(md_mark)
.use(md_sub) // .use(md_sub)
.use(md_sup) // .use(md_sup)
.use(md_directive)
// .use((md) => {
// md.inlineDirectives['directive-name'] = (state, content, dests, attrs, contentStart, contentEnd, directiveStart, directiveEnd) => {
// const token = state.push('html_inline', '', 0)
// token.content = JSON.stringify({ directive: 'directive-name', content, dests, attrs }) + '\n'
// }
// md.blockDirectives['directive-name'] = (
// state, content, contentTitle, inlineContent, dests, attrs,
// contentStartLine, contentEndLine,
// contentTitleStart, contentTitleEnd,
// inlineContentStart, inlineContentEnd,
// directiveStartLine, directiveEndLine
// ) => {
// const token = state.push('html_block', '', 0)
// token.map = [directiveStartLine, directiveEndLine]
// token.content = JSON.stringify({
// directive: 'directive-name (block)', content, contentTitle, inlineContent, dests, attrs
// }) + '\n'
// }
// })
} }
// Beautify output of parser for html content // Beautify output of parser for html content

2
support/demo_template/rollup.config.mjs

@ -1,10 +1,12 @@
import nodeResolve from '@rollup/plugin-node-resolve' import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs' import commonjs from '@rollup/plugin-commonjs'
import terser from '@rollup/plugin-terser' import terser from '@rollup/plugin-terser'
import json from '@rollup/plugin-json'
const plugins = [ const plugins = [
nodeResolve({ preferBuiltins: true }), nodeResolve({ preferBuiltins: true }),
commonjs(), commonjs(),
json(),
// Here terser is used only to force ascii output // Here terser is used only to force ascii output
terser({ terser({
mangle: false, mangle: false,

Loading…
Cancel
Save