gpt4 book ai didi

How correctly integrate angular-froala-wysiwyg and codemirror v5 to edit code?(如何正确地集成角度-Froala-wysiwyg和codemirror v5来编辑代码?)

转载 作者:bug小助手 更新时间:2023-10-25 17:43:55 27 4
gpt4 key购买 nike



I want edit a source code (javascript, json, etc.) in angular-froala-wysiwyg. So following step by step documentation https://froala.com/wysiwyg-editor/examples/code-mirror/, i have installed codemirror and included all plugins and styles, configured codemirror options. But still its doesn't work.

我想编辑一个源代码(Java脚本、JSON等)。在角-弗罗拉-所见即所得中。因此,按照逐步的文档https://froala.com/wysiwyg-editor/examples/code-mirror/,,我已经安装了codemirror,并包括了所有插件和样式,配置了codemirror选项。但它仍然不起作用。


app.module.ts

import 'froala-editor/js/plugins.pkgd.min.js';
import 'froala-editor/js/plugins/align.min.js';
import 'froala-editor/js/plugins/code_view.min.js';
import 'froala-editor/js/languages/ru.js';
import 'froala-editor/js/third_party/embedly.min';


styles.scss

@use 'froala-editor/css/plugins/code_view.min.css';
@use 'codemirror/lib/codemirror.css';
@use 'codemirror/theme/dracula.css';

component.html
<div class="froala-editor"
[froalaEditor]="froalaEditorConfig"
[formControl]="editorControl"
></div>

component.ts

import * as CodeMirror from 'codemirror';
import 'codemirror/mode/xml/xml';
import 'codemirror/mode/javascript/javascript.js';

this.froalaEditorConfig = {
key: 'my-key',
imagePaste: false,
imageUpload: false,
events: {},
language: 'ru',
attribution: false,
toolbarButtons: {
moreText: {
buttons: [
'bold',
'italic',
'underline',
'strikeThrough',
'subscript',
'superscript',
'fontFamily',
'fontSize',
'textColor',
'backgroundColor',
'inlineClass',
'inlineStyle',
'clearFormatting',
],
},
moreParagraph: {
buttons: [
'alignLeft',
'alignCenter',
'alignRight',
'formatOLSimple',
'alignJustify',
'formatOL',
'formatUL',
'paragraphFormat',
'paragraphStyle',
'lineHeight',
'outdent',
'indent',
'quote',
],
buttonsVisible: 3,
},
moreRich: {
buttons: ['insertLink', 'insertTable', 'specialCharacters', 'insertHR'],
buttonsVisible: 6,
},
moreMisc: {
buttons: ['undo', 'redo', 'html', 'help', 'fullscreen'],
align: 'right',
buttonsVisible: 5,
},
},
quickInsertButtons: ['embedly', 'table', 'ul', 'ol', 'hr'],
placeholderText: '',
enter: 0,
codeMirror: CodeMirror,
codeMirrorOptions: {
tabSize: 2,
lineNumbers: true,
mode: {
name: 'javascript',
json: true,
},
theme: 'dracula',
lineWrapping: true,
},
};

this.editorControl.patchValue(
JSON.stringify({
name: 'John',
age: 30,
car: null,
}),
);

Current result:
enter image description here

当前结果:在此处输入图像描述


Expected result:
enter image description here

预期结果:在此处输入图像描述


更多回答

why do you JSON.stringify( the object? just pass it as is

为什么你要把(物体)强化呢?只需原样通过即可

优秀答案推荐
更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com