diff --git a/.c8rc.json b/.c8rc.json new file mode 100644 index 0000000..142038d --- /dev/null +++ b/.c8rc.json @@ -0,0 +1,19 @@ +{ + "all": true, + "check-coverage": false, + "include": [ + "lib/src", + "src" + ], + "exclude": [ + "node_modules", + "**/*.d.ts" + ], + "sourceMap": true, + "extension": [ + ".ts", + ".js", + ".jsx", + ".tsx" + ] +} diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md index 6cffa59..366557c 100644 --- a/.github/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md @@ -1,46 +1,133 @@ + # Contributor Covenant Code of Conduct ## Our Pledge -In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. ## Our Standards -Examples of behavior that contributes to creating a positive environment include: +Examples of behavior that contributes to a positive environment for our +community include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community -Examples of unacceptable behavior by participants include: +Examples of unacceptable behavior include: -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting -## Our Responsibilities +## Enforcement Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. ## Scope -This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at val.istar.guo@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[INSERT CONTACT METHOD]. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning -Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available +at [https://www.contributor-covenant.org/translations][translations]. -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ +[homepage]: https://www.contributor-covenant.org +[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 887c799..ff74d93 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -17,10 +17,3 @@ Please note we have a [code of conduct](https://github.com/Val-istar-Guo/rehype- * Complete testing of the modified code * Each commit message must follows the [Conventional Commits Specification](https://conventionalcommits.org/). This will be used for automatic generation of changelog. * No need to bump the version number, there will be someone responsible for the release. - - -# Coding style - -* Use two Spaces for indenting -* No semicolons -* Use utf8 encoding diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index edf85e4..1bda37b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,6 +1,8 @@ --- name: Bug report about: Create a report to help us improve +title: 'Bug: ' +labels: bug --- @@ -19,10 +21,9 @@ Steps to reproduce the behavior: A clear and concise description of what you expected to happen. **Platform (please complete the following information):** - - Device: [e.g. Mac, Windows, iPhone6] - - OS: [e.g. iOS8.2] - - Environment: [e.g. nodejs, chrome, safari] - - Version [e.g. 6.1.2] + +- Environment: NodeJS + + Version: **Additional context** Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/docs_improve.md b/.github/ISSUE_TEMPLATE/docs_improve.md index 7c0ecf4..687f1aa 100644 --- a/.github/ISSUE_TEMPLATE/docs_improve.md +++ b/.github/ISSUE_TEMPLATE/docs_improve.md @@ -1,7 +1,8 @@ --- name: Document improve about: Improve document quality or improve document content - +title: 'Document: ' +labels: documentation --- diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index abed773..6416b55 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,6 +1,8 @@ --- name: Feature request about: Suggest an idea for this project +title: 'Feature: ' +labels: enhancement --- diff --git a/.milirc.yml b/.milirc.yml index 7be68d1..ed3e794 100644 --- a/.milirc.yml +++ b/.milirc.yml @@ -1,5 +1,5 @@ template: npm:@mtpl/component -version: 4.1.4 +version: 4.5.3 answers: travis: true lock: false diff --git a/.nycrc.yml b/.nycrc.yml deleted file mode 100644 index bef4181..0000000 --- a/.nycrc.yml +++ /dev/null @@ -1,19 +0,0 @@ -all: true -check-coverage: false -include: - - lib/src - - src -exclude: - - node_modules - - "**/*.d.ts" -sourceMap: true -extension: - - .ts - - .js - - .jsx - - .tsx - -branches: 60 -lines: 80 -functions: 80 -statements: 80 diff --git a/.travis.yml b/.travis.yml index 85e5be6..abb3a5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,4 @@ node_js: - lts/* after_success: - npm run coveralls +dist: focal diff --git a/README.md b/README.md index b63252a..17b70e4 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,9 @@ [![version](https://img.shields.io/npm/v/rehype-prism.svg?style=flat-square)](https://www.npmjs.com/package/rehype-prism) [![downloads](https://img.shields.io/npm/dm/rehype-prism.svg?style=flat-square)](https://www.npmjs.com/package/rehype-prism) [![license](https://img.shields.io/npm/l/rehype-prism.svg?style=flat-square)](https://www.npmjs.com/package/rehype-prism) -[![dependencies](https://img.shields.io/librariesio/release/npm/rehype-prism?style=flat-square)](https://www.npmjs.com/package/rehype-prism) +[![dependencies](https://img.shields.io/librariesio/github/Val-istar-Guo/rehype-prism.svg?style=flat-square)](https://www.npmjs.com/package/rehype-prism) [![coveralls](https://img.shields.io/coveralls/github/Val-istar-Guo/rehype-prism.svg?style=flat-square)](https://coveralls.io/github/Val-istar-Guo/rehype-prism) - - The unified plugin used to highlight code block in html with Prism. @@ -23,7 +21,6 @@ The unified plugin used to highlight code block in html with Prism. This package is ESM only: Node 12+ and [unified 10](https://www.npmjs.com/package/unified) is needed to use it and it must be imported instead of required. - ```typescript import { unified } from 'unified' import rehype from 'rehype' @@ -44,12 +41,14 @@ unified() .use(rehypePrism, { plugins: ['line-numbers'] }) .use(rehypeStringify) .parse(/* markstring string */) + // .processSync(/* markdown string */) // parse code block in html string rehype() .use(rehypePrism) .use(rehypeStringify) .parse(/* html string */) + // .processSync(/* html string */) ``` ## Server Side Render @@ -63,7 +62,7 @@ rehype() `` -> Some plugins will not work(e.g. `line-number`). Because it's only work in browser. +> Some plugins will not work. Because it's only work in browser. ## Load Plugins @@ -86,7 +85,6 @@ The names to use can be found [here](https://github.com/PrismJS/prism/tree/maste If in doubt, please submit an issue. - ## Contributing & Development If there is any doubt, it is very welcome to discuss the issue together. diff --git a/ava.config.js b/ava.config.js index 3b32915..537db5e 100644 --- a/ava.config.js +++ b/ava.config.js @@ -1,6 +1,5 @@ export default { files: ['tests/**/*.ts', '!tests/**/*.before-each.ts'], - // extensions: { ts: 'module' }, typescript: { rewritePaths: { 'tests/': 'lib/tests/', diff --git a/build/tsconfig.test.json b/build/tsconfig.test.json index 00c9f3e..2a8549f 100644 --- a/build/tsconfig.test.json +++ b/build/tsconfig.test.json @@ -9,4 +9,3 @@ "../tests/**/*.ts" ], } - diff --git a/index.ts b/index.ts deleted file mode 100644 index c7ee744..0000000 --- a/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './src/index.js' -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -/** @ts-ignore */ -import defaultExport from './src/index.js' -export default defaultExport diff --git a/package.json b/package.json index f464e5e..35b5e34 100644 --- a/package.json +++ b/package.json @@ -4,25 +4,26 @@ "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "scripts": { - "test": "npm run build:test && c8 ava", - "test:debug": "ava --verbose", - "test:update": "ava -u", - "report": "npm run build:test && c8 --reporter=html --reporter=text-summary --skip-full ava", - "coveralls": "c8 report --reporter=text-lcov | coveralls", - "ci": "git-cz", + "lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" --fix", + "prepare": "is-ci || husky install", "ca": "git add -A && git-cz -av", + "ci": "git-cz", "release": "standard-version", "release:alpha": "standard-version --prerelease alpha", "release:first": "standard-version --first-release", + "test": "npm run clean && npm run build:test && c8 ava", + "test:debug": "ava --verbose", + "test:update": "ava -u", + "report": "npm run build:test && c8 --reporter=html --reporter=text-summary --skip-full ava", + "coveralls": "c8 report --reporter=text-lcov | coveralls", "prepublishOnly": "npm run build", - "clean": "rm -rf ./lib/*", + "clean": "rm -rf ./lib/* && rm -rf ./es/*", + "prebuild": "npm run clean", + "build": "ttsc && npm run copyfile", + "build:test": "ttsc -p build/tsconfig.test.json && npm run copyfile", "copyfile": "copyfiles -u 1 \"src/**/*.!(ts)\" lib/src", - "build": "npm run clean && ttsc && npm run copyfile", - "build:test": "npm run clean && ttsc -p build/tsconfig.test.json && npm run copyfile", "prewatch": "npm run copyfile", - "watch": "NODE_ENV=development ttsc -w", - "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" --fix", - "prepare": "is-ci || husky install" + "watch": "NODE_ENV=development ttsc -w" }, "description": "The unified plugin used to highlight code block in html with Prism", "version": "2.1.3", @@ -57,30 +58,30 @@ "devDependencies": { "@ava/babel": "^2.0.0", "@ava/typescript": "^3.0.1", - "@commitlint/cli": "^17.0.2", - "@commitlint/config-conventional": "^17.0.2", + "@commitlint/cli": "^12.1.4", + "@commitlint/config-conventional": "^12.1.4", "@typescript-eslint/eslint-plugin": "^4.15.2", "@typescript-eslint/parser": "^4.15.2", "ajv": "8", "ava": "^4.3.0", - "c8": "^7.11.3", + "c8": "^7.12.0", "commitizen": "^4.2.4", "copyfiles": "^2.4.1", "coveralls": "^3.1.0", "cz-conventional-changelog": "^3.3.0", "eslint": "^7.20.0", - "husky": "7", + "husky": "^5.2.0", "is-ci": "^3.0.0", - "lint-staged": "^13.0.2", - "mili": "^4.7.4", + "lint-staged": "^11.0.0", + "mili": "^4.7.5", "rehype-stringify": "^8.0.0", "remark-parse": "^9.0.0", "remark-rehype": "^8.1.0", "sinon": "^14.0.0", "standard-version": "^9.3.0", "ts-node": "^10.8.1", - "ttypescript": "^1.5.12", - "typescript": "^4.2.2", + "ttypescript": "^1.5.13", + "typescript": "^4.7.4", "typescript-transform-paths": "^3.3.1", "unified": "^10.1.2" }, diff --git a/src/index.ts b/src/index.ts index 6dcc02c..9c2fa56 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,10 +2,10 @@ import 'prismjs' import unifiedTypes from 'unified' import { Element } from 'hast' import { visit } from 'unist-util-visit' -import { preElementSelector } from './pre-element-selector' -import { RehypePrismOptions } from './rehype-prism-options' -import { parseCodeVisitor } from './parse-code-vistor' import { Test } from 'unist-util-is' +import { preElementSelector } from './pre-element-selector.js' +import { RehypePrismOptions } from './rehype-prism-options.js' +import { parseCodeVisitor } from './parse-code-vistor.js' const rehypePrism: unifiedTypes.Plugin<[RehypePrismOptions?], Element> = (options?: RehypePrismOptions) => { diff --git a/src/parse-code-vistor.ts b/src/parse-code-vistor.ts index 0023f78..e2fa984 100644 --- a/src/parse-code-vistor.ts +++ b/src/parse-code-vistor.ts @@ -6,11 +6,11 @@ import { Visitor } from 'unist-util-visit/complex-types' import { unified } from 'unified' import { h } from 'hastscript' import { select } from 'unist-util-select' -import { getLang } from './get-lang' -import { Checker } from './checker' -import { appendClassName } from './append-class-name' -import { getLineNumber } from './get-line-number' -import { RehypePrismOptions } from './rehype-prism-options' +import { getLang } from './get-lang.js' +import { Checker } from './checker.js' +import { appendClassName } from './append-class-name.js' +import { getLineNumber } from './get-line-number.js' +import { RehypePrismOptions } from './rehype-prism-options.js' const parser = unified() diff --git a/src/pre-element-selector.ts b/src/pre-element-selector.ts index 7f51c03..172c6f1 100644 --- a/src/pre-element-selector.ts +++ b/src/pre-element-selector.ts @@ -1,5 +1,5 @@ import { Test } from 'unist-util-is' -import { Checker } from './checker' +import { Checker } from './checker.js' export function preElementSelector(): Test { diff --git a/tests/tsconfig.json b/tests/tsconfig.json index 5197ce2..b10524d 100644 --- a/tests/tsconfig.json +++ b/tests/tsconfig.json @@ -1,4 +1,8 @@ { "extends": "../tsconfig.json", - "include": ["./**/*.ts"] + "include": ["./**/*.ts"], + "compilerOptions": { + "sourceRoot": "../src", + "sourceMap": true, + } } diff --git a/tsconfig.json b/tsconfig.json index a73fdf0..032b19b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -35,5 +35,8 @@ ], "include": [ "src/**/*.ts" - ] + ], + "ts-node": { + "compiler": "ttypescript" + } }