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

dbl-markdown-loader

v1.0.6

Published

--- imports: import {Button} from '@ali/dblx'; --- # markdown-it-react-loader

Downloads

5

Readme


imports: import {Button} from '@ali/dblx';

markdown-it-react-loader

用Markdown提供一份直观的React文档,有可运行的示例,有示例源代码,有示例的说明。

这样用户看起来直观,编写者写起来也直观,维护成本低。

经过几番尝试,结合 React 的特点。写了一套处理 Markdown 文件的 webpack loader,可以将 Markdown 转成 React 文件。


Install

npm install dbl-markdown-loader

在 webpack 中加入 loader

{
    test: /\.md$/,
    loader: 'babel!dbl-markdown-loader'
}

随后把md文件当成一个react component去使用即可。比如本工程中的demo

import ReadMe from '../README.md';

options

  • className 默认'doc',页面容器的class
// webpack.config.js
module.export = {
    //...省略
    markdownItReact: function () {
        return {
            className: 'doc' // 默认也是doc
        };
    }
};

具体见webpack.config.js

样式

提供样式文件index.css,可直接引入或自定义。


语法介绍

正常的Markdown语法不影响。有几个需要注意的地方:

使用示例

纯渲染

::: demo 这是描述这是描述,点三角可展开代码。也可以不提供

<button onClick={() => alert('dou la mi fa sou')}>click me</button>

:::

    ::: demo 这是描述这是**描述**,点三角可展开代码
    ```jsx
    <button>adfasdfa</button>
    ```
    :::

注意:渲染到页面的代码语言必须写jsx,因为loaders会把语言为jsx放入render的jsx内

引入其他库

::: demo Button组件

<Button/>

:::

在md开头添加引入库

---
imports:
    import {Button} from '@ali/dblx';
---

然后

    ::: demo 
    ```jsx
    <Loading/>
    ```
    :::

更丰富的交互

比如需要 state,需要handleXXX

::: demo 更丰富的交互写在js内,这种场景更多

class Test extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            value: 'hello'
        };
    }
    handleChange(e){
        this.setState({value: e.target.value});
    }
    render(){
        return (<input value={this.state.value} onChange={::this.handleChange} />)
    }
}
<Test/>

:::

    ::: demo 更丰富的交互写在js内,这种场景更多
    ```js
    class Test extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                value: 'hello'
            };
        }
        handleChange(e){
            this.setState({value: e.target.value});
        }
        render(){
            return (<input value={this.state.value} onChange={::this.handleChange} />)
        }
    }
    ```
    ```jsx
    <Test/>
    ```
    :::

花括号 (表达式)

有意思的是可以用花括号写表达式,比如我要显示

当前url是:{location.href}

userAgent是:{navigator.userAgent}

因而你要用花括号时{'{}'}需要写成{'{\'{}\'}'}

代码里面的花括号

{'{ }'}会自动转,无需关注

<div>{location.href}</div>

参考

其他

anchor

github page是不支持browserHistory的,一般路由用hash处理。而锚点也是用hash,会冲突。 所以只能自己处理。 监听锚的点击,阻止默认事件,然后用你自己的规则处理吧。

react模块

默认已经import React from 'react';