Skip to content

Commit

Permalink
merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
BearToCode committed Aug 1, 2023
2 parents ab99c97 + ded0477 commit 1d2bc03
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 271 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
"name": "carta",
"type": "module",
"module": "esnext",
"version": "2.0.5",
"version": "2.0.6",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/BearToCode/carta-md.git"
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"postinstall": "node ./scripts/gen-speed-highlight.js",
"core": "cd packages/carta-md && npm run dev",
"dev": "cd demo && npm run dev",
"check": "cd packages/carta-md && npm run check",
Expand Down
3 changes: 2 additions & 1 deletion packages/carta-md/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"./light.css": "./dist/light.css",
"./dark.css": "./dist/dark.css"
},
"version": "2.0.5",
"version": "2.0.6",
"scripts": {
"dev": "vite dev",
"build": "svelte-kit sync && svelte-package",
Expand All @@ -37,6 +37,7 @@
},
"type": "module",
"dependencies": {
"@speed-highlight/core": "^1.2.2",
"marked": "^4.3.0"
},
"peerDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions packages/carta-md/src/lib/internal/carta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import type { SvelteComponentTyped } from 'svelte';
import { CartaRenderer } from './renderer';
import {
loadCustomLanguage,
type HighlightLanguage,
type HighlightFunctions,
highlight,
highlightAutodetect
highlightAutodetect,
type HighlightFunctions
} from './highlight.js';
import type { ShjLanguageDefinition } from '@speed-highlight/core/index';

