私は回避策を見つけました。 blockRendererFnのmarkdown codeblockをdandで検出しています。
// use blockRedererFn
<Editor
blockRendererFn={(block) => blockRenderer(block, this.state.editorState)}
editorState={this.state.editorState}
/>;
// detect code block and add fontFamily: monospace
// Example
//
// ```
// here
// ```
function blockRenderer(contentBlock, editorState) {
const type = contentBlock.getType();
if (type === "unstyled") {
const allText = editorState.getCurrentContent().getPlainText();
const allCount = countCodeBlockHeader(allText);
if (allCount > 0 && allCount % 2 === 0) {
const contentText = contentBlock.getText();
const [before, after] = allText.split(contentText);
const beforeCount = countCodeBlockHeader(before);
const afterCount = countCodeBlockHeader(after);
if (beforeCount % 2 === 1) {
if (afterCount % 2 === 1) {
return {
component: (_props) => {
return <code style={{
fontFamily: "monospace",
direction: "ltr",
unicodeBidi: "bidi-override",
}}>{contentText}</code>;
},
editable: true
};
}
}
}
}
}
function countCodeBlockHeader(text) {
return text
.split("\n")
.filter(l => l.match(new RegExp("^(```)")))
.length;
}
でも汚れています。
コンテンツブロック(色の例のような)に強調テキストを実装できますが、生のテキストからコードブロック構文を検出して装飾するのはまだ難しいです。 – mizchi
未加工テキストからコードブロックを検出する必要があることがわかりません。未処理のテキストを検出してコード構文を適用すると、新しいブロック(未加工テキストなし)が「コードブロック」であることをどのように伝えることができますか? –