1
0
mirror of https://gitee.com/Doocs/md synced 2025-04-29 09:32:27 +08:00

chore: add .npmrc (#616)

close #613
This commit is contained in:
Libin YANG 2025-04-06 10:03:41 +08:00 committed by GitHub
parent d0931d819d
commit f9d07a2675
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 2330 additions and 603 deletions

View File

@ -10,12 +10,11 @@ jobs:
runs-on: ubuntu-latest
if: github.repository == 'doocs/md'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm run build:cli
- run: cd md-cli && npm ci && npm publish

1
.npmrc Normal file
View File

@ -0,0 +1 @@
registry=https://registry.npmmirror.com

View File

@ -117,6 +117,9 @@ util.axios
## 如何开发和部署
```sh
# 安装 node 版本
nvm i && nvm use
# 安装依赖
npm i

View File

@ -1,9 +1,9 @@
[build]
command = "npm run build:h5-netlify"
publish = "dist"
command = "npm run build:h5-netlify"
publish = "dist"
# 设置重定向规则确保SPA路由正常工作
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
from = "/*"
to = "/index.html"
status = 200

2854
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -85,7 +85,7 @@
"unocss": "^66.0.0",
"unplugin-auto-import": "^19.1.2",
"unplugin-vue-components": "^28.4.1",
"vite": "^6.2.4",
"vite": "^6.2.5",
"vite-plugin-node-polyfills": "^0.23.0",
"vite-plugin-radar": "^0.10.0",
"vite-plugin-vue-devtools": "^7.7.2",

View File

@ -1,6 +1,6 @@
import type { ThemeStyles } from '@/types'
import type { MarkedExtension, Tokens } from 'marked'
import { getStyleString } from '.'
import type { ThemeStyles } from '@/types'
/**
* A marked extension to support horizontal sliding images.
@ -10,17 +10,17 @@ export default function markedSlider(options: { styles?: ThemeStyles } = {}): Ma
return {
extensions: [
{
name: 'horizontalSlider',
level: 'block',
name: `horizontalSlider`,
level: `block`,
start(src: string) {
return src.match(/^<\!\[/)?.index
return src.match(/^<!\[/)?.index
},
tokenizer(src: string) {
const rule = /^<(\!\[.*?\]\(.*?\)(?:,\!\[.*?\]\(.*?\))*)>/
const rule = /^<(!\[.*?\]\(.*?\)(?:,!\[.*?\]\(.*?\))*)>/
const match = src.match(rule)
if (match) {
return {
type: 'horizontalSlider',
type: `horizontalSlider`,
raw: match[0],
text: match[1],
}
@ -29,27 +29,27 @@ export default function markedSlider(options: { styles?: ThemeStyles } = {}): Ma
},
renderer(token: Tokens.Generic) {
const { text } = token
const imageMatches = text.match(/\!\[(.*?)\]\((.*?)\)/g) || []
const imageMatches = text.match(/!\[(.*?)\]\((.*?)\)/g) || []
if (imageMatches.length === 0) {
return ''
return ``
}
const images = imageMatches.map((img: string) => {
const altMatch = img.match(/\!\[(.*?)\]/) || []
const altMatch = img.match(/!\[(.*?)\]/) || []
const srcMatch = img.match(/\]\((.*?)\)/) || []
const alt = altMatch[1] || ''
const src = srcMatch[1] || ''
const alt = altMatch[1] || ``
const src = srcMatch[1] || ``
const { styles } = options
const imgStyles = styles ? getStyleString(styles['image']) : ''
const imgStyles = styles ? getStyleString(styles.image) : ``
return { src, alt, imgStyles }
})
// 使用微信公众号兼容的滑动容器布局
// 使用微信支持的section标签和特殊样式组合
return `
<section style="box-sizing: border-box; font-size: 16px;">
<section data-role="outer" style="font-family: 微软雅黑; font-size: 16px;">
@ -58,10 +58,10 @@ export default function markedSlider(options: { styles?: ThemeStyles } = {}): Ma
<section style="display: inline-block; width: 100%;">
<!-- 微信公众号支持的滑动图片容器 -->
<section style="overflow-x: scroll; -webkit-overflow-scrolling: touch; white-space: nowrap; width: 100%; text-align: center;">
${images.map((img: { src: string; alt: string; imgStyles: string }, _index: number) => `<section style="display: inline-block; width: 100%; margin-right: 0; vertical-align: top;">
${images.map((img: { src: string, alt: string, imgStyles: string }, _index: number) => `<section style="display: inline-block; width: 100%; margin-right: 0; vertical-align: top;">
<img src="${img.src}" alt="${img.alt}" title="${img.alt}" style="${img.imgStyles}; width: 100%; height: auto; border-radius: 4px; vertical-align: top;"/>
<p style="margin-top: 5px; font-size: 14px; color: #666; text-align: center; white-space: normal;">${img.alt}</p>
</section>`).join('')}
</section>`).join(``)}
</section>
</section>
</section>
@ -70,8 +70,8 @@ export default function markedSlider(options: { styles?: ThemeStyles } = {}): Ma
<p style="font-size: 14px; color: #999; text-align: center; margin-top: 5px;"><<< >>></p>
</section>
`
}
}
]
},
},
],
}
}
}

View File

@ -12,8 +12,8 @@ import readingTime from 'reading-time'
import { getStyleString } from '.'
import markedAlert from './MDAlert'
import markedSlider from './MDSlider'
import { MDKatex } from './MDKatex'
import markedSlider from './MDSlider'
marked.setOptions({
breaks: true,
@ -180,10 +180,8 @@ export function initRenderer(opts: IOpts) {
if (oldStyle !== newStyle) {
marked.use(markedAlert({ styles: styleMapping }))
marked.use(
MDKatex({ nonStandard: true },
styles('inline_katex', `;vertical-align: middle; line-height: 1;`),
styles('block_katex', `;text-align: center; overflow: auto;`)
)
MDKatex({ nonStandard: true }, styles(`inline_katex`, `;vertical-align: middle; line-height: 1;`), styles(`block_katex`, `;text-align: center; overflow: auto;`),
),
)
}
}
@ -347,10 +345,8 @@ export function initRenderer(opts: IOpts) {
marked.use(markedSlider({ styles: styleMapping }))
marked.use(markedAlert({ styles: styleMapping }))
marked.use(
MDKatex({ nonStandard: true },
styles('inline_katex', `;vertical-align: middle; line-height: 1;`),
styles('block_katex', `;text-align: center; overflow: auto;`)
)
MDKatex({ nonStandard: true }, styles(`inline_katex`, `;vertical-align: middle; line-height: 1;`), styles(`block_katex`, `;text-align: center; overflow: auto;`),
),
)
return {