Skip to content

Commit

Permalink
fix transformChildren orders (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnecec authored Aug 1, 2023
1 parent 0cbc889 commit 1b23836
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 154 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-glasses-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'prettier-plugin-zh': patch
---

fix function orders in transformMarkdown
2 changes: 1 addition & 1 deletion apps/website/components/logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function Logo({ size = 81 }) {
<path
d="M362.5 400H203.137C146.13 399.954 99.9536 353.492 100 296.226V137.406M137.5 100.001L296.863 100C353.87 100.047 400.046 146.509 400 203.775V362.596"
stroke="currentColor"
stroke-width="40"
strokeWidth="40"
></path>
</svg>

Expand Down
2 changes: 1 addition & 1 deletion apps/website/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import nextra from 'nextra'

const withNextra = nextra({
defaultShowCopyCode: true,
theme: 'nextra-theme-docs',
themeConfig: './theme.config.tsx',
defaultShowCopyCode: true,
})

export default withNextra({
Expand Down
8 changes: 4 additions & 4 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
},
"devDependencies": {
"@types/node": "^20.4.5",
"@types/react": "^18.2.17",
"@types/react": "^18.2.18",
"@types/react-dom": "^18.2.7",
"autoprefixer": "^10.4.14",
"eslint-plugin-next": "",
"typescript": "^5.1.6",
"tailwindcss": "^3.3.3",
"postcss": "^8.4.27",
"autoprefixer": "^10.4.14"
"tailwindcss": "^3.3.3",
"typescript": "^5.1.6"
}
}
19 changes: 13 additions & 6 deletions apps/website/pages/index.mdx
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
---
type: posts
title: Introduction
---

import { Logo } from '~/components/logo'

<Logo size={120} />

**Zh** is a plugins collection designed to optimize Chinese text formatting.
**Zh** is designed to help formatting Chinese with ease.

## Rules

- spaceAroundAlphabet
- spaceAroundNumber
- noSpaceBetweenNumberUnit
- noSpaceAroundFullwidth
- noDuplicatePunctuation
- space-around-alphabet
- space-around-number
- no-space-between-number-unit
- no-space-around-fullwidth
- no-duplicate-punctuation

In the future, more options for format will be added.

Visit Rules part for more detail.

## Tools

- [prettier-plugin-zh](/prettier-plugin-zh)
Expand Down
32 changes: 30 additions & 2 deletions apps/website/theme.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,31 @@ import type { DocsThemeConfig } from 'nextra-theme-docs'
import { Logo } from './components/logo'

const config: DocsThemeConfig = {
chat: {
icon: (
<svg height={24} viewBox="0 0 24 24" width={24}>
<g>
<path
d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"
fill="currentColor"
></path>
</g>
</svg>
),
link: 'https://x.com/nnecec_cn',
},
docsRepositoryBase: 'https://github.com/nnecec/zh',
editLink: {
component: ({ children, filePath }) => (
<a
className="nx-text-xs nx-font-medium nx-text-gray-500 hover:nx-text-gray-900 dark:nx-text-gray-400 dark:hover:nx-text-gray-100 contrast-more:nx-text-gray-800 contrast-more:dark:nx-text-gray-50"
href={`https://github.com/nnecec/zh/tree/main/apps/website/${filePath}`}
rel="noopener noreferrer"
target="_blank"
>
{children}
</a>
),
text: 'Edit this page on GitHub →',
},
feedback: {
Expand Down Expand Up @@ -39,8 +63,8 @@ const config: DocsThemeConfig = {
<meta content="#fff" name="theme-color" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta content="en" httpEquiv="Content-Language" />
<meta content="Format standard of Chinese." name="description" />
<meta content="Format standard of Chinese." name="og:description" />
<meta content="Formatting Chinese with ease." name="description" />
<meta content="Formatting Chinese with ease." name="og:description" />
<meta content={title ? title + ' – Zh' : 'Zh'} name="og:title" />
<meta content="Zh" name="apple-mobile-web-app-title" />
<link href="/favicon.svg" rel="icon" type="image/svg+xml" />
Expand All @@ -49,6 +73,10 @@ const config: DocsThemeConfig = {
)
},
logo: <Logo size={36} />,
primaryHue: {
dark: 350,
light: 340,
},
project: {
link: 'https://github.com/nnecec/zh',
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@nnecec/eslint-config": "^0.5.1",
"@nnecec/prettier-config": "^0.3.0",
"@turbo/gen": "^1.10.12",
"eslint": "^8.45.0",
"eslint": "^8.46.0",
"prettier": "^3.0.0",
"prettier-plugin-zh": "workspace:*",
"turbo": "^1.10.12"
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-zh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"test": "echo \"Error: no test specified\" && exit 0"
},
"devDependencies": {
"eslint": "^8.45.0"
"eslint": "^8.46.0"
},
"peerDependencies": {
"eslint": ">=8.0.0"
Expand Down
10 changes: 6 additions & 4 deletions packages/prettier-plugin-zh/src/transforms/transform-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ export const transformMarkdown: Transform = (ast, options) => {
if (child.type === 'text') {
if (options.spaceAroundAlphabet === true) child.value = spaceAroundAlphabet(child.value)
if (options.spaceAroundNumber === true) child.value = spaceAroundNumber(child.value)

if (options.noDuplicatePunctuation === true) {
child.value = noDuplicatePunctuation(child.value)
}

if (options.noSpaceBetweenNumberUnit && options.noSpaceBetweenNumberUnit.length > 0) {
child.value = noSpaceBetweenNumberUnit(child.value, options.noSpaceBetweenNumberUnit)
}
if (options.noSpaceAroundFullwidth) {
if (options.noSpaceAroundFullwidth === true) {
child.value = noSpaceAroundFullwidth(child.value)
}
if (options.noDuplicatePunctuation === true) {
child.value = noDuplicatePunctuation(child.value)
}
}
})
}
8 changes: 3 additions & 5 deletions packages/prettier-plugin-zh/tests/fixtures/space-around.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# 标题 Title
# 标题Title

- 名称Name中国China面积960

ZH
[提交一個 issue](https://github.com/sparanoid/chinese-copywriting-guidelines) 並分配给相關同事。

- 名称Name美国American面积937

EN
訪問我們網站的最新動態,請[點擊這裡](https://www.x.com)進行訂閱!
Loading

0 comments on commit 1b23836

Please sign in to comment.