Skip to content

Commit 2f2d7f0

Browse files
committed
Remove markdown-it
1 parent 8fcd02a commit 2f2d7f0

49 files changed

Lines changed: 612 additions & 823 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package-lock.json

Lines changed: 15 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"packages/api",
3636
"packages/isomorphic-react",
3737
"packages/isomorphic-react-dom",
38+
"packages/component-better-link",
3839
"packages/component",
3940
"packages/repack/adaptivecards",
4041
"packages/repack/base64-js",

packages/api/src/hooks/useLocalizer.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { isForbiddenPropertyName } from 'botframework-webchat-core';
22
import { useCallback } from 'react';
33

4+
import { isPlainObject } from '@msinternal/botframework-webchat-base/utils';
45
import getAllLocalizedStrings from '../localization/getAllLocalizedStrings';
56
import useLocalizedGlobalize from './internal/useLocalizedGlobalize';
67
import useLocalizedStrings from './internal/useLocalizedStrings';
7-
import { isPlainObject } from '@msinternal/botframework-webchat-base/utils';
88

99
const DEFAULT_STRINGS = getAllLocalizedStrings()['en-US'];
1010

@@ -17,12 +17,18 @@ type Plural = {
1717
other: string;
1818
};
1919

20-
export default function useLocalizer({ plural }: { plural?: boolean } = {}) {
20+
type PluralLocalizer = (id: Plural, arg0: number, ...argRest: readonly string[]) => string;
21+
type SingularLocalizer = (id: string, ...argRest: readonly string[]) => string;
22+
23+
function useLocalizer(init: { plural: true }): PluralLocalizer;
24+
function useLocalizer(init?: { plural?: false } | undefined): SingularLocalizer;
25+
26+
function useLocalizer({ plural }: { plural?: boolean } = {}): PluralLocalizer | SingularLocalizer {
2127
const [globalize] = useLocalizedGlobalize();
2228
const localizedStrings = useLocalizedStrings();
2329

2430
return useCallback(
25-
(id: string | Plural, ...args: [(number | string)?, ...string[]]) => {
31+
(id: string | Plural, arg0: number | string, ...argRest: readonly string[]) => {
2632
let stringId = id as string;
2733

2834
if (plural) {
@@ -32,7 +38,7 @@ export default function useLocalizer({ plural }: { plural?: boolean } = {}) {
3238
throw new Error('useLocalizer: Plural string must pass "id" as a plain object instead of string.');
3339
} else if (typeof pluralId.other !== 'string') {
3440
throw new Error('useLocalizer: Plural string must have "id.other" of string.');
35-
} else if (typeof args[0] !== 'number') {
41+
} else if (typeof arg0 !== 'number') {
3642
throw new Error('useLocalizer: Plural string must have first argument as a number.');
3743
}
3844

@@ -58,12 +64,12 @@ export default function useLocalizer({ plural }: { plural?: boolean } = {}) {
5864
);
5965
}
6066

61-
stringId = pluralId[globalize.plural(args[0])] || pluralId.other;
67+
stringId = pluralId[globalize.plural(arg0)] || pluralId.other;
6268
} else if (typeof id !== 'string') {
6369
throw new Error('useLocalizer: "id" must be a string.');
6470
}
6571

66-
return Object.entries(args).reduce(
72+
return Object.entries([arg0, ...argRest]).reduce(
6773
(str, [index, arg]) => str.replace(`$${+index + 1}`, arg),
6874
// Mitigation through denylisting.
6975
// eslint-disable-next-line security/detect-object-injection
@@ -73,3 +79,5 @@ export default function useLocalizer({ plural }: { plural?: boolean } = {}) {
7379
[globalize, localizedStrings, plural]
7480
);
7581
}
82+
83+
export default useLocalizer;

packages/bundle/src/markdown/createStreamingRenderer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import katex from 'katex';
33
import { compile, parse, postprocess, preprocess } from 'micromark';
44
import { gfm, gfmHtml } from 'micromark-extension-gfm';
55
import type { Event, Options } from 'micromark-util-types';
6+
import { betterLinkDocumentMod } from 'botframework-webchat-component/internal.js';
67

78
import { math, mathHtml } from './mathExtension';
8-
import betterLinkDocumentMod from './private/betterLinkDocumentMod';
9+
import { createDecorate } from './private/createDecorate';
910
import extractDefinitionsFromEvents, { type MarkdownLinkDefinition } from './private/extractDefinitionsFromEvents';
1011
import { pre as respectCRLFPre } from './private/respectCRLF';
11-
import { createDecorate } from './private/createDecorate';
1212

1313
type StreamingRenderInit = Readonly<{
1414
externalLinkAlt: string;

packages/bundle/src/markdown/private/createDecorate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import type { BetterLinkDocumentModDecoration } from 'botframework-webchat-component/internal.js';
12
import { onErrorResumeNext } from 'botframework-webchat-core';
2-
import type { BetterLinkDocumentModDecoration } from './betterLinkDocumentMod';
3-
import type { MarkdownLinkDefinition } from './extractDefinitionsFromEvents';
43
import { sanitizeUri } from 'micromark-util-sanitize-uri';
4+
import type { MarkdownLinkDefinition } from './extractDefinitionsFromEvents';
55

66
export const ALLOWED_SCHEMES = ['data', 'http', 'https', 'ftp', 'mailto', 'sip', 'tel'];
77

packages/bundle/src/markdown/renderMarkdown.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
betterLinkDocumentMod,
23
parseDocumentFragmentFromString,
34
serializeDocumentFragmentIntoString,
45
type HighlightCodeFn
@@ -14,10 +15,9 @@ import createStreamingRenderer, {
1415
type StreamingRenderOptions
1516
} from './createStreamingRenderer';
1617
import { math, mathHtml } from './mathExtension';
17-
import betterLinkDocumentMod from './private/betterLinkDocumentMod';
18+
import { createDecorate } from './private/createDecorate';
1819
import iterateLinkDefinitions from './private/iterateLinkDefinitions';
1920
import { pre as respectCRLFPre } from './private/respectCRLF';
20-
import { createDecorate } from './private/createDecorate';
2121

2222
type RenderInit = Readonly<{
2323
codeBlockCopyButtonTagName: string;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extends:
2+
- ../../.eslintrc.production.yml
3+
- ../../.eslintrc.react.yml
4+
5+
# This package is compatible with web browser.
6+
env:
7+
browser: true
8+
9+
rules:
10+
# React functional component is better in function style than arrow style.
11+
prefer-arrow-callback: off
12+
13+
# React already deprecated default props.
14+
react/require-default-props: off
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*.tgz
2+
/dist/
3+
/node_modules/
4+
/tsup.config.bundled_*.mjs
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "@msinternal/botframework-webchat-component-better-link",
3+
"version": "0.0.0-0",
4+
"description": "botframework-webchat-component/better-link package",
5+
"main": "./dist/botframework-webchat-component-better-link.js",
6+
"types": "./dist/botframework-webchat-component-better-link.d.ts",
7+
"exports": {
8+
".": {
9+
"import": {
10+
"types": "./dist/botframework-webchat-component-better-link.d.mts",
11+
"default": "./dist/botframework-webchat-component-better-link.mjs"
12+
},
13+
"require": {
14+
"types": "./dist/botframework-webchat-component-better-link.d.ts",
15+
"default": "./dist/botframework-webchat-component-better-link.js"
16+
}
17+
}
18+
},
19+
"author": "Microsoft Corporation",
20+
"license": "MIT",
21+
"private": true,
22+
"repository": {
23+
"type": "git",
24+
"url": "git+https://github.com/microsoft/BotFramework-WebChat.git"
25+
},
26+
"bugs": {
27+
"url": "https://github.com/microsoft/BotFramework-WebChat/issues"
28+
},
29+
"files": [
30+
"./dist/**/*",
31+
"./src/**/*",
32+
"*.js"
33+
],
34+
"homepage": "https://github.com/microsoft/BotFramework-WebChat/tree/main/packages/component-better-link#readme",
35+
"scripts": {
36+
"build": "npm run --if-present build:pre && npm run build:run && npm run --if-present build:post",
37+
"build:pre": "npm run build:pre:local-dependencies && npm run build:pre:watch",
38+
"build:pre:local-dependencies": "../../scripts/npm/build-local-dependencies.sh",
39+
"build:pre:watch": "../../scripts/npm/build-watch.sh",
40+
"build:run": "tsup",
41+
"bump": "vg bump prod && vg bump dev && vg bump peer && (npm audit fix || exit 0)",
42+
"eslint": "npm run precommit",
43+
"postversion": "../../scripts/npm/postversion.sh",
44+
"precommit": "npm run precommit:eslint -- src && npm run precommit:typecheck",
45+
"precommit:eslint": "../../node_modules/.bin/eslint --report-unused-disable-directives --max-warnings 0",
46+
"precommit:typecheck": "tsc --project ./src --emitDeclarationOnly false --esModuleInterop true --noEmit --pretty false",
47+
"preversion": "../../scripts/npm/preversion.sh",
48+
"start": "../../scripts/npm/notify-build.sh \"src\""
49+
},
50+
"pinDependencies": {},
51+
"localDependencies": {},
52+
"devDependencies": {
53+
"typescript": "^6.0.3"
54+
},
55+
"peerDependencies": {}
56+
}

packages/bundle/src/markdown/private/betterLinkDocumentMod.ariaLabel.spec.ts renamed to packages/component-better-link/src/betterLinkDocumentMod.ariaLabel.spec.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
/** @jest-environment @happy-dom/jest-environment */
22
/// <reference types="jest" />
33

4-
import {
5-
parseDocumentFragmentFromString,
6-
serializeDocumentFragmentIntoString
7-
} from 'botframework-webchat-component/internal.js';
84
import { micromark } from 'micromark';
95
import betterLinkDocumentMod, { type BetterLinkDocumentModDecoration } from './betterLinkDocumentMod';
6+
import parseDocumentFragmentFromString from './parseDocumentFragmentFromString';
7+
import serializeDocumentFragmentIntoString from './serializeDocumentFragmentIntoString';
108

119
const BASE_MARKDOWN = '[Example](https://example.com)';
1210
let baseHTML: string;
@@ -24,7 +22,7 @@ describe('When passing "ariaLabel" option with "Hello, World!"', () => {
2422
});
2523

2624
test('should have "aria-label" attribute set to "Hello, World!"', () =>
27-
expect(actual.querySelector('a').getAttribute('aria-label')).toBe('Hello, World!'));
25+
expect(actual.querySelector('a')?.getAttribute('aria-label')).toBe('Hello, World!'));
2826

2927
test('should match snapshot', () =>
3028
expect(serializeDocumentFragmentIntoString(actual)).toBe(
@@ -44,7 +42,7 @@ describe('When passing "ariaLabel" option with false', () => {
4442
});
4543

4644
test('should have "aria-label" attribute removed', () =>
47-
expect(actual.querySelector('a').hasAttribute('aria-label')).toBe(false));
45+
expect(actual.querySelector('a')?.hasAttribute('aria-label')).toBe(false));
4846

4947
test('should match snapshot', () =>
5048
expect(serializeDocumentFragmentIntoString(actual)).toBe(

0 commit comments

Comments
 (0)