Skip to content

Commit

Permalink
fix(cli,markdown-loader): markdown-loader add style option, linter ig…
Browse files Browse the repository at this point in the history
…nore generators

affects: @varlet/cli, @varlet/markdown-loader
  • Loading branch information
haoziqaq committed Sep 9, 2021
1 parent 9b3e3bb commit 7ca8844
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 101 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
packages/varlet-cli/lib/**
packages/varlet-cli/site/**
packages/varlet-cli/site/**

packages/varlet-icons/dist/**

Expand All @@ -9,3 +10,4 @@ packages/varlet-ui/umd/**
packages/varlet-ui/site/**
packages/varlet-ui/src/*/__tests__/**
*.md

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"ignorePatterns": [
"packages/varlet-cli/lib/**",
"packages/varlet-cli/site/**",
"packages/varlet-cli/generators/**",
"packages/varlet-ui/es/**",
"packages/varlet-ui/umd/**",
"packages/varlet-ui/site/**",
Expand All @@ -48,6 +49,8 @@
],
"ignoreFiles": [
"packages/varlet-cli/lib/**",
"packages/varlet-cli/site/**",
"packages/varlet-cli/generators/**",
"packages/varlet-icons/dist/**",
"packages/varlet-ui/es/**",
"packages/varlet-ui/umd/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"vue": "^3.0.0"
},
"devDependencies": {
"@varlet/cli": "^[email protected]",
"@vue/compiler-sfc": "3.1.4",
"@varlet/cli": "^[email protected]",
"vue": "3.1.4"
},
"dependencies": {
Expand Down
113 changes: 23 additions & 90 deletions packages/varlet-cli/generators/ts-sfc-varlet-cli-app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
chalk "^2.0.0"
js-tokens "^4.0.0"

"@babel/parser@^7.1.0", "@babel/parser@^7.12.0", "@babel/parser@^7.13.9", "@babel/parser@^7.15.0", "@babel/parser@^7.15.4", "@babel/parser@^7.15.5":
"@babel/parser@^7.1.0", "@babel/parser@^7.12.0", "@babel/parser@^7.13.9", "@babel/parser@^7.15.4", "@babel/parser@^7.15.5":
version "7.15.5"
resolved "https://registry.nlark.com/@babel/parser/download/@babel/parser-7.15.5.tgz#d33a58ca69facc05b26adfe4abebfed56c1c2dac"
integrity sha1-0zpYymn6zAWyat/kq+v+1WwcLaw=
Expand Down Expand Up @@ -913,7 +913,7 @@
debug "^4.1.0"
globals "^11.1.0"

"@babel/types@^7.0.0", "@babel/types@^7.12.0", "@babel/types@^7.13.0", "@babel/types@^7.15.0", "@babel/types@^7.15.4", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4":
"@babel/types@^7.0.0", "@babel/types@^7.12.0", "@babel/types@^7.13.0", "@babel/types@^7.15.4", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4":
version "7.15.4"
resolved "https://registry.nlark.com/@babel/types/download/@babel/types-7.15.4.tgz#74eeb86dbd6748d2741396557b9860e57fce0a0d"
integrity sha1-dO64bb1nSNJ0E5ZVe5hg5X/OCg0=
Expand Down Expand Up @@ -1599,21 +1599,21 @@
dependencies:
"@types/yargs-parser" "*"

"@varlet/cli@^1.16.3@alpha.9":
version "1.16.3-alpha.9"
resolved "https://registry.npmjs.org/@varlet/cli/-/cli-1.16.3-alpha.9.tgz#7226f9496de98841b3daaa321727dc068a075bd7"
integrity sha512-x2L5kjZBSPAib/n6Tgh457gU1CcsjC0ne9HSyRbZpwcrd7SvCxvBbDZ6/xrnmviNAlGRIHoztYtgIEB0lX72mw==
"@varlet/cli@^1.16.3@alpha.10":
version "1.16.3-alpha.10"
resolved "https://registry.npmjs.org/@varlet/cli/-/cli-1.16.3-alpha.10.tgz#7b9e050dcdfee8f289c3546a7e52cc50b8beae9d"
integrity sha512-lB1tTx+g7vTUw6ABfuD6EhNsJK1Nubeo9KmiG3uYV/i7dYUQO5hNPDWR3FcKeW7mFTDwjrDTorK6s68F0Xu2ZQ==
dependencies:
"@babel/core" "^7.14.8"
"@babel/preset-env" "^7.14.8"
"@babel/preset-typescript" "^7.14.5"
"@commitlint/cli" "^11.0.0"
"@commitlint/config-conventional" "^11.0.0"
"@varlet/markdown-loader" "^1.16.1"
"@varlet/markdown-loader" "^1.16.3-alpha.10+9b3e3bb"
"@varlet/touch-emulator" "^1.0.1"
"@varlet/ui" "^1.16.3-alpha.9+703517e"
"@varlet/ui" "^1.16.3-alpha.10+9b3e3bb"
"@vue/babel-plugin-jsx" "^1.0.6"
"@vue/compiler-sfc" "^3.1.4"
"@vue/compiler-sfc" "3.1.4"
"@vue/test-utils" "^2.0.0-rc.6"
address "^1.1.2"
autoprefixer "9"
Expand Down Expand Up @@ -1667,23 +1667,23 @@
fs-extra "^9.0.1"
webfont "^9.0.0"

"@varlet/markdown-loader@^1.16.1":
version "1.16.1"
resolved "https://registry.npmjs.org/@varlet/markdown-loader/-/markdown-loader-1.16.1.tgz#28fdb872e3ed782c4c4fd3b04f8e4c91c2d4b30f"
integrity sha512-myvHQfDluJHNa0TEFGHDcLpk0mzoh+vUr+L4WKyukv0REufmwAMu4xO2HIfOLdt4UsOPTc7g0SfXTJR7WI3PuQ==
"@varlet/markdown-loader@^1.16.3-alpha.10+9b3e3bb":
version "1.16.3-alpha.10"
resolved "https://registry.npmjs.org/@varlet/markdown-loader/-/markdown-loader-1.16.3-alpha.10.tgz#387b9c659e4d0610f18428939a2c102ef71f04a6"
integrity sha512-erfN8H8G42FfL449QNeqHJKDPR48FmvbEtvNkdSP+3ANnGf784LLMAXdWGbUyS7kuFS0bQXPzcc2F8tyo407/A==
dependencies:
highlight.js "^10.3.2"
highlight.js "10.3.2"
markdown-it "^12.0.2"

"@varlet/touch-emulator@^1.0.1":
version "1.0.1"
resolved "https://registry.nlark.com/@varlet/touch-emulator/download/@varlet/touch-emulator-1.0.1.tgz#3c2fb609561ecc089be6bf748ae42610cfca8a18"
integrity sha1-PC+2CVYezAib5r90iuQmEM/Kihg=

"@varlet/ui@^1.16.3-alpha.9+703517e":
version "1.16.3-alpha.9"
resolved "https://registry.npmjs.org/@varlet/ui/-/ui-1.16.3-alpha.9.tgz#d9a07777afd5d858e8b8696d2a84ce8388d0953c"
integrity sha512-ARRGHe0iPyu1WV0ptoe31rLBUL2q6A267oNYVqBzbWrivfw4eNQ68Ff0N2R2JaTKJhJ9ZWORMw9vrUEp9OM6NA==
"@varlet/ui@^1.16.3-alpha.10+9b3e3bb":
version "1.16.3-alpha.10"
resolved "https://registry.npmjs.org/@varlet/ui/-/ui-1.16.3-alpha.10.tgz#0a4bdb91cfc610bcb7cbe8c0e382a82adf9d3592"
integrity sha512-Kt+60/J5l/3Co5QbDKzh9a3mghoYZjvs60G4ctO2qms90iUVZIZDKy92kMBCB9szhhYjM5+MlKgTu4LzK1J6Wg==
dependencies:
"@varlet/icons" "^1.0.0"
dayjs "^1.10.4"
Expand Down Expand Up @@ -1720,17 +1720,6 @@
estree-walker "^2.0.1"
source-map "^0.6.1"

"@vue/[email protected]":
version "3.2.11"
resolved "https://registry.nlark.com/@vue/compiler-core/download/@vue/compiler-core-3.2.11.tgz#10af3777dba303ee7aae668029f131cb90391bee"
integrity sha1-EK83d9ujA+56rmaAKfExy5A5G+4=
dependencies:
"@babel/parser" "^7.15.0"
"@babel/types" "^7.15.0"
"@vue/shared" "3.2.11"
estree-walker "^2.0.2"
source-map "^0.6.1"

"@vue/[email protected]":
version "3.1.4"
resolved "https://registry.npmjs.org/@vue/compiler-dom/-/compiler-dom-3.1.4.tgz#bf3795e1449f32c965d38c4ea6d808ca05fdfc97"
Expand All @@ -1739,14 +1728,6 @@
"@vue/compiler-core" "3.1.4"
"@vue/shared" "3.1.4"

"@vue/[email protected]":
version "3.2.11"
resolved "https://registry.nlark.com/@vue/compiler-dom/download/@vue/compiler-dom-3.2.11.tgz#d066f8e1f1812b4e881593819ade0fe6d654c776"
integrity sha1-0Gb44fGBK06IFZOBmt4P5tZUx3Y=
dependencies:
"@vue/compiler-core" "3.2.11"
"@vue/shared" "3.2.11"

"@vue/[email protected]":
version "3.1.4"
resolved "https://registry.npmjs.org/@vue/compiler-sfc/-/compiler-sfc-3.1.4.tgz#93e87db950e0711339c18baa7bb7d28d3522d7bc"
Expand All @@ -1770,30 +1751,6 @@
postcss-selector-parser "^6.0.4"
source-map "^0.6.1"

"@vue/compiler-sfc@^3.1.4":
version "3.2.11"
resolved "https://registry.nlark.com/@vue/compiler-sfc/download/@vue/compiler-sfc-3.2.11.tgz#628fa12238760d9b9b339ac2e125a759224fadbf"
integrity sha1-Yo+hIjh2DZubM5rC4SWnWSJPrb8=
dependencies:
"@babel/parser" "^7.15.0"
"@babel/types" "^7.15.0"
"@types/estree" "^0.0.48"
"@vue/compiler-core" "3.2.11"
"@vue/compiler-dom" "3.2.11"
"@vue/compiler-ssr" "3.2.11"
"@vue/ref-transform" "3.2.11"
"@vue/shared" "3.2.11"
consolidate "^0.16.0"
estree-walker "^2.0.2"
hash-sum "^2.0.0"
lru-cache "^5.1.1"
magic-string "^0.25.7"
merge-source-map "^1.1.0"
postcss "^8.1.10"
postcss-modules "^4.0.0"
postcss-selector-parser "^6.0.4"
source-map "^0.6.1"

"@vue/[email protected]":
version "3.1.4"
resolved "https://registry.npmjs.org/@vue/compiler-ssr/-/compiler-ssr-3.1.4.tgz#7f6eaac5b1851fc15c82c083e8179eb1216b303c"
Expand All @@ -1802,32 +1759,13 @@
"@vue/compiler-dom" "3.1.4"
"@vue/shared" "3.1.4"

"@vue/[email protected]":
version "3.2.11"
resolved "https://registry.nlark.com/@vue/compiler-ssr/download/@vue/compiler-ssr-3.2.11.tgz#702cef3429651645bdbe09fe5962803b5a621abb"
integrity sha1-cCzvNCllFkW9vgn+WWKAO1piGrs=
dependencies:
"@vue/compiler-dom" "3.2.11"
"@vue/shared" "3.2.11"

"@vue/[email protected]":
version "3.1.4"
resolved "https://registry.npmjs.org/@vue/reactivity/-/reactivity-3.1.4.tgz#d926ed46fb0d48582ccf8665b062d37b5d35ba99"
integrity sha512-YDlgii2Cr9yAoKVZFzgY4j0mYlVT73986X3e5SPp6ifqckSEoFSUWXZK2Tb53TB/9qO29BEEbspnKD3m3wAwkA==
dependencies:
"@vue/shared" "3.1.4"

"@vue/[email protected]":
version "3.2.11"
resolved "https://registry.nlark.com/@vue/ref-transform/download/@vue/ref-transform-3.2.11.tgz#4d282b9570d1485a73e7bf5d57cce27b4a7aa690"
integrity sha1-TSgrlXDRSFpz579dV8zie0p6ppA=
dependencies:
"@babel/parser" "^7.15.0"
"@vue/compiler-core" "3.2.11"
"@vue/shared" "3.2.11"
estree-walker "^2.0.2"
magic-string "^0.25.7"

"@vue/[email protected]":
version "3.1.4"
resolved "https://registry.npmjs.org/@vue/runtime-core/-/runtime-core-3.1.4.tgz#3e30ae6ecbfff06df5adc9414491143191a375ba"
Expand All @@ -1850,11 +1788,6 @@
resolved "https://registry.npmjs.org/@vue/shared/-/shared-3.1.4.tgz#c14c461ec42ea2c1556e86f60b0354341d91adc3"
integrity sha512-6O45kZAmkLvzGLToBxEz4lR2W6kXohCtebV2UxjH9GXjd8X9AhEn68FN9eNanFtWNzvgw1hqd6HkPRVQalqf7Q==

"@vue/[email protected]":
version "3.2.11"
resolved "https://registry.nlark.com/@vue/shared/download/@vue/shared-3.2.11.tgz#01899f54949caf1ac241de397bd17069632574de"
integrity sha1-AYmfVJScrxrCQd45e9FwaWMldN4=

"@vue/test-utils@^2.0.0-rc.6":
version "2.0.0-rc.14"
resolved "https://registry.nlark.com/@vue/test-utils/download/@vue/test-utils-2.0.0-rc.14.tgz#9da1be7b0e365ff5f945677da17bf6c8a7a83abd"
Expand Down Expand Up @@ -3954,7 +3887,7 @@ estraverse@^5.1.0, estraverse@^5.2.0:
resolved "https://registry.npm.taobao.org/estraverse/download/estraverse-5.2.0.tgz#307df42547e6cc7324d3cf03c155d5cdb8c53880"
integrity sha1-MH30JUfmzHMk088DwVXVzbjFOIA=

estree-walker@^2.0.1, estree-walker@^2.0.2:
estree-walker@^2.0.1:
version "2.0.2"
resolved "https://registry.nlark.com/estree-walker/download/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac"
integrity sha1-UvAQF4wqTBF6d1fP6UKtt9LaTKw=
Expand Down Expand Up @@ -4824,10 +4757,10 @@ he@^1.2.0:
resolved "https://registry.npm.taobao.org/he/download/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
integrity sha1-hK5l+n6vsWX922FWauFLrwVmTw8=

highlight.js@^10.3.2:
version "10.7.3"
resolved "https://registry.nlark.com/highlight.js/download/highlight.js-10.7.3.tgz#697272e3991356e40c3cac566a74eef681756531"
integrity sha1-aXJy45kTVuQMPKxWanTu9oF1ZTE=
[email protected]:
version "10.3.2"
resolved "https://registry.npmjs.org/highlight.js/-/highlight.js-10.3.2.tgz#135fd3619a00c3cbb8b4cd6dbc78d56bfcbc46f1"
integrity sha512-3jRT7OUYsVsKvukNKZCtnvRcFyCJqSEIuIMsEybAXRiFSwpt65qjPd/Pr+UOdYt7WJlt+lj3+ypUsHiySBp/Jw==

homedir-polyfill@^1.0.1:
version "1.0.3"
Expand Down
12 changes: 11 additions & 1 deletion packages/varlet-cli/src/config/webpack.base.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { VueLoaderPlugin } from 'vue-loader'
import { pathExistsSync } from 'fs-extra'
import { WebpackPluginInstance } from 'webpack'
import { createPostcssOptions } from './postcss.config'
import { getVarletConfig } from './varlet.config'
import { get } from 'lodash'

export const CSS_LOADERS = [
require.resolve('style-loader'),
Expand Down Expand Up @@ -83,7 +85,15 @@ export const BASE_CONFIG = {
},
{
test: /\.md$/,
use: [VUE_LOADER, require.resolve('@varlet/markdown-loader')],
use: [
VUE_LOADER,
{
loader: require.resolve('@varlet/markdown-loader'),
options: {
style: get(getVarletConfig(), 'highlight.style'),
},
},
],
},
{
test: /\.(png|jpg|gif|jpeg|svg)$/,
Expand Down
7 changes: 7 additions & 0 deletions packages/varlet-cli/varlet.default.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ module.exports = {
title: 'VARLET',
logo: 'https://varlet.gitee.io/varlet-ui/varlet_icon.png',
defaultLanguage: 'zh-CN',
highlight: {
style: '//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/styles/color-brewer.min.css',
},
analysis: {
baidu: '',
},
useMobile: false,
pc: {
menu: [],
redirect: '/home',
title: {
'zh-CN': 'Varlet 面向Vue3的Material风格移动端组件库',
Expand Down
11 changes: 8 additions & 3 deletions packages/varlet-markdown-loader/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
const markdown = require('markdown-it')
const hljs = require('highlight.js')
const loaderUtils = require('loader-utils')

function cardWrapper(html) {
const group = html.replace(/<h3/g, ':::<h3').replace(/<h2/g, ':::<h2').split(':::')

return group.map((fragment) => (fragment.includes('<h3') ? `<div class="card">${fragment}</div>` : fragment)).join('')
}

function highlight(str, lang) {
function highlight(str, lang, style) {
if (lang && hljs.getLanguage(lang)) {
return (
'<pre class="hljs"><code>' +
'<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/styles/color-brewer.min.css">' +
'<link rel="stylesheet" href="' +
style +
'"/>' +
hljs.highlight(lang, str, true).value +
'</code></pre>'
)
Expand All @@ -21,10 +24,12 @@ function highlight(str, lang) {
}

function markLoader(source) {
const options = loaderUtils.getOptions(this)
const style = options.style || '//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/styles/color-brewer.min.css'
const md = markdown({
html: true,
typographer: true,
highlight,
highlight: (str, lang) => highlight(str, lang, style),
})
const html = cardWrapper(md.render(source))

Expand Down
3 changes: 2 additions & 1 deletion packages/varlet-markdown-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
"dependencies": {
"highlight.js": "10.3.2",
"markdown-it": "^12.0.2"
"markdown-it": "^12.0.2",
"loader-utils": "^2.0.0"
},
"gitHead": "42554856ff028f6f411a35f468e0f763978270b0"
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3138,9 +3138,9 @@
"@vue/compiler-core" "3.1.4"
"@vue/shared" "3.1.4"

"@vue/compiler-sfc@^3.1.4":
"@vue/[email protected]":
version "3.1.4"
resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.1.4.tgz#93e87db950e0711339c18baa7bb7d28d3522d7bc"
resolved "https://registry.npmjs.org/@vue/compiler-sfc/-/compiler-sfc-3.1.4.tgz#93e87db950e0711339c18baa7bb7d28d3522d7bc"
integrity sha512-4KDQg60Khy3SgnF+V/TB2NZqzmM4TyGRmzsxqG1SebGdMSecCweFDSlI/F1vDYk6dKiCHgmpoT9A1sLxswkJ0A==
dependencies:
"@babel/parser" "^7.13.9"
Expand Down Expand Up @@ -7342,9 +7342,9 @@ he@^1.2.0:
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==

highlight.js@^10.3.2:
[email protected]:
version "10.3.2"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-10.3.2.tgz#135fd3619a00c3cbb8b4cd6dbc78d56bfcbc46f1"
resolved "https://registry.npmjs.org/highlight.js/-/highlight.js-10.3.2.tgz#135fd3619a00c3cbb8b4cd6dbc78d56bfcbc46f1"
integrity sha512-3jRT7OUYsVsKvukNKZCtnvRcFyCJqSEIuIMsEybAXRiFSwpt65qjPd/Pr+UOdYt7WJlt+lj3+ypUsHiySBp/Jw==

homedir-polyfill@^1.0.1:
Expand Down

0 comments on commit 7ca8844

Please sign in to comment.