markdown编辑器增加cherryMarkdown

* 使用cherryMarkdown替换editorMd

* 支持历史&边栏

* 优化代码&支持html格式渲染为预览格式&保存主题配置

* 修复drawio异常

* 优化drawio异常改法

* 自定义提示面板主题颜色

* drawio增加样式,并且更新到最新版本

* 增加代码块复制功能&&修复drawio渲染图片过大&&drawio生成图片背景改为透明

* 恢复原有markdown编辑器,新增cherry markdown编辑器

* 修复复制功能异常

* 修复drawio偶尔无法编辑

---------

Co-authored-by: zhangsheng.93 <zhangsheng.93@bytedance.com>
This commit is contained in:
张胜
2023-07-03 09:41:27 +08:00
committed by GitHub
parent 048135a2d9
commit 21fe4b631a
386 changed files with 254574 additions and 581 deletions

View File

@@ -24,37 +24,31 @@ import (
// Document struct.
type Document struct {
DocumentId int `orm:"pk;auto;unique;column(document_id)" json:"doc_id"`
DocumentName string `orm:"column(document_name);size(500);description(文档名称)" json:"doc_name"`
// Identify 文档唯一标识
Identify string `orm:"column(identify);size(100);index;null;default(null);description(唯一标识)" json:"identify"`
BookId int `orm:"column(book_id);type(int);index;description(关联bools表主键)" json:"book_id"`
ParentId int `orm:"column(parent_id);type(int);index;default(0);description(父级文档)" json:"parent_id"`
OrderSort int `orm:"column(order_sort);default(0);type(int);index;description(排序从小到大排序)" json:"order_sort"`
// Markdown markdown格式文档.
Markdown string `orm:"column(markdown);type(text);null;description(markdown内容)" json:"markdown"`
// Release 发布后的Html格式内容.
Release string `orm:"column(release);type(text);null;description(文章内容)" json:"release"`
// Content 未发布的 Html 格式内容.
Content string `orm:"column(content);type(text);null;description(文章内容)" json:"content"`
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add;description(创建时间)" json:"create_time"`
MemberId int `orm:"column(member_id);type(int);description(关系用户id)" json:"member_id"`
ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now;description(修改时间)" json:"modify_time"`
ModifyAt int `orm:"column(modify_at);type(int);description(修改人id)" json:"-"`
Version int64 `orm:"column(version);type(bigint);description(版本关联历史文档里的version)" json:"version"`
//是否展开子目录0 否/1 是 /2 空间节点,单击时展开下一级
IsOpen int `orm:"column(is_open);type(int);default(0);description(是否展开子目录 0阅读时关闭节点 1阅读时展开节点 2空目录 单击时会展开下级节点)" json:"is_open"`
ViewCount int `orm:"column(view_count);type(int);description(浏览量)" json:"view_count"`
AttachList []*Attachment `orm:"-" json:"attach"`
DocumentId int `orm:"pk;auto;unique;column(document_id)" json:"doc_id"`
DocumentName string `orm:"column(document_name);size(500);description(文档名称)" json:"doc_name"`
Identify string `orm:"column(identify);size(100);index;null;default(null);description(唯一标识)" json:"identify"` // Identify 文档唯一标识
BookId int `orm:"column(book_id);type(int);index;description(关联bools表主键)" json:"book_id"`
ParentId int `orm:"column(parent_id);type(int);index;default(0);description(父级文档)" json:"parent_id"`
OrderSort int `orm:"column(order_sort);default(0);type(int);index;description(排序从小到大排序)" json:"order_sort"`
Markdown string `orm:"column(markdown);type(text);null;description(markdown内容)" json:"markdown"` // Markdown markdown格式文档.
MarkdownTheme string `orm:"column(markdown_theme);size(50);default(theme__light);description(markdown主题)" json:"markdown_theme"`
Release string `orm:"column(release);type(text);null;description(文章内容)" json:"release"` // Release 发布后的Html格式内容.
Content string `orm:"column(content);type(text);null;description(文章内容)" json:"content"` // Content 未发布的 Html 格式内容.
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add;description(创建时间)" json:"create_time"`
MemberId int `orm:"column(member_id);type(int);description(关系用户id)" json:"member_id"`
ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now;description(修改时间)" json:"modify_time"`
ModifyAt int `orm:"column(modify_at);type(int);description(修改人id)" json:"-"`
Version int64 `orm:"column(version);type(bigint);description(版本关联历史文档里的version)" json:"version"`
IsOpen int `orm:"column(is_open);type(int);default(0);description(是否展开子目录 0阅读时关闭节点 1阅读时展开节点 2空目录 单击时会展开下级节点)" json:"is_open"` //是否展开子目录0 否/1 是 /2 空间节点,单击时展开下一级
ViewCount int `orm:"column(view_count);type(int);description(浏览量)" json:"view_count"`
AttachList []*Attachment `orm:"-" json:"attach"`
//i18n
Lang string `orm:"-"`
}
// 多字段唯一键
func (item *Document) TableUnique() [][]string {
return [][]string{
[]string{"book_id", "identify"},
}
return [][]string{{"book_id", "identify"}}
}
// TableName 获取对应数据库表名.
@@ -77,7 +71,7 @@ func NewDocument() *Document {
}
}
//根据文档ID查询指定文档.
// 根据文档ID查询指定文档.
func (item *Document) Find(id int) (*Document, error) {
if id <= 0 {
return item, ErrInvalidParameter
@@ -94,7 +88,7 @@ func (item *Document) Find(id int) (*Document, error) {
return item, nil
}
//插入和更新文档.
// 插入和更新文档.
func (item *Document) InsertOrUpdate(cols ...string) error {
o := orm.NewOrm()
item.DocumentName = utils.StripTags(item.DocumentName)
@@ -126,7 +120,7 @@ func (item *Document) InsertOrUpdate(cols ...string) error {
return nil
}
//根据文档识别编号和项目id获取一篇文档
// 根据文档识别编号和项目id获取一篇文档
func (item *Document) FindByIdentityFirst(identify string, bookId int) (*Document, error) {
o := orm.NewOrm()
@@ -135,7 +129,7 @@ func (item *Document) FindByIdentityFirst(identify string, bookId int) (*Documen
return item, err
}
//递归删除一个文档.
// 递归删除一个文档.
func (item *Document) RecursiveDocument(docId int) error {
o := orm.NewOrm()
@@ -163,7 +157,7 @@ func (item *Document) RecursiveDocument(docId int) error {
return nil
}
//将文档写入缓存
// 将文档写入缓存
func (item *Document) PutToCache() {
go func(m Document) {
@@ -181,7 +175,7 @@ func (item *Document) PutToCache() {
}(*item)
}
//清除缓存
// 清除缓存
func (item *Document) RemoveCache() {
go func(m Document) {
cache.Put("Document.Id."+strconv.Itoa(m.DocumentId), m, time.Second*3600)
@@ -192,7 +186,7 @@ func (item *Document) RemoveCache() {
}(*item)
}
//从缓存获取
// 从缓存获取
func (item *Document) FromCacheById(id int) (*Document, error) {
if err := cache.Get("Document.Id."+strconv.Itoa(id), &item); err == nil && item.DocumentId > 0 {
@@ -211,7 +205,7 @@ func (item *Document) FromCacheById(id int) (*Document, error) {
return item, err
}
//根据文档标识从缓存中查询文档
// 根据文档标识从缓存中查询文档
func (item *Document) FromCacheByIdentify(identify string, bookId int) (*Document, error) {
key := fmt.Sprintf("Document.BookId.%d.Identify.%s", bookId, identify)
@@ -229,7 +223,7 @@ func (item *Document) FromCacheByIdentify(identify string, bookId int) (*Documen
return item.FindByIdentityFirst(identify, bookId)
}
//根据项目ID查询文档列表.
// 根据项目ID查询文档列表.
func (item *Document) FindListByBookId(bookId int) (docs []*Document, err error) {
o := orm.NewOrm()
@@ -238,14 +232,14 @@ func (item *Document) FindListByBookId(bookId int) (docs []*Document, err error)
return
}
//判断文章是否存在
// 判断文章是否存在
func (item *Document) IsExist(documentId int) bool {
o := orm.NewOrm()
return o.QueryTable(item.TableNameWithPrefix()).Filter("document_id", documentId).Exist()
}
//发布单篇文档
// 发布单篇文档
func (item *Document) ReleaseContent() error {
item.Release = strings.TrimSpace(item.Content)
@@ -298,6 +292,9 @@ func (item *Document) Processor() *Document {
content.WriteString("</ul></div>")
if docQuery == nil {
docQuery, err = goquery.NewDocumentFromReader(content)
if err != nil {
logs.Error("goquery->NewDocumentFromReader err:%+v", err)
}
} else {
if selector := docQuery.Find("div.wiki-bottom").First(); selector.Size() > 0 {
selector.BeforeHtml(content.String()) //This branch should be a compatible branch.