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 🙏

© 2026 – Pkg Stats / Ryan Hefner

hulk-markdown-loader

v2.0.10

Published

san markdown loader

Readme

hulk-markdown-loader

专门给 Component 命令使用的 markdown loader,会将 markdown 文档中的 demo 部分代码解析出来,生成可展现的 San 组件。

Usage

{
    test: /\.md$/,
    use: [{loader: 'hulk-markdown-loader': options: {template: 'path.template'}}]
}

template 说明

支持自定义 template,默认 template 为:

<template>
    <section class="code-box {{isExpand?'expand':''}}" id="${id}">
        <section class="code-box-demo"><code-preview /></section>
        <section class="code-box-meta markdown">
            <text-container-placeholder />
            <span class="code-expand-icon" on-click="toggleExpand">
                <img
                    alt="expand code"
                    src="https://gw.alipayobjects.com/zos/rmsportal/wSAkBuJFbdxsosKKpqyq.svg"
                    class="{{isExpand?'code-expand-icon-hide':'code-expand-icon-show'}}"
                />
                <img
                    alt="expand code"
                    src="https://gw.alipayobjects.com/zos/rmsportal/OpROPHYqWmrMDBFMZtKF.svg"
                    class="{{isExpand?'code-expand-icon-show':'code-expand-icon-hide'}}"
                />
            </span>
        </section>
        <section class="highlight-wrapper {{isExpand?'highlight-wrapper-expand':''}}">
            <code-container-placeholder />
        </section>
    </section>
</template>
<script>
    export default {
        initData() {
            return {
                isExpand: false
            };
        },
        toggleExpand() {
            this.data.set('isExpand', !this.data.get('isExpand'));
        }
    };
</script>

特殊标签说明:

  • <code-preview/>: markdown 中的 fence部分 san 代码会被渲染出来的效果
  • <text-container-placeholder/>: markdown 中text标签内部的文案转 html
  • <code-container-placeholder/>:markdown 中的 fence部分 san 代码,被 prismjs 语法高亮

参数

  • ignore:正则忽略
  • template:模板路径
  • context:目录上下文
  • textTag = 'text':匹配 text 的 tag,支持 i18n 写法:<text lang='cn'>
  • i18n = 'cn':默认解析的文档语言
  • exportType: 支持三种,默认是 app,即
    • app:默认,即通常的用法,会返回template转成的 doc+预览的效果,可以修改 template 模板的方式来修改样式
    • object:返回的是包含 text、sanComponent 和 code 的对象,在index.js中可以自由使用灵活度较高;
    • component:仅仅返回 markdown 文档中的代码部分 san 组件,用于只显示预览效果。

只展现html中的代码,不显示页面文档内容

新建preview.js,内容如下:

// html:
import {Component} from 'san';
import Basic from './basic.md?exportType=component';

export default class Index extends Component {
    static template = `
        <div>
            <basic/>
        </div>
    `;
    static components = {
        basic: Basic
    };
}

在这里import Basic from './basic.md?exportType=component'得到的是不再是一个完整的文档+预览内容,而是得到预览部分代码的的 San 组件,通过这种方式可以直接预览 Markdown 文档中的代码部分效果。可以用于移动页面嵌入 iframe 预览效果

如果组件使用了 ts 语法,需要完善相应 loader 配置

假设有个ts-comp.san文件,script内容如下:

<script lang="ts">
import {Component} from 'san';

const text: string = 'Hello TS!';

export default class TsComp extends Component {
    static template = `
        <div>{{ text }}</div>
    `;

    initData() {
        return {
            text
        };
    }
}
</script>

那么 webpack 配置文件中需要包括:

{
    module: {
        rules: [
            {
                test: /\.md/,
                use: 'hulk-markdown-loader'
            },
            {
                test: /\.san$/,
                use: 'san-loader'
            },
            {
                test: /\.ts$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: [
                            ...babelConfig.presets,
                            ['@babel/preset-typescript', {
                                allExtensions: true
                            }]
                        ],
                        plugins: babelConfig.plugins
                    }
                }
            },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: babelConfig
                }
            },
            {
                test: /\.(css|less)$/,
                oneOf: [
                    // 这里匹配 `<style lang="less" module>`
                    {
                        resourceQuery: /module/,
                        use: [
                            'style-loader',
                            {
                                loader: 'css-loader',
                                options: {
                                    modules: {
                                        localIdentName: '[local]_[hash:base64:5]'
                                    },
                                    localsConvention: 'camelCase'
                                }
                            },
                            'less-loader'
                        ]
                    },
                    // 这里匹配 `<style lang="less">`
                    {
                        use: [
                            'style-loader',
                            'css-loader',
                            'less-loader'
                        ]
                    }
                ]
            }
            {
                test: /\.html$/,
                use: [
                    {
                        loader: 'html-loader',
                        options: {
                            esModule: false
                        }
                    }
                ]
            }
        ]
    }
}