/**
* Carta-specific event with extra payload.
Expand Down Expand Up @@ -126,7 +126,7 @@ export interface CartaExtension {
/**
* Custom markdown highlight rules. See [Speed-Highlight Wiki](https://github.com/speed-highlight/core/wiki/Create-or-suggest-new-languages).
*/
highlightRules?: HighlightLanguage;
highlightRules?: ShjLanguageDefinition;
/**
* This function can be used to access a reference to the `Carta` class immediately after initialization.
*/
Expand All @@ -141,7 +141,7 @@ export class Carta {
public readonly keyboardShortcuts: KeyboardShortcut[];
public readonly icons: CartaIcon[];
public readonly prefixes: Prefix[];
public readonly highlightRules: HighlightLanguage;
public readonly highlightRules: ShjLanguageDefinition;
public readonly listeners: CartaListeners;
public readonly components: CartaExtensionComponents;

Expand Down
24 changes: 6 additions & 18 deletions packages/carta-md/src/lib/internal/highlight.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import { detectLanguage } from '@speed-highlight/core/detect';
import { highlightText, loadLanguage } from '@speed-highlight/core';

export type HighlightRule =
| { type: string; match: RegExp }
| { extand: string }
| {
match: RegExp;
sub:
| string
| ((code: string) => { type: string; sub: Array<{ match: RegExp; sub: string }> });
};

export type HighlightLanguage = Array<HighlightRule>;
import { detectLanguage } from '@speed-highlight/core/detect.js';
import { highlightText, loadLanguage, type ShjLanguageDefinition } from '@speed-highlight/core';

/**
* Highlight text using Speed-Highlight. May return null on error(usually if requested
Expand All @@ -27,7 +15,7 @@ export async function highlight(
hideLineNumbers?: boolean
): Promise<string | null> {
try {
return await highlightText(text, lang, true, { hideLineNumbers });
return await highlightText(text, lang, true, { hideLineNumbers: hideLineNumbers ?? true });
} catch (_) {
return null;
}
Expand All @@ -40,8 +28,8 @@ export async function highlight(
* @returns Highlighted html text.
*/
export async function highlightAutodetect(text: string, hideLineNumbers?: boolean) {
const lang = detectLanguage(text);
return await highlightText(text, lang, true, { hideLineNumbers });
const lang = await detectLanguage(text);
return await highlightText(text, lang, true, { hideLineNumbers: hideLineNumbers ?? true });
}

/**
Expand All @@ -66,7 +54,7 @@ export async function highlightAutodetect(text: string, hideLineNumbers?: boolea
* .then(module => Carta.loadCustomLanguage("lang-name", module));
* ```
*/
export function loadCustomLanguage(id: string, langModule: { default: HighlightLanguage }) {
export function loadCustomLanguage(id: string, langModule: { default: ShjLanguageDefinition }) {
return loadLanguage(id, langModule);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/carta-md/src/lib/internal/shj.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ShjLanguage } from '@speed-highlight/core';
import { detectLanguage } from '@speed-highlight/core/detect';
import { detectLanguage } from '@speed-highlight/core/detect.js';
import type { ShjLanguageDefinition } from '@speed-highlight/core';

/**
* Markdown syntax highlighting rules.
*/
const cartaMarkdown: ShjLanguage = [
const cartaMarkdown: ShjLanguageDefinition = [
{
type: 'cmnt',
match: /^>.*|(=|-)\1+/gm
Expand Down
5 changes: 1 addition & 4 deletions packages/carta-md/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ const config = {
preprocess: vitePreprocess(),

kit: {
adapter: adapter(),
alias: {
'@speed-highlight/core': './src/lib/speed-highlight'
}
adapter: adapter()
}
};

Expand Down
3 changes: 1 addition & 2 deletions packages/carta-md/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
"ignoreDeprecations": "5.0",
"plugins": [],
"baseUrl": "./",
"typeRoots": ["./node_modules/@types", "./typings"],
"paths": {
"$lib": ["src/lib"],
"$lib/*": ["src/lib/*"]
}
},
"include": ["./src", "./typings"]
"include": ["./src"]
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
Expand Down
53 changes: 0 additions & 53 deletions packages/carta-md/typings/index.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/plugin-code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
"typescript-cp": "^0.1.8"
},
"peerDependencies": {
"carta-md": "^2.0.5",
"carta-md": "^2.0.6",
"marked": "^4.3.0"
},
"files": [
"dist"
],
"version": "2.0.5",
"version": "2.0.6",
"dependencies": {
"marked-highlight": "^2.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-emoji/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cartamd/plugin-emoji",
"version": "2.0.5",
"version": "2.0.6",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -39,7 +39,7 @@
},
"peerDependencies": {
"svelte": "^3.54.0",
"carta-md": "^2.0.5",
"carta-md": "^2.0.6",
"marked": "^4.3.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-math/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"typescript": "^5.0.4"
},
"peerDependencies": {
"carta-md": "^2.0.5",
"carta-md": "^2.0.6",
"katex": "^0.16.7",
"marked": "^4.3.0"
},
Expand All @@ -33,7 +33,7 @@
"dependencies": {
"katex": "^0.16.7"
},
"version": "2.0.5",
"version": "2.0.6",
"keywords": [
"carta",
"markdown",
Expand Down
4 changes: 1 addition & 3 deletions packages/plugin-math/src/latex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { HighlightLanguage } from 'carta-md';

export default [
{
match:
Expand Down Expand Up @@ -37,4 +35,4 @@ export default [
match: /[0-9]+/g,
type: 'num'
}
] satisfies HighlightLanguage;
];
4 changes: 2 additions & 2 deletions packages/plugin-slash/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cartamd/plugin-slash",
"version": "2.0.5",
"version": "2.0.6",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -38,7 +38,7 @@
},
"peerDependencies": {
"svelte": "^3.54.0",
"carta-md": "^2.0.5"
"carta-md": "^2.0.6"
},
"devDependencies": {
"carta-md": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-tikz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
"md5": "^2.3.0"
},
"peerDependencies": {
"carta-md": "^2.0.5",
"carta-md": "^2.0.6",
"marked": "^4.3.0"
},
"files": [
"dist"
],
"version": "2.0.5",
"version": "2.0.6",
"keywords": [
"carta",
"markdown",
Expand Down
4 changes: 1 addition & 3 deletions packages/plugin-tikz/src/tikz.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { HighlightLanguage } from 'carta-md';

export default [
{
match: /\\(usepackage|input|usemodule)(?![a-zA-Z0-9])/g,
Expand All @@ -25,4 +23,4 @@ export default [
match: /[0-9]+[a-z]{0,3}/g,
type: 'num'
}
] satisfies HighlightLanguage;
];
Loading

0 comments on commit 1d2bc03

Please sign in to comment.