Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
init

BREAKING CHANGE: init
  • Loading branch information
revelt committed Sep 19, 2022
1 parent 26064b6 commit b8dbd5f
Show file tree
Hide file tree
Showing 14 changed files with 323 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/remark-typography/.all-contributorsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"projectName": "remark-typography",
"projectOwner": "codsen",
"files": ["README.md"],
"imageSize": 100,
"contributors": [
{
"login": "revelt",
"name": "Roy Revelt",
"avatar_url": "https://avatars.githubusercontent.com/u/8344688?v=4",
"profile": "https://github.com/revelt",
"contributions": ["code", "test", "doc", "review"]
}
]
}
12 changes: 12 additions & 0 deletions packages/remark-typography/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# folders:
.turbo
coverage
src
test

# files:
.all-contributorsrc
.npmignore
.prettierignore
rollup.config.js
tsconfig.json
1 change: 1 addition & 0 deletions packages/remark-typography/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
4 changes: 4 additions & 0 deletions packages/remark-typography/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
test/fixtures
fixtures/
*.json
4 changes: 4 additions & 0 deletions packages/remark-typography/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
22 changes: 22 additions & 0 deletions packages/remark-typography/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2010-2022 Roy Revelt and other contributors

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67 changes: 67 additions & 0 deletions packages/remark-typography/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# remark-typography

> All-in-one English typography plugin for markdown
<div class="package-badges">
<a href="https://www.npmjs.com/package/remark-typography" rel="nofollow noreferrer noopener">
<img src="https://img.shields.io/badge/-npm-blue?style=flat-square" alt="page on npm">
</a>
<a href="https://codsen.com/os/remark-typography" rel="nofollow noreferrer noopener">
<img src="https://img.shields.io/badge/-codsen-blue?style=flat-square" alt="page on codsen.com">
</a>
<a href="https://github.com/codsen/codsen/tree/main/packages/remark-typography" rel="nofollow noreferrer noopener">
<img src="https://img.shields.io/badge/-github-blue?style=flat-square" alt="page on github">
</a>
<a href="https://npmcharts.com/compare/remark-typography?interval=30" rel="nofollow noreferrer noopener" target="_blank">
<img src="https://img.shields.io/npm/dm/remark-typography.svg?style=flat-square" alt="Downloads per month">
</a>
<a href="https://prettier.io" rel="nofollow noreferrer noopener" target="_blank">
<img src="https://img.shields.io/badge/code_style-prettier-brightgreen.svg?style=flat-square" alt="Code style: prettier">
</a>
<img src="https://img.shields.io/badge/licence-MIT-brightgreen.svg?style=flat-square" alt="MIT License">
<a href="https://liberamanifesto.com" rel="nofollow noreferrer noopener" target="_blank">
<img src="https://img.shields.io/badge/libera-manifesto-lightgrey.svg?style=flat-square" alt="libera manifesto">
</a>
</div>

## Install

This package is [pure ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).

```bash
npm i remark-typography
```

## Quick Take

```js
import { strict as assert } from "assert";
import { remark } from "remark";

import fixTypography from "remark-typography";

(async () => {
assert.equal(
(await remark().use(fixTypography, {}).process("Yes that's true but..."))
.toString()
.trim(),
`Yes that\u2019s true but\u2026`
);
})();
```

## Documentation

