Closed chunyangyang closed 2 years ago
当前信息我也无法判断
后端数据:
### 吹过的风更改
#
dfsdf是
```javascript
dfdsf
dsfdsf
npm run dev
```
/
> 第三方
djkfdksjfh
dfsdfdscasE
是的
**x**Space
`**SS杀杀杀**`
是的
是的
:::info
:::
DFD
:::success
:::
| ddd |
| |
| --- | --- | --- |
| | | |
| | | |
# 发发生的f
DFDS
[]()
---
目前兼容代码
2.光标问题,我是用的example/react的代码,去掉了评论相关
# <br />
dfsdf是
dfdsf
dsfdsf
npm run dev
/
> 第三方
djkfdksjfh<br />dfsdfdscasE<br />是的
**x**Space<br />`**SS杀杀杀**`<br />是的<br />是的
:::info
:::
DFD
:::success
:::
| ddd | <br /> | |
| --- | --- | --- |
| | | |
| | | |
# 发发生的f
DFDS<br />[]()
---</p>
有办法处理吗
要不你给个最小复现吧
engine\src\change\index.ts
setMarkdown
markdown.enable(['paragraph', 'html_inline', 'newline'])
有些语法没有开启转换 image ,table,header
这些都是在插件里面启用的 from 阿里邮箱 iPhone------------------------------------------------------------------ @.> 日 期:2022年09月06日 12:20:39 @.> @.>; @.> 主 题:Re: [red-axe/am-editor] 由于后端返回的数据有两种格式一种是html,一种是mardown语法,有没有办法处理下数据 (Issue #246)
engine\src\change\index.ts setMarkdown markdown.enable(['paragraph', 'html_inline', 'newline']) 有些语法没有开启转换 image ,table,header — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
是需要调用这个API启用吧
engine.on('markdown-it', (markdown) => {
markdown.enable('markdown-it 插件名称');
markdown.use(markdown - it插件);
});
插件内是调用了的
setMarkdown 之后,需要在内容最后按下 回车键 才会渲染 MarkdownShow
更新一下到最新版本再试试
最新版测试没问题
复现代码不怎么好整理,我看了你的源码,是在协同的时候,值是在这个路径下 packages\engine\src\ot\index.ts的syncValue方法设置的
syncValue(defaultValue?: string) {
const { doc, engine } = this;
if (!doc) return;
// 除了div 和 selection-data 外 还必须有其它节点
if (doc.type && Array.isArray(doc.data) && doc.data.length > 2) {
// 远端有数据就设置数据到当前编辑器
this.engine.setJsonValue(doc.data);
return;
}
// 如果有设置默认值,就设置编辑器的值
if (defaultValue) engine.setValue(defaultValue);
// 没有数据,就把当前编辑器值提交
doc.on('create', () => {
const data = toJSON0(engine.container);
(doc as Doc).submitOp(
[
{
p: [],
oi: data,
},
],
{
source: this.clientId,
},
);
});
}
之前我没有做协同是自己做了个判断,代码如下:
// 非协同编辑,设置编辑器值,异步渲染后回调
// console.log(' inflateValue', inflateValue);
// console.log(' inflateValue.substring(0, 1) == "<"==>', inflateValue.indexOf('data-id=') != -1);
if (inflateValue.indexOf('data-id=') != -1) {
engine.current.setValue(inflateValue, (count) => {
console.log("setValue loaded:", count);
if (onLoad) onLoad(engine.current!);
return setLoading(false);
});
} else {
engine.current.setMarkdown(inflateValue, (count) => {
console.log("setValue loaded:", count);
if (onLoad) onLoad(engine.current!);
return setLoading(false);
});
}`
只能这样看看能不能先转换成 value 了
import { convertMarkdown, createMarkdownIt, Parser } from '@aomao/engine'
const markdown = createMarkdownIt(engine, 'zero');
markdown.enable(['paragraph', 'html_inline', 'newline']);
const tokens = markdown.parse(text, {});
if (tokens.length === 0) return;
const html = convertMarkdown(this.engine, markdown, tokens);
const parser = new Parser(value, engine)
const value = parser.toValue(engine.schema, engine.conversion)
只能这样看看能不能先转换成 value 了 协同赋值是你这边赋值是你里面写死了这样赋值,我要怎么加你这段代码呢?
// 除了div 和 selection-data 外 还必须有其它节点 if (doc.type && Array.isArray(doc.data) && doc.data.length > 2) { // 远端有数据就设置数据到当前编辑器 this.engine.setJsonValue(doc.data); return; }```
你获取到后端的md数据后,用上面代码转成 value 格式。然后 https://github.com/red-axe/am-editor/blob/master/examples/react/components/editor/index.tsx#L194 这里把这个 value 传过去,ot 那边如果没有值就会使用这个值设置到 ot 当中,ot 就会更新到编辑器上
你获取到后端的md数据后,用上面代码转成 value 格式。然后 https://github.com/red-axe/am-editor/blob/master/examples/react/components/editor/index.tsx#L194 这里把这个 value 传过去,ot 那边如果没有值就会使用这个值设置到 ot 当中,ot 就会更新到编辑器上
按照上面的设置还是不行,可以麻烦看下原因吗?
我的代码如下:
//inflateValue是后端返回的数据
const markdown = createMarkdownIt(engine.current, 'zero');
markdown.enable(['paragraph', 'html_inline', 'newline']);
const tokens = markdown.parse(inflateValue, {});
if (tokens.length === 0) return;
const html = convertMarkdown(engine.current, markdown, tokens);
const parser = new Parser(inflateValue, engine.current)
inflateValue = parser.toValue(engine.current.schema, engine.current.conversion)
console.log('html==》', html);
console.log('inflateValue==》', inflateValue);
返回的结果如下:
html==》 <p><p data-id="p838747a-j2QFl1fj">### 这是一段代码</p><p data-id="p838747a-2BiZZIhQ"><code>json { &quot;appName&quot;: &quot;tech-main&quot;, &quot;origin&quot;: &quot;/api/usm/&quot;, &quot;target&quot;: &quot;<a href="http://10.219.12.51:905/microservices-usm-spring-cloud-starter&quot;">http://10.219.12.51:905/microservices-usm-spring-cloud-starter&quot;</a>, &quot;rewriteFrom&quot;: &quot;^/api/usm/&quot;, &quot;rewriteTo&quot;: &quot;/Api/usm/&quot;, &quot;description&quot;: &quot;&quot; } </code></p><p data-id="p838747a-nf2JfKn3">复合弓得到的单独单独的4500</p><p data-id="p838747a-US2pQWT4">的</p><p data-id="p838747a-KJKYmjkU">你是搜索</p><p data-id="p838747a-ITIcdSDS"><cursor /><br /></p><p data-id="p838747a-1j6EjRkc"><br /></p></p>
inflateValue==》 <p data-id="p838747a-j2QFl1fj">### 这是一段代码</p><p data-id="p838747a-2BiZZIhQ"><code>json { "appName": "tech-main", "origin": "/api/usm/", "target": "http://10.219.12.51:905/microservices-usm-spring-cloud-starter", "rewriteFrom": "^/api/usm/", "rewriteTo": "/Api/usm/", "description": "" } </code></p><p data-id="p838747a-nf2JfKn3">复合弓得到的单独单独的4500</p><p data-id="p838747a-US2pQWT4">的</p><p data-id="p838747a-KJKYmjkU">你是搜索</p><p data-id="p838747a-ITIcdSDS"><span data-element="cursor"></span><br /></p><p data-id="p838747a-1j6EjRkc"><br /></p>
页面效果如果:
### 这是一段代码
json { "appName": "tech-main", "origin": "/api/usm/", "target": "http://10.219.12.51:905/microservices-usm-spring-cloud-starter", "rewriteFrom": "^/api/usm/", "rewriteTo": "/Api/usm/", "description": "" }
复合弓得到的单独单独的4500
的
你是搜索
还有这种 code不支持
code:`Ctrl+F`
你获取到后端的md数据后,用上面代码转成 value 格式。然后 https://github.com/red-axe/am-editor/blob/master/examples/react/components/editor/index.tsx#L194 这里把这个 value 传过去,ot 那边如果没有值就会使用这个值设置到 ot 当中,ot 就会更新到编辑器上
按照上面的设置还是不行,可以麻烦看下原因吗?
我的代码如下:
//inflateValue是后端返回的数据 const markdown = createMarkdownIt(engine.current, 'zero'); markdown.enable(['paragraph', 'html_inline', 'newline']); const tokens = markdown.parse(inflateValue, {}); if (tokens.length === 0) return; const html = convertMarkdown(engine.current, markdown, tokens); const parser = new Parser(inflateValue, engine.current) inflateValue = parser.toValue(engine.current.schema, engine.current.conversion) console.log('html==》', html); console.log('inflateValue==》', inflateValue);
返回的结果如下:
html==》 <p><p data-id="p838747a-j2QFl1fj">### 这是一段代码</p><p data-id="p838747a-2BiZZIhQ"><code>json { &quot;appName&quot;: &quot;tech-main&quot;, &quot;origin&quot;: &quot;/api/usm/&quot;, &quot;target&quot;: &quot;<a href="http://10.219.12.51:905/microservices-usm-spring-cloud-starter&quot;">http://10.219.12.51:905/microservices-usm-spring-cloud-starter&quot;</a>, &quot;rewriteFrom&quot;: &quot;^/api/usm/&quot;, &quot;rewriteTo&quot;: &quot;/Api/usm/&quot;, &quot;description&quot;: &quot;&quot; } </code></p><p data-id="p838747a-nf2JfKn3">复合弓得到的单独单独的4500</p><p data-id="p838747a-US2pQWT4">的</p><p data-id="p838747a-KJKYmjkU">你是搜索</p><p data-id="p838747a-ITIcdSDS"><cursor /><br /></p><p data-id="p838747a-1j6EjRkc"><br /></p></p> inflateValue==》 <p data-id="p838747a-j2QFl1fj">### 这是一段代码</p><p data-id="p838747a-2BiZZIhQ"><code>json { "appName": "tech-main", "origin": "/api/usm/", "target": "http://10.219.12.51:905/microservices-usm-spring-cloud-starter", "rewriteFrom": "^/api/usm/", "rewriteTo": "/Api/usm/", "description": "" } </code></p><p data-id="p838747a-nf2JfKn3">复合弓得到的单独单独的4500</p><p data-id="p838747a-US2pQWT4">的</p><p data-id="p838747a-KJKYmjkU">你是搜索</p><p data-id="p838747a-ITIcdSDS"><span data-element="cursor"></span><br /></p><p data-id="p838747a-1j6EjRkc"><br /></p>
页面效果如果:
### 这是一段代码 json { "appName": "tech-main", "origin": "/api/usm/", "target": "http://10.219.12.51:905/microservices-usm-spring-cloud-starter", "rewriteFrom": "^/api/usm/", "rewriteTo": "/Api/usm/", "description": "" } 复合弓得到的单独单独的4500 的 你是搜索
更新到最新版本了吗?
是2.9.37
import { createMarkdownIt, convertMarkdown, Parser } from '@aomao/engine';
let inflateValue = '### This is Heading3';
const markdown = createMarkdownIt(engine, 'zero');
markdown.enable(['paragraph', 'html_inline', 'newline']);
const tokens = markdown.parse(inflateValue, {});
if (tokens.length === 0) return;
const html = convertMarkdown(engine, markdown, tokens);
const parser = new Parser(inflateValue, engine)
inflateValue = parser.toValue(engine.schema, engine.conversion)
console.log('html==》', html);
console.log('inflateValue==》', inflateValue);
1.项目有些文档数据是存储的mardown语法,导致页面渲染需要兼容两种语法 现在协同如果是mardown语法会渲染不了,求帮助 2.使用协同没有光标是什么原因?