Skip to content

Commit

Permalink
fix: not resolve eacape in message.open (#2973)
Browse files Browse the repository at this point in the history
* fix: not resolve eacape in message

* chore: add note
  • Loading branch information
pipiiiiii authored Aug 2, 2023
1 parent 3a2cde3 commit 5cbd668
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 10 additions & 0 deletions packages/components/src/utils/marked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ export const parseMarkdown = (
};

export const toMarkdownHtml = (value: string, options?: IMarkedOptions) => marked(value, options);

export const parseWithoutEscape = (token: marked.Token) => {
// 这里兼容下 vscode 的写法,vscode 这里没有处理 markdown 语法
// 否则会出现 (\\) 被解析成 () 期望是 (\)
if (token.type === 'escape') {
token.text = token.raw;
}

return token;
};
9 changes: 5 additions & 4 deletions packages/core-browser/src/markdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React from 'react';

import { DATA_SET_COMMAND, RenderWrapper } from '@opensumi/ide-components/lib/markdown/render';
import { createMarkedRenderer, toMarkdownHtml as toHtml } from '@opensumi/ide-components/lib/utils';
import { createMarkedRenderer, toMarkdownHtml as toHtml, IMarkedOptions } from '@opensumi/ide-components/lib/utils';

import { IOpenerService } from '../opener';

export const toMarkdown = (message: string | React.ReactNode, opener?: IOpenerService): React.ReactNode =>
export const toMarkdown = (message: string | React.ReactNode, opener?: IOpenerService, options?: IMarkedOptions): React.ReactNode =>
typeof message === 'string' ? (
<RenderWrapper opener={opener} html={toMarkdownHtml(message)}></RenderWrapper>
<RenderWrapper opener={opener} html={toMarkdownHtml(message, options)}></RenderWrapper>
) : (
message
);

export const toMarkdownHtml = (message: string): string => {
export const toMarkdownHtml = (message: string, options?: IMarkedOptions): string => {
const renderer = createMarkedRenderer();

renderer.link = (href, title, text) =>
Expand All @@ -25,5 +25,6 @@ export const toMarkdownHtml = (message: string): string => {
smartLists: true,
smartypants: false,
renderer,
...(options || {}),
});
};
3 changes: 2 additions & 1 deletion packages/overlay/src/browser/message.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';

import { Autowired, Injectable } from '@opensumi/di';
import { notification, open } from '@opensumi/ide-components';
import { parseWithoutEscape } from '@opensumi/ide-components/lib/utils';
import { IOpenerService, toMarkdown } from '@opensumi/ide-core-browser';
import { MessageType, uuid, localize } from '@opensumi/ide-core-common';

Expand Down Expand Up @@ -64,7 +65,7 @@ export class MessageService extends AbstractMessageService implements IMessageSe
const description = from && typeof from === 'string' ? `${localize('component.message.origin')}: ${from}` : '';
const key = uuid();
const promise = open<T>(
toMarkdown(message, this.openerService),
toMarkdown(message, this.openerService, { walkTokens: parseWithoutEscape }),
type,
closable,
key,
Expand Down

0 comments on commit 5cbd668

Please sign in to comment.