@rspress/shared 0.0.0-next-20231113024827 → 0.0.0-next-20231207111357

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { RsbuildPlugin } from '@rsbuild/core';
2
- import { RsbuildConfig } from '@rsbuild/core/rspack-provider';
1
+ import { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core';
3
2
  import { PluggableList } from 'unified';
4
3
 
5
4
  interface ZoomOptions {
@@ -513,6 +512,7 @@ interface SiteData<ThemeConfig = NormalizedConfig> {
513
512
  markdown: {
514
513
  showLineNumbers: boolean;
515
514
  defaultWrapCode: boolean;
515
+ codeHighlighter: 'prism' | 'shiki';
516
516
  };
517
517
  multiVersion: {
518
518
  default: string;
@@ -646,6 +646,10 @@ interface MarkdownOptions {
646
646
  * Register global components in mdx files
647
647
  */
648
648
  globalComponents?: string[];
649
+ /**
650
+ * Code highlighter, default is prism for performance reason
651
+ */
652
+ codeHighlighter?: 'prism' | 'shiki';
649
653
  /**
650
654
  * Register prism languages
651
655
  */
@@ -667,6 +671,7 @@ declare const MDX_REGEXP: RegExp;
667
671
  declare const APPEARANCE_KEY = "rspress-theme-appearance";
668
672
  declare const SEARCH_INDEX_NAME = "search_index";
669
673
  declare const RSPRESS_TEMP_DIR = ".rspress";
674
+ declare const DEFAULT_HIGHLIGHT_LANGUAGES: (string | string[])[];
670
675
  declare const isSCM: () => boolean;
671
676
  declare const isProduction: () => boolean;
672
677
  declare const isDebugMode: () => boolean;
@@ -680,7 +685,8 @@ declare function removeLeadingSlash(url: string): string;
680
685
  declare function addTrailingSlash(url: string): string;
681
686
  declare function removeTrailingSlash(url: string): string;
682
687
  declare function normalizeSlash(url: string): string;
683
- declare function isExternalUrl(url: string): boolean;
688
+ declare function isExternalUrl(url?: string): boolean;
689
+ declare function isDataUrl(url?: string): boolean;
684
690
  declare function replaceLang(rawUrl: string, lang: {
685
691
  current: string;
686
692
  target: string;
@@ -709,4 +715,4 @@ declare function removeBase(url: string, base: string): string;
709
715
  declare function withoutHash(url: string): string;
710
716
  declare const mergeDocConfig: (...configs: UserConfig[]) => UserConfig;
711
717
 
712
- export { APPEARANCE_KEY, AdditionalPage, BaseRuntimePageInfo, Config, Config$1 as DefaultThemeConfig, DocFooter, EditLink, Feature, Footer, FrontMatterMeta, HASH_REGEXP, Header, Hero, Image, LocalSearchOptions, Locale, LocaleConfig, LocaleLink, LocaleLinks, MDX_REGEXP, MarkdownOptions, Nav, NavItem, NavItemWithChildren, NavItemWithLink, NavItemWithLinkAndChildren, NormalizedConfig, NormalizedConfig as NormalizedDefaultThemeConfig, NormalizedLocales, NormalizedSidebar, NormalizedSidebarGroup, PageData, PageIndexInfo, PageModule, PageType, RspressPlugin as Plugin, QUERY_REGEXP, RSPRESS_TEMP_DIR, RemotePageInfo, RemoteSearchIndexInfo, RemoteSearchOptions, ReplaceRule, Route, RouteMeta, RouteOptions, RspressPlugin, SEARCH_INDEX_NAME, SearchHooks, SearchOptions, Sidebar, SidebarDivider, SidebarGroup, SidebarItem, SiteData, SocialLink, SocialLinkIcon, UserConfig, addLeadingSlash, addTrailingSlash, cleanUrl, inBrowser, isDebugMode, isExternalUrl, isProduction, isSCM, mergeDocConfig, normalizeHref, normalizePosixPath, normalizeSlash, omit, parseUrl, removeBase, removeHash, removeLeadingSlash, removeTrailingSlash, replaceLang, replaceVersion, slash, withBase, withoutBase, withoutHash, withoutLang };
718
+ export { APPEARANCE_KEY, AdditionalPage, BaseRuntimePageInfo, Config, DEFAULT_HIGHLIGHT_LANGUAGES, Config$1 as DefaultThemeConfig, DocFooter, EditLink, Feature, Footer, FrontMatterMeta, HASH_REGEXP, Header, Hero, Image, LocalSearchOptions, Locale, LocaleConfig, LocaleLink, LocaleLinks, MDX_REGEXP, MarkdownOptions, Nav, NavItem, NavItemWithChildren, NavItemWithLink, NavItemWithLinkAndChildren, NormalizedConfig, NormalizedConfig as NormalizedDefaultThemeConfig, NormalizedLocales, NormalizedSidebar, NormalizedSidebarGroup, PageData, PageIndexInfo, PageModule, PageType, RspressPlugin as Plugin, QUERY_REGEXP, RSPRESS_TEMP_DIR, RemotePageInfo, RemoteSearchIndexInfo, RemoteSearchOptions, ReplaceRule, Route, RouteMeta, RouteOptions, RspressPlugin, SEARCH_INDEX_NAME, SearchHooks, SearchOptions, Sidebar, SidebarDivider, SidebarGroup, SidebarItem, SiteData, SocialLink, SocialLinkIcon, UserConfig, addLeadingSlash, addTrailingSlash, cleanUrl, inBrowser, isDataUrl, isDebugMode, isExternalUrl, isProduction, isSCM, mergeDocConfig, normalizeHref, normalizePosixPath, normalizeSlash, omit, parseUrl, removeBase, removeHash, removeLeadingSlash, removeTrailingSlash, replaceLang, replaceVersion, slash, withBase, withoutBase, withoutHash, withoutLang };
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
23
  APPEARANCE_KEY: () => APPEARANCE_KEY,
24
+ DEFAULT_HIGHLIGHT_LANGUAGES: () => DEFAULT_HIGHLIGHT_LANGUAGES,
24
25
  HASH_REGEXP: () => HASH_REGEXP,
25
26
  MDX_REGEXP: () => MDX_REGEXP,
26
27
  QUERY_REGEXP: () => QUERY_REGEXP,
@@ -30,6 +31,7 @@ __export(src_exports, {
30
31
  addTrailingSlash: () => addTrailingSlash,
31
32
  cleanUrl: () => cleanUrl,
32
33
  inBrowser: () => inBrowser,
34
+ isDataUrl: () => isDataUrl,
33
35
  isDebugMode: () => isDebugMode,
34
36
  isExternalUrl: () => isExternalUrl,
35
37
  isProduction: () => isProduction,
@@ -1116,6 +1118,22 @@ var MDX_REGEXP = /\.mdx?$/;
1116
1118
  var APPEARANCE_KEY = "rspress-theme-appearance";
1117
1119
  var SEARCH_INDEX_NAME = "search_index";
1118
1120
  var RSPRESS_TEMP_DIR = ".rspress";
1121
+ var DEFAULT_HIGHLIGHT_LANGUAGES = [
1122
+ ["js", "javascript"],
1123
+ ["ts", "typescript"],
1124
+ ["jsx", "tsx"],
1125
+ "tsx",
1126
+ "json",
1127
+ "css",
1128
+ "scss",
1129
+ "less",
1130
+ ["xml", "xml-doc"],
1131
+ "diff",
1132
+ "yaml",
1133
+ ["md", "markdown"],
1134
+ ["mdx", "tsx"],
1135
+ "bash"
1136
+ ];
1119
1137
  var isSCM = () => Boolean(process.env.BUILD_VERSION);
1120
1138
  var isProduction = () => process.env.NODE_ENV === "production";
1121
1139
  var isDebugMode = () => Boolean(process.env.DOC_DEBUG);
@@ -1166,9 +1184,12 @@ function removeTrailingSlash(url) {
1166
1184
  function normalizeSlash(url) {
1167
1185
  return removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
1168
1186
  }
1169
- function isExternalUrl(url) {
1187
+ function isExternalUrl(url = "") {
1170
1188
  return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("mailto:") || url.startsWith("tel:");
1171
1189
  }
1190
+ function isDataUrl(url = "") {
1191
+ return /^\s*data:/i.test(url);
1192
+ }
1172
1193
  function replaceLang(rawUrl, lang, version, base = "") {
1173
1194
  let url = removeBase(rawUrl, base);
1174
1195
  if (!url) {
@@ -1249,16 +1270,17 @@ function normalizeHref(url, cleanUrls = false) {
1249
1270
  return url;
1250
1271
  }
1251
1272
  let { url: cleanUrl2, hash } = parseUrl(decodeURIComponent(url));
1252
- if (url.startsWith("mailto:") || url.startsWith("tel:")) {
1253
- return url;
1254
- }
1255
- if (!cleanUrls && !cleanUrl2.endsWith(".html")) {
1273
+ const hasExt = cleanUrl2.split("/").pop()?.includes(".");
1274
+ if (!cleanUrls && !cleanUrl2.endsWith(".html") && !hasExt) {
1256
1275
  if (cleanUrl2.endsWith("/")) {
1257
1276
  cleanUrl2 += "index.html";
1258
1277
  } else {
1259
1278
  cleanUrl2 += ".html";
1260
1279
  }
1261
1280
  }
1281
+ if (cleanUrls && cleanUrl2.endsWith("/")) {
1282
+ cleanUrl2 += "index";
1283
+ }
1262
1284
  return addLeadingSlash(hash ? `${cleanUrl2}#${hash}` : cleanUrl2);
1263
1285
  }
1264
1286
  function withoutLang(path, langs) {
@@ -1295,6 +1317,7 @@ var mergeDocConfig = (...configs) => mergeWith_default({}, ...configs, (target,
1295
1317
  // Annotate the CommonJS export names for ESM import in node:
1296
1318
  0 && (module.exports = {
1297
1319
  APPEARANCE_KEY,
1320
+ DEFAULT_HIGHLIGHT_LANGUAGES,
1298
1321
  HASH_REGEXP,
1299
1322
  MDX_REGEXP,
1300
1323
  QUERY_REGEXP,
@@ -1304,6 +1327,7 @@ var mergeDocConfig = (...configs) => mergeWith_default({}, ...configs, (target,
1304
1327
  addTrailingSlash,
1305
1328
  cleanUrl,
1306
1329
  inBrowser,
1330
+ isDataUrl,
1307
1331
  isDebugMode,
1308
1332
  isExternalUrl,
1309
1333
  isProduction,
package/dist/index.mjs CHANGED
@@ -1060,6 +1060,22 @@ var MDX_REGEXP = /\.mdx?$/;
1060
1060
  var APPEARANCE_KEY = "rspress-theme-appearance";
1061
1061
  var SEARCH_INDEX_NAME = "search_index";
1062
1062
  var RSPRESS_TEMP_DIR = ".rspress";
1063
+ var DEFAULT_HIGHLIGHT_LANGUAGES = [
1064
+ ["js", "javascript"],
1065
+ ["ts", "typescript"],
1066
+ ["jsx", "tsx"],
1067
+ "tsx",
1068
+ "json",
1069
+ "css",
1070
+ "scss",
1071
+ "less",
1072
+ ["xml", "xml-doc"],
1073
+ "diff",
1074
+ "yaml",
1075
+ ["md", "markdown"],
1076
+ ["mdx", "tsx"],
1077
+ "bash"
1078
+ ];
1063
1079
  var isSCM = () => Boolean(process.env.BUILD_VERSION);
1064
1080
  var isProduction = () => process.env.NODE_ENV === "production";
1065
1081
  var isDebugMode = () => Boolean(process.env.DOC_DEBUG);
@@ -1110,9 +1126,12 @@ function removeTrailingSlash(url) {
1110
1126
  function normalizeSlash(url) {
1111
1127
  return removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
1112
1128
  }
1113
- function isExternalUrl(url) {
1129
+ function isExternalUrl(url = "") {
1114
1130
  return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("mailto:") || url.startsWith("tel:");
1115
1131
  }
1132
+ function isDataUrl(url = "") {
1133
+ return /^\s*data:/i.test(url);
1134
+ }
1116
1135
  function replaceLang(rawUrl, lang, version, base = "") {
1117
1136
  let url = removeBase(rawUrl, base);
1118
1137
  if (!url) {
@@ -1193,16 +1212,17 @@ function normalizeHref(url, cleanUrls = false) {
1193
1212
  return url;
1194
1213
  }
1195
1214
  let { url: cleanUrl2, hash } = parseUrl(decodeURIComponent(url));
1196
- if (url.startsWith("mailto:") || url.startsWith("tel:")) {
1197
- return url;
1198
- }
1199
- if (!cleanUrls && !cleanUrl2.endsWith(".html")) {
1215
+ const hasExt = cleanUrl2.split("/").pop()?.includes(".");
1216
+ if (!cleanUrls && !cleanUrl2.endsWith(".html") && !hasExt) {
1200
1217
  if (cleanUrl2.endsWith("/")) {
1201
1218
  cleanUrl2 += "index.html";
1202
1219
  } else {
1203
1220
  cleanUrl2 += ".html";
1204
1221
  }
1205
1222
  }
1223
+ if (cleanUrls && cleanUrl2.endsWith("/")) {
1224
+ cleanUrl2 += "index";
1225
+ }
1206
1226
  return addLeadingSlash(hash ? `${cleanUrl2}#${hash}` : cleanUrl2);
1207
1227
  }
1208
1228
  function withoutLang(path, langs) {
@@ -1238,6 +1258,7 @@ var mergeDocConfig = (...configs) => mergeWith_default({}, ...configs, (target,
1238
1258
  });
1239
1259
  export {
1240
1260
  APPEARANCE_KEY,
1261
+ DEFAULT_HIGHLIGHT_LANGUAGES,
1241
1262
  HASH_REGEXP,
1242
1263
  MDX_REGEXP,
1243
1264
  QUERY_REGEXP,
@@ -1247,6 +1268,7 @@ export {
1247
1268
  addTrailingSlash,
1248
1269
  cleanUrl,
1249
1270
  inBrowser,
1271
+ isDataUrl,
1250
1272
  isDebugMode,
1251
1273
  isExternalUrl,
1252
1274
  isProduction,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/shared",
3
- "version": "0.0.0-next-20231113024827",
3
+ "version": "0.0.0-next-20231207111357",
4
4
  "types": "./dist/index.d.ts",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -22,7 +22,7 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
- "@rsbuild/core": "0.0.14",
25
+ "@rsbuild/core": "0.0.0-next-20231207110454",
26
26
  "unified": "10.1.2",
27
27
  "chalk": "4.1.2",
28
28
  "rslog": "^1.1.0"
@@ -47,6 +47,7 @@
47
47
  "provenance": true,
48
48
  "registry": "https://registry.npmjs.org/"
49
49
  },
50
+ "license": "MIT",
50
51
  "files": [
51
52
  "bin",
52
53
  "dist"