Open bosens-China opened 2 months ago
Try to write #
inside your component code instead of outside.
😀明天试一下这个
import { Root } from "../../types/textTypes";
interface Props {
text: string;
vocabulary: Root["vocabulary"];
}
const textContrast = (a: string, b: string) => {
return new RegExp(a, "i").test(b);
};
/**
* 输出文本,如果包含本课的新词会重点描述
* @param param0
*/
export const TextVocabularyOutput: React.FC<Props> = ({ text, vocabulary }) => {
const arr = text
.split(/\s/g)
.map((item, index, array) => {
const isEnd = array.length === index - 1;
const text = isEnd ? "" : " ";
if (vocabulary.find((f) => textContrast(f.word, item))) {
return [<span key={item}>{item}</span>, text];
}
return [item, text];
})
.flat(2);
return <># {arr}</>;
};
在mdx中如果这样调用
# Lesson 1 Excuse me! 对不起!
<TextVocabularyOutput text={data.title} vocabulary={data.vocabulary} />
输出
If you using .tsx
, return <># {arr}</>;
means return simple text.
The tsx component should not be used to generate markdown headers and more dynamic markdown/html structures, which will lack a lot of metadata information when analyzing at build time. The correct usage of the tsx component should be to write a component written by react that not return markdown structure.
If you use the original method in your issue screenshot, the id
and href
attributes cannot be generated when mdx is compiled.
版本信息
问题详情
复现链接
none
复现步骤
不需要