Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export {math} from './lib/syntax.js'
*/
export interface HtmlOptions extends KatexOptions {
/**
* The field `displayMode` cannot be passed to `micromark-extension-math`.
* The field `displayMode` cannot be passed to `micromark-extension-cfm-math`.
* It is overwritten by it,
* to `false` for math in text (inline) and `true` for math in flow (block).
*/
Expand Down
2 changes: 1 addition & 1 deletion dev/lib/html.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @import {HtmlOptions as Options} from 'micromark-extension-math'
* @import {HtmlOptions as Options} from 'micromark-extension-cfm-math'
* @import {HtmlExtension} from 'micromark-util-types'
*/

Expand Down
87 changes: 87 additions & 0 deletions dev/lib/math-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ function tokenizeMathFenced(effects, ok, nok) {
return metaAfter(code)
}

return effects.attempt(
{tokenize: tokenizeSingleLine, partial: true},
singleLineSuccess,
multiLineMetaStart
)(code)
}

/** @type {State} */
function singleLineSuccess(code) {
effects.exit('mathFlowFence')
return after(code)
}

/** @type {State} */
function multiLineMetaStart(code) {
effects.enter('mathFlowFenceMeta')
effects.enter(types.chunkString, {contentType: constants.contentTypeString})
return meta(code)
Expand Down Expand Up @@ -273,6 +288,78 @@ function tokenizeMathFenced(effects, ok, nok) {
return ok(code)
}

/** @type {Tokenizer} */
function tokenizeSingleLine(effects, ok, nok) {
// We are right after the opening fence, e.g., `$$`
// The first character `code` is part of the meta string.
effects.enter('mathFlowFenceMeta')
effects.enter(types.chunkString, {contentType: constants.contentTypeString})
return meta

/**
* In meta part of a single line math flow.
* @type {State}
*/
function meta(code) {
if (code === codes.eof || markdownLineEnding(code)) {
// No closing fence on the same line, so this isn't a single-line block.
return nok(code)
}

if (code === codes.dollarSign) {
// Potential closing fence.
effects.exit(types.chunkString)
effects.exit('mathFlowFenceMeta')
return close(code)
}

effects.consume(code)
return meta
}

/**
* At closing fence of a single line math flow.
* @type {State}
*/
function close(code) {
let size = 0
effects.enter('mathFlowFenceSequence')
return sequenceClose(code)

/**
* In closing fence sequence of a single line math flow.
* @type {State}
*/
function sequenceClose(code) {
if (code === codes.dollarSign) {
size++
effects.consume(code)
return sequenceClose
}

// For single line, we require the size to be exactly the same.
if (size !== sizeOpen) {
return nok(code)
}

effects.exit('mathFlowFenceSequence')
return factorySpace(effects, afterSequence, types.whitespace)(code)
}

/**
* After closing fence of a single line math flow.
* @type {State}
*/
function afterSequence(code) {
if (code === codes.eof || markdownLineEnding(code)) {
return ok(code)
}

return nok(code)
}
}
}

/** @type {Tokenizer} */
function tokenizeClosingFence(effects, ok, nok) {
let size = 0
Expand Down
2 changes: 1 addition & 1 deletion dev/lib/math-text.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @import {Options} from 'micromark-extension-math'
* @import {Options} from 'micromark-extension-cfm-math'
* @import {Construct, Previous, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types'
*/

Expand Down
2 changes: 1 addition & 1 deletion dev/lib/syntax.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @import {Options} from 'micromark-extension-math'
* @import {Options} from 'micromark-extension-cfm-math'
* @import {Extension} from 'micromark-util-types'
*/

Expand Down
19 changes: 6 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "micromark-extension-math",
"version": "3.1.0",
"description": "micromark extension to support math (`$C_L$`)",
"name": "micromark-extension-cfm-math",
"version": "3.1.1",
"description": "micromark extension to support math (`$C_L$`) for Cherry Studio Flavored Markdown (CFM), forked from micromark-extension-math.",
"license": "MIT",
"keywords": [
"micromark",
Expand All @@ -13,16 +13,9 @@
"markdown",
"unified"
],
"repository": "micromark/micromark-extension-math",
"bugs": "https://github.com/micromark/micromark-extension-math/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Titus Wormer <[email protected]> (https://wooorm.com)",
"contributors": [
"Titus Wormer <[email protected]> (https://wooorm.com)"
],
"repository": "alephpiece/micromark-extension-cfm-math",
"bugs": "https://github.com/alephpiece/micromark-extension-cfm-math/issues",
"author": "alephpiece <[email protected]> (https://github.com/alephpiece)",
"sideEffects": false,
"type": "module",
"exports": {
Expand Down
94 changes: 69 additions & 25 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# micromark-extension-math
# micromark-extension-cfm-math

[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]

[micromark][] extensions to support math (`$C_L$`).
Expand All @@ -15,6 +13,8 @@
* [What is this?](#what-is-this)
* [When to use this](#when-to-use-this)
* [Install](#install)
* [Replacing the official package](#replacing-the-official-package)
* [Standard Installation](#standard-installation)
* [Use](#use)
* [API](#api)
* [`math(options?)`](#mathoptions)
Expand Down Expand Up @@ -59,26 +59,76 @@ making it easier to transform content by abstracting these internals away.

## Install

### Replacing the official package

If you are using another tool (such as `remark-math`) that depends on the original `micromark-extension-math`, you will need to tell your build tool or package manager to use this package (`micromark-extension-cfm-math`) instead.

#### With Vite

In your `vite.config.js` (or `vite.config.ts`), you can use the `resolve.alias` option:

```js
import { defineConfig } from 'vite'

export default defineConfig({
// ...
resolve: {
alias: {
'micromark-extension-math': 'micromark-extension-cfm-math'
}
}
})
```

#### With Package Manager Overrides

A more robust method is to use the overrides feature of your package manager. This forces the dependency resolution to always use your preferred version, regardless of how deep it is in the dependency tree.

* **For npm (v8.3.0+):** add this to your `package.json`:
```json
"overrides": {
"micromark-extension-math": "npm:micromark-extension-cfm-math@^3"
}
```
* **For pnpm:** add this to your `package.json`:
```json
"pnpm": {
"overrides": {
"micromark-extension-math": "npm:micromark-extension-cfm-math@^3"
}
}
```
* **For Yarn (v1 Classic and v2+ Modern):** add this to your `package.json`:
```json
"resolutions": {
"micromark-extension-math": "npm:micromark-extension-cfm-math@^3"
}
```

After adding this, delete your `node_modules` directory and lock file (`package-lock.json`, `pnpm-lock.yaml`, or `yarn.lock`), and run install again.

### Standard Installation

This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:

[npm][]:

```sh
npm install micromark-extension-math
npm install micromark-extension-cfm-math
```

In Deno with [`esm.sh`][esmsh]:

```js
import {math, mathHtml} from 'https://esm.sh/micromark-extension-math@3'
import {math, mathHtml} from 'https://esm.sh/micromark-extension-cfm-math@3'
```

In browsers with [`esm.sh`][esmsh]:

```html
<script type="module">
import {math, mathHtml} from 'https://esm.sh/micromark-extension-math@3?bundle'
import {math, mathHtml} from 'https://esm.sh/micromark-extension-cfm-math@3?bundle'
</script>
```

Expand All @@ -99,7 +149,7 @@ $$
```js
import fs from 'node:fs/promises'
import {micromark} from 'micromark'
import {math, mathHtml} from 'micromark-extension-math'
import {math, mathHtml} from 'micromark-extension-cfm-math'

const output = micromark(await fs.readFile('example.md'), {
extensions: [math()],
Expand Down Expand Up @@ -323,7 +373,7 @@ versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`micromark-extension-math@^3`, compatible with Node.js 16.
`micromark-extension-cfm-math@^3`, compatible with Node.js 16.

This package works with `micromark` version `3` and later.

Expand Down Expand Up @@ -352,43 +402,37 @@ abide by its terms.

## License

[MIT][license] © [Titus Wormer][author]
[MIT][license] © [alephpiece][author]

<!-- Definitions -->

[build-badge]: https://github.com/micromark/micromark-extension-math/workflows/main/badge.svg

[build]: https://github.com/micromark/micromark-extension-math/actions

[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-math.svg

[coverage]: https://codecov.io/github/micromark/micromark-extension-math
[build-badge]: https://github.com/alephpiece/micromark-extension-cfm-math/workflows/main/badge.svg

[downloads-badge]: https://img.shields.io/npm/dm/micromark-extension-math.svg
[build]: https://github.com/alephpiece/micromark-extension-cfm-math/actions

[downloads]: https://www.npmjs.com/package/micromark-extension-math
[coverage-badge]: https://img.shields.io/codecov/c/github/alephpiece/micromark-extension-cfm-math.svg

[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-extension-math
[coverage]: https://codecov.io/github/alephpiece/micromark-extension-cfm-math

[size]: https://bundlejs.com/?q=micromark-extension-math
[downloads-badge]: https://img.shields.io/npm/dm/micromark-extension-cfm-math.svg

[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[downloads]: https://www.npmjs.com/package/micromark-extension-cfm-math

[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-extension-cfm-math

[collective]: https://opencollective.com/unified
[size]: https://bundlejs.com/?q=micromark-extension-cfm-math

[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg

[chat]: https://github.com/micromark/micromark/discussions
[chat]: https://github.com/alephpiece/micromark-extension-cfm-math/discussions

[npm]: https://docs.npmjs.com/cli/install

[esmsh]: https://esm.sh

[license]: license

[author]: https://wooorm.com
[author]: https://github.com/alephpiece

[contributing]: https://github.com/micromark/.github/blob/main/contributing.md

Expand Down
Loading
Loading