Skip to content

Commit 6bcfcee

Browse files
compulimCopilot
andauthored
Remove markdown-it (#5825)
* Remove markdown-it * Fix type error * Fix undefined author name * Add TODO * Refactor internalRenderMarkdownInline * Add component-better-link to npm start * Add dataset options to better link * Remove trailing </p> * Fix localize spread args * Fix Prettier * Add entry * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent b9ad8fa commit 6bcfcee

58 files changed

Lines changed: 736 additions & 854 deletions

File tree

Some content is hidden

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

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Legends:
1919

2020
## [Unreleased]
2121

22+
### Changed
23+
24+
- Removed `markdown-it` and completed migration to `micromark`, in PR [#5825](https://github.com/microsoft/BotFramework-WebChat/pull/5825), by [@compulim](https://github.com/compulim)
25+
2226
## [4.19.0] - 2026-05-25
2327

2428
Breaking changes in this release:

lint-staged.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
'packages/base/src/**/*.{mjs,js,ts,tsx}': ['npm run precommit:eslint:base'],
1818
'packages/bundle/src/**/*.{mjs,js,ts,tsx}': ['npm run precommit:eslint:bundle'],
1919
'packages/component/src/**/*.{mjs,js,ts,tsx}': ['npm run precommit:eslint:component'],
20+
'packages/component-better-link/src/**/*.{mjs,js,ts,tsx}': ['npm run precommit:eslint:component-better-link'],
2021
'packages/core/src/**/*.{mjs,js,ts,tsx}': ['npm run precommit:eslint:core'],
2122
'packages/core-debug-api/src/**/*.{mjs,js,ts,tsx}': ['npm run precommit:eslint:core-debug-api'],
2223
'packages/core-graph/src/**/*.{mjs,js,ts,tsx}': ['npm run precommit:eslint:core-graph'],

package-lock.json

Lines changed: 17 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: 4 additions & 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",
@@ -83,6 +84,7 @@
8384
"precommit:eslint:base": "cd packages && cd base && npm run precommit:eslint",
8485
"precommit:eslint:bundle": "cd packages && cd bundle && npm run precommit:eslint",
8586
"precommit:eslint:component": "cd packages && cd component && npm run precommit:eslint",
87+
"precommit:eslint:component-better-link": "cd packages && cd component-better-link && npm run precommit:eslint",
8688
"precommit:eslint:core": "cd packages && cd core && npm run precommit:eslint",
8789
"precommit:eslint:core-debug-api": "cd packages && cd core-debug-api && npm run precommit:eslint",
8890
"precommit:eslint:core-graph": "cd packages && cd core-graph && npm run precommit:eslint",
@@ -121,6 +123,7 @@
121123
"precommit:typecheck:base": "cd packages && cd base && npm run precommit:typecheck",
122124
"precommit:typecheck:bundle": "cd packages && cd bundle && npm run precommit:typecheck",
123125
"precommit:typecheck:component": "cd packages && cd component && npm run precommit:typecheck",
126+
"precommit:typecheck:component-better-link": "cd packages && cd component-better-link && npm run precommit:typecheck",
124127
"precommit:typecheck:core": "cd packages && cd core && npm run precommit:typecheck",
125128
"precommit:typecheck:core-debug-api": "cd packages && cd core-debug-api && npm run precommit:typecheck",
126129
"precommit:typecheck:core-graph": "cd packages && cd core-graph && npm run precommit:typecheck",
@@ -151,6 +154,7 @@
151154
"start:base": "cd packages && cd base && npm start",
152155
"start:bundle": "cd packages && cd bundle && npm start",
153156
"start:component": "cd packages && cd component && npm start",
157+
"start:component-better-link": "cd packages && cd component-better-link && npm start",
154158
"start:core": "cd packages && cd core && npm start",
155159
"start:core-debug-api": "cd packages && cd core-debug-api && npm start",
156160
"start:core-graph": "cd packages && cd core-graph && npm start",

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(typeof arg0 === 'undefined' ? argRest : [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

0 commit comments

Comments
 (0)