Please [visit codsen.com](https://codsen.com/os/remark-typography/) for a full description of the API.

## Contributing

To report bugs or request features or assistance, [raise an issue](https://github.com/codsen/codsen/issues/new/choose) on GitHub.

## Licence

MIT License

Copyright (c) 2010-2022 Roy Revelt and other contributors

<img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center">
15 changes: 15 additions & 0 deletions packages/remark-typography/examples/_quickTake.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Quick Take

import { strict as assert } from "assert";
import { remark } from "remark";

import fixTypography from "../dist/remark-typography.esm.js";

(async () => {
assert.equal(
(await remark().use(fixTypography, {}).process("Yes that's true but..."))
.toString()
.trim(),
`Yes that\u2019s true but\u2026`
);
})();
80 changes: 80 additions & 0 deletions packages/remark-typography/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"name": "remark-typography",
"version": "0.0.1",
"description": "All-in-one English typography plugin for markdown",
"keywords": [
"unified",
"remark",
"remark-plugin",
"plugin",
"mdast",
"markdown",
"text",
"typography",
"typographic",
"typesetting",
"english"
],
"homepage": "https://codsen.com/os/remark-typography",
"repository": {
"type": "git",
"url": "https://github.com/codsen/codsen.git",
"directory": "packages/remark-typography"
},
"license": "MIT",
"author": {
"name": "Roy Revelt",
"email": "roy@codsen.com",
"url": "https://codsen.com"
},
"type": "module",
"exports": {
"types": "./types/index.d.ts",
"default": "./dist/remark-typography.esm.js"
},
"types": "types/index.d.ts",
"scripts": {
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
"devtest": "c8 yarn run unit && yarn run examples && yarn run lint",
"dts": "rollup -c && yarn run prettier 'types/index.d.ts' --write",
"examples": "node '../../ops/scripts/run-examples.js'",
"lect": "node '../../ops/lect/lect.js' && yarn run prettier 'README.md' '.all-contributorsrc' 'rollup.config.js' --write",
"letspublish": "yarn publish || :",
"lint": "eslint . --fix",
"perf": "echo 'skip perf'",
"prepare": "echo 'ready'",
"prettier": "prettier",
"prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
"pretest": "yarn run lect && yarn run build",
"test": "yarn run devtest",
"unit": "uvu test"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"c8": {
"check-coverage": true,
"exclude": [
"**/test/**/*.*"
],
"lines": 100
},
"lect": {
"licence": {
"extras": [
""
]
},
"various": {}
},
"dependencies": {
"string-apostrophes": "^3.1.2",
"unist-util-visit": "^4.1.1"
},
"devDependencies": {
"@types/hast": "^2.3.4",
"remark": "^14.0.2",
"unified": "^10.1.2"
}
}
19 changes: 19 additions & 0 deletions packages/remark-typography/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json from "@rollup/plugin-json";
import dts from "rollup-plugin-dts";

export default () => [
// Type definitions
{
input: "src/main.ts",
output: [{ file: "types/index.d.ts", format: "es" }],
plugins: [
json(),
dts({
compilerOptions: {
composite: false,
incremental: false,
},
}),
],
},
];
23 changes: 23 additions & 0 deletions packages/remark-typography/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { visit } from "unist-util-visit";
import type { Plugin } from "unified";
import type { Root } from "hast";
import { convertAll } from "string-apostrophes";

type UnifiedPlugin<T> = Plugin<[T], Root>;
// declare let DEV: boolean;

const fixTypography: UnifiedPlugin<any[]> = () => {
let ellipsis = "\u2026";
let mDash = "\u2014";
//
return async (tree) => {
visit(tree, "text", (node) => {
node.value = convertAll(node.value)
.result.replace(/([^.])\.\.\.$/, `$1${ellipsis}`)
.replace(/([^.])\.\.\.([^.])/g, `$1${ellipsis}$2`)
.replace(/ - /g, ` ${mDash} `);
});
};
};

export default fixTypography;
38 changes: 38 additions & 0 deletions packages/remark-typography/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { test } from "uvu";
// eslint-disable-next-line no-unused-vars
import { equal, is, ok, throws, type, not, match } from "uvu/assert";
import { remark } from "remark";

import fixTypography from "../dist/remark-typography.esm.js";

// const leftSingleQuote = "\u2018";
const ellipsis = "\u2026";
const rightSingleQuote = "\u2019";
// const leftDoubleQuote = "\u201C";
// const rightDoubleQuote = "\u201D";
// const singlePrime = "\u2032";
// const doublePrime = "\u2033";
// const nDash = "\u2013";
const mDash = "\u2014";

// -----------------------------------------------------------------------------

test(`01 - apostrophes and ellipsis`, async () => {
equal(
(await remark().use(fixTypography, {}).process("Yes that's true but..."))
.toString()
.trim(),
`Yes that${rightSingleQuote}s true but${ellipsis}`
);
});

test(`02 - m-dashes`, async () => {
equal(
(await remark().use(fixTypography, {}).process("Some text - more text."))
.toString()
.trim(),
`Some text ${mDash} more text.`
);
});

test.run();
16 changes: 16 additions & 0 deletions packages/remark-typography/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist"
},
"include": [
"src/**/*",
"package.json",
"../../ops/typedefs/common.ts"
],
"exclude": [
".git",
"node_modules"
],
"references": []
}
7 changes: 7 additions & 0 deletions packages/remark-typography/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Plugin } from "unified";
import { Root } from "hast";

declare type UnifiedPlugin<T> = Plugin<[T], Root>;
declare const fixTypography: UnifiedPlugin<any[]>;

export { fixTypography as default };

0 comments on commit b8dbd5f

Please sign in to comment.