bro*_*ros 9 html css reactjs react-markdown
我在 React Markdown 中传递各种数量的数据,例如表格、列表和 h 标签。我想知道如何单独设置每个元素的样式。我到处搜索,但没有提到如何设置元素的样式,而不仅仅是粗体或强调等。我想我可以在 ReactMarkdown 组件中传递一个类名来设置它的样式,但这不仅仅是为组件提供样式。如何设计其中的各种元素的样式?
const ReadMePreviewer = ({ readMeCode }) => {
return (
<ReactMarkdown
plugins={[[gfm, { singleTilde: false }]]}
className={style.reactMarkDown}
// className={style.reactMarkDownRemovingExtraGlobal}
renderers={renderers}
source={readMeCode}
/>
);
};Run Code Online (Sandbox Code Playgroud)
Mad*_*rus 21
这就是我让它为我工作的方式。我使用 CSS 明确地执行此操作,而不是使用 SCSS 或 CSS-in-JS 等,以免使用额外的库或 webpack/babel 微调来打扰您:
使用您的样式创建一个单独的markdown-styles.module.cssCSS 模块文件,例如,
.reactMarkDown {
// some root styles here
}
.reactMarkDown ul {
margin-top: 1em;
margin-bottom: 1em;
list-style: disc outside none;
}
.reactMarkDown ul li {
margin-left: 2em;
display: list-item;
text-align: -webkit-match-parent;
}
// your other styles but all under .reactMarkDown blocks
Run Code Online (Sandbox Code Playgroud)
然后您可以将其导入到您的组件中并像您一样使用:
import style from './markdown-styles.module.css';
...
const ReadMePreviewer = ({ readMeCode }) => {
return (
<ReactMarkdown
plugins={[[gfm, { singleTilde: false }]]}
className={style.reactMarkDown}
renderers={renderers}
children={readMeCode}
/>
);
};
Run Code Online (Sandbox Code Playgroud)
这似乎可以包装 into new line
App.css
.markdown code {
display: block;
white-space: pre-wrap;
}
Run Code Online (Sandbox Code Playgroud)
Component:
<ReactMarkdown className="markdown">{page.Content}</ReactMarkdown>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19679 次 |
| 最近记录: |