npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

markrun

v0.26.0

Published

Let your markdown to run, ````js to <pre> & <script>

Downloads

125

Readme

📝 markrun

Let your markdown to run, ````js to <pre> & <script>

Build Status NPM version NPM downloads

preview

📦 Install

npm i markrun

Online demo

<script src="https://unpkg.com/markrun/dist/markrun.min.js"></script>
<script>
console.log(
    markrun('````js\nconsole.log(1)\n````')
)
</script>

📄 Usage

markrun(md [,options][,info])

var markrun = require('markrun')
var html = markrun("````js\n document.title = new Date().getTime() \n````")

var fs = require('fs')
var path = require('path')
fs.writeFileSync(path.join(__dirname, 'demo.html'), html)

defaultOptions

markrun.string

You can use ES6 template strings replace markrun.string

markrun.string(function() {/*!
````js
console.log("markrun")
````
*/})
markrun.string([
'````js',
'console.log("markrun")',
'````'
])
````js
/*_{
    html: '<div id="demo" ></div>',
    title: '行内表单',
    desc: '表单元素水平排列。'
}_*/
table('#demo', {
    inline: true
})
````
same
<!--
{
    html: '<div id="demo" ></div>',
    title: '行内表单',
    desc: '表单元素水平排列。'
}
-->
````js
table('#demo', {
    inline: true
})
````

options

options.template

template: 'string' template: function(templateData) {return 'string'}

var template = markrun.string(function () {/*!

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title><%= title %></title>
<% if (theme === 'bs') {%>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css">
<%= } %>
</head>
<body>
<%- content %>
</body>
</html>

*/})

var content = markrun.string(function () {/*!

# some

<!--
MARKRUN-DATA
{
    theme: 'bs'
}
-->

```js
console.log('markrun')
```

*/})
markrun(content, {
    templateDefaultData: {
        theme: '',
        keywords: '',
        description: ''
    },
    template: template
})

abbreviation

<!--
MR-D
{
    theme: 'bs'
}
-->

```js
console.log('markrun')

### options.compile

```shell
npm i babel babel-preset-es2015 babel-preset-react -D
var content = markrun.string(function () {/*!

<!-- {some: 'abc'} -->
````js
ReactDOM.render(
    (<div>markrun</div>),
    document.getElementById('demo')
)
````

*/})

var babel = require('babel')
markrun(content, {
    compile: {
        'js': function (source, data, info) {
            /*!
            source:
                ReactDOM.render(
                    (<div>markrun</div>),
                    document.getElementById('demo')
                )
            data: {some: 'abc'}
            */
            var code = babel.transform(source, {
                presets: [
                     require('babel-preset-es2015'),
                     require('babel-preset-react')
                ]
            }).code
            return {
                lang: 'js',
                code: code,
                // source not required
                source: source
            }
        }
    }
})

compile[lang] Should be returned

{
    lang: 'css',
    code: 'body{font-size:12px;}'
}
{
    lang: 'js',
    code: 'console.log(1)'
}
{
    lang: 'html',
    code: '<div>hello</div>'
}

Turns async function into sync

If compile function need asynchronous operations, Please use deasync

DeAsync turns async function into sync, implemented with a blocking mechanism by calling Node.js event loop at JavaScript layer. The core of deasync is writen in C++.

npm i deasync -D
var deasync = require('deasync');
var cp = require('child_process');
var exec = deasync(cp.exec);
// output result of ls -la
try{
    console.log(exec('ls -la'));
}
catch(err){
    console.log(err);
}
// done is printed last, as supposed, with cp.exec wrapped in deasync; first without.
console.log('done');

options.markdownParser

| attr | default | example | desc | |-----|----------|---------|------| | marked | false | `require('marked')`` | markdown parser |

markrun(content, {
    markdownParser: require('marked')
})

if marked is false, Use ./lib/marked.js.

Code snippets render data

````js
document.getElementById('demoA').innerHTML = 'change demoA text'
````
<div id="demoA">demoA</div>

<!-- {
    markrun_lastrun: false
} -->
````js
document.getElementById('demoB').innerHTML = 'change demoB text'
````
<div id="demoB">demoB</div>

| attr | default | example | desc | |------|---------|---------|------| | markrun_lastrun Boolean | true | false true | Script append body |

markrun_ at the beginning of is makrun rendering method.

About render data

MARKRUN-HTML

var content = markrun.string(function() {/*!

abc
<!-- MARKRUN-HTML
This text is display
-->
123

*/})
markrun(content)
/*
abc
This text is display
123
*/

abbreviation

<!-- MR-H
This text is display
-->

🔨 Development

npm i
npm run test
# or mocha -w

options.replace

default type: "pre"

options.js

{
    "name": "some options",
    "age": 23
}

write

[options.js](./options.js)
<!-- MARKRUN-REPLACE
{
    file: './options.js',
    type: 'pre'
}
-->

default options

{
    replace: {
        pre: function (data, options, info, highlight) {
            if (typeof data.run === 'undefined') {
                data.run = true
            }
            var path = require('path')
            var fs = require('fs')
            var fullpath = path.join(path.dirname(info.filepath), data.file)
            var code = fs.readFileSync(fullpath, 'utf-8').toString()
            info.deps = info.deps || []
            info.deps.push(fullpath)
            code = '<pre class="markrun-source-pre" data-lang="js" >' + highlight(code, 'js') + '</pre>'
            if (data.run) {
                code = code +'<script data-markrun-lastrun="true" src="'+ data.file + '"></script>'
            }
            return code
        }
    }
}

no need script tag

[options.js](./options.js)
<!-- MARKRUN-REPLACE
{
    file: './options.js',
    type: 'pre',
    run: false
}
-->

abbreviation

[options.js](./options.js)
<!-- MR-R
{
    "file": "./options.js",
    "type": "pre"
}
-->

setOptions

markrun.setOptions({
    template: ''
})
markrun(md)