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

markdown-it-wrap-alphabet

v1.3.0

Published

Wrap alphabets between CJK for markdown-it markdown parser.

Downloads

2

Readme

markdown-it-wrap-alphabet

Wrap alphabets between CJK for markdown-it markdown parser.

Markdown:

精神分析中的「享乐」这一概念常常使用法语的 *jouissance* 一词。

HTML:

<p>精神分析中的「享乐」这一概念常常使用法语的<span class='before after'><em>jouissance</em></span>一词。</p>

Then you can add CSS in your website to add space between alphabets and CJK glyphs, for instance:

.before::before {
  content: '\2006';
}
.after::after {
  content: '\2006';
}

(U+2006 refers to the white space that is one sixth of an em wide. For a detailed list of all white spaces avaible, see Whitespace character - Wiki.)

Note:

  1. This plugin will automatically remove the space between alphabets and CJK glyphs.
  2. Space won't be added between alphabets and punctuations. For example, 自由是一个 regulative ideal。 will be rendered as <p>自由是一个<span class='before'>regulative ideal</span>。</p>, omitting the after class.

Install

Node.JS:

npm i markdown-it-wrap-english

Use

const md = require('markdown-it')()
const wrap = require('markdown-it-wrap-alphabet')

md.use(wrap)

Configuration

You can pass an object to customize its output. All are optional.

const md = require('markdown-it')()
const wrap = require('markdown-it-wrap-alphabet')

md.use(wrap, {
  before: 'space-before', // default: 'before'
  after:  'space-after',  // default: 'after'
  lang:   'en'            // default: ''
                          // Add lang attribute to span
  wrapAll: true           // default: false
  shouldWrap: state => {  // default: always return true
    if (...) return true
    return false
  }
})

Generally speaking, you don't need to customize wrapAll and shouldWrap options. Here are their explanations:

wrapAll: By default, this plugin skips paragraphs without CJK glyphs. However, in the case that you use the language attribute to apply different styles (i.e., you set different font sizes depending on languages), you may want to wrap all alphabets even when there is no CJK glyphs in a certain paragraph.

shouldWrap: Normally this plugin leaves alone all paragraphs without CJK glyphs, not to mention a post without CJK glyphs at all. However, there is a possible edge case in which you have some CJK glyphs in a post written in, say, English. In that case, it is preferable to wrap manually that part of CJK glyphs instead of letting the plugin wrap all the English. Here is where the necessity of having a filter function to only implement this plugin to a certain set of posts comes in.

The argument of shouldWrap is the state property of parser_block. (See state's source code here) That being said, what we need is more likely to depend on the environment markdown-it is utilized in. For instance, if you use Eleventy as your SSG (static site generator) and have lang attribute in the frontmatter of every posts, you can pass a function as follows to skip all posts that are marked as English.

state => {
  const lang = state.env && state.env.lang
  if (lang !== undefined && lang === 'en') return false
  else return true
}

License

MIT