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

@ylzcc/remark-code

v0.0.8

Published

an extension of `unifiedjs` to enable code syntax, with a new feature `props`.

Downloads

31

Readme

@imarkjs/remark-code

Introduction

an extension for unified to enable code syntax, support that parse AST from markdown and compile AST into markdown.

Features

  1. Compatible with standard code syntax. ```lang metadata code ```

  2. Expending a new feature props. ```lang metadata code ```{{props}}

Using

Install

npm i unified remark-parse remark-stringify @imarkjs/remark-code -S

Example


import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import remarkCode from '@imarkjs/remark-code'

const str = `
# Example
\`\`\`lang meta
let s = 'hi'
console.log(s)
\`\`\`{{properties}}
`

const processor1 = unified()
    .use(remarkParse)
    .use(remarkCode)
const ast = processor1.parse(str)
console.log('ast ->', ast)

const processor2 = unified()
    .use(remarkParse)
    .use(remarkCode)
    .use(remarkStringify)
const md = processor2.stringify(ast)
console.log('markdown ->', md)

run it, you will get result as following:

ast -> {
  type: 'root',
  children: [
    {
      type: 'heading',
      depth: 1,
      children: [Array],
      position: [Object]
    },
    {
      type: 'code',
      lang: 'lang',
      meta: 'meta',
      props: 'properties',
      value: "\nlet s = 'hi'\nconsole.log(s)\n",
      position: [Object]
    }
  ],
  position: {
    start: { line: 1, column: 1, offset: 0 },
    end: { line: 6, column: 1, offset: 69 }
  }
}

# note: use ''' to beautify \`\`\`. 

markdown -> # Example

'''lang meta
let s = 'hi'
console.log(s)
'''{{properties}}

How does it works ?

How does it works?

注意事项

在Micromark(一个Markdown解析器)的上下文中,concrete: true 是一个标志位,用于告诉Micromark在处理某个节点时,这个节点是一个不可分割的实体(即“具体的”或“连续的”)。这意味着在处理该节点时,解析器不应该尝试在节点内部进行更多的语法规则匹配,而是将整个区块视为单一实体。

在factory函数中,concrete属性主要应用于那些在Markdown文本中具有明显边界且不应被进一步拆分的结构,比如代码块、HTML块、链接引用等。对于代码块(code fence)而言,concrete: true意味着一旦进入代码块,解析器将完整地对待整个代码块,直到遇到结束标记为止,期间不会试图解析代码块内部的Markdown语法。

简而言之,concrete: true有助于确保解析器正确地区分和处理文档中那些具有封闭边界的独立结构。