Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Cozy Stack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
Factory
LLLE_Project
Cozy Stack
Commits
bddfcb3f
Commit
bddfcb3f
authored
3 years ago
by
Bruno Michel
Browse files
Options
Downloads
Patches
Plain Diff
Import notes with complex tables
parent
29a9e3ba
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
model/note/markdown.go
+65
-5
65 additions, 5 deletions
model/note/markdown.go
with
65 additions
and
5 deletions
model/note/markdown.go
+
65
−
5
View file @
bddfcb3f
...
@@ -56,7 +56,16 @@ func markdownSerializer(images []*Image) *markdown.Serializer {
...
@@ -56,7 +56,16 @@ func markdownSerializer(images []*Image) *markdown.Serializer {
state
.
RenderContent
(
node
)
state
.
RenderContent
(
node
)
},
},
"table"
:
func
(
state
*
markdown
.
SerializerState
,
node
,
_parent
*
model
.
Node
,
_index
int
)
{
"table"
:
func
(
state
*
markdown
.
SerializerState
,
node
,
_parent
*
model
.
Node
,
_index
int
)
{
state
.
Write
(
"________________________________________{.table}
\n\n
"
)
var
attrs
string
if
node
.
Attrs
[
"layout"
]
==
"wide"
{
attrs
+=
` layout="wide"`
}
else
if
node
.
Attrs
[
"layout"
]
==
"full-width"
{
attrs
+=
` layout="full-width"`
}
if
node
.
Attrs
[
"isNumberColumnEnabled"
]
==
true
{
attrs
+=
" number=true"
}
state
.
Write
(
"________________________________________{.table"
+
attrs
+
"}
\n\n
"
)
state
.
RenderContent
(
node
)
state
.
RenderContent
(
node
)
state
.
EnsureNewLine
()
state
.
EnsureNewLine
()
state
.
Write
(
"________________________________________{.tableEnd}
\n
"
)
state
.
Write
(
"________________________________________{.tableEnd}
\n
"
)
...
@@ -69,11 +78,13 @@ func markdownSerializer(images []*Image) *markdown.Serializer {
...
@@ -69,11 +78,13 @@ func markdownSerializer(images []*Image) *markdown.Serializer {
state
.
CloseBlock
(
node
)
state
.
CloseBlock
(
node
)
},
},
"tableHeader"
:
func
(
state
*
markdown
.
SerializerState
,
node
,
_parent
*
model
.
Node
,
_index
int
)
{
"tableHeader"
:
func
(
state
*
markdown
.
SerializerState
,
node
,
_parent
*
model
.
Node
,
_index
int
)
{
state
.
Write
(
"____________________{.tableHeader}
\n\n
"
)
attrs
:=
cellMarkup
(
node
)
state
.
Write
(
"____________________{.tableHeader"
+
attrs
+
"}
\n\n
"
)
state
.
RenderContent
(
node
)
state
.
RenderContent
(
node
)
},
},
"tableCell"
:
func
(
state
*
markdown
.
SerializerState
,
node
,
_parent
*
model
.
Node
,
_index
int
)
{
"tableCell"
:
func
(
state
*
markdown
.
SerializerState
,
node
,
_parent
*
model
.
Node
,
_index
int
)
{
state
.
Write
(
"____________________{.tableCell}
\n\n
"
)
attrs
:=
cellMarkup
(
node
)
state
.
Write
(
"____________________{.tableCell"
+
attrs
+
"}
\n\n
"
)
state
.
RenderContent
(
node
)
state
.
RenderContent
(
node
)
},
},
"status"
:
func
(
state
*
markdown
.
SerializerState
,
node
,
_parent
*
model
.
Node
,
_index
int
)
{
"status"
:
func
(
state
*
markdown
.
SerializerState
,
node
,
_parent
*
model
.
Node
,
_index
int
)
{
...
@@ -139,11 +150,45 @@ func markdownSerializer(images []*Image) *markdown.Serializer {
...
@@ -139,11 +150,45 @@ func markdownSerializer(images []*Image) *markdown.Serializer {
return
markdown
.
NewSerializer
(
nodes
,
marks
)
return
markdown
.
NewSerializer
(
nodes
,
marks
)
}
}
func
cellMarkup
(
node
*
model
.
Node
)
string
{
var
attrs
string
if
color
,
ok
:=
node
.
Attrs
[
"background"
]
.
(
string
);
ok
&&
color
[
0
]
==
'#'
{
attrs
+=
fmt
.
Sprintf
(
` background="%s"`
,
color
)
}
if
span
,
ok
:=
node
.
Attrs
[
"rowspan"
]
.
(
float64
);
ok
&&
span
>
1
{
attrs
+=
fmt
.
Sprintf
(
" rowspan=%d"
,
int
(
span
))
}
if
span
,
ok
:=
node
.
Attrs
[
"colspan"
]
.
(
float64
);
ok
&&
span
>
1
{
attrs
+=
fmt
.
Sprintf
(
" colspan=%d"
,
int
(
span
))
}
return
attrs
}
func
isTableCell
(
item
*
StackItem
)
bool
{
func
isTableCell
(
item
*
StackItem
)
bool
{
name
:=
item
.
Type
.
Name
name
:=
item
.
Type
.
Name
return
name
==
"tableHeader"
||
name
==
"tableCell"
return
name
==
"tableHeader"
||
name
==
"tableCell"
}
}
func
cellAttributes
(
node
ast
.
Node
)
map
[
string
]
interface
{}
{
background
,
ok
:=
node
.
AttributeString
(
"background"
)
if
!
ok
{
background
=
nil
}
colspan
,
ok
:=
node
.
AttributeString
(
"colspan"
)
if
!
ok
{
colspan
=
1
}
rowspan
,
ok
:=
node
.
AttributeString
(
"rowspan"
)
if
!
ok
{
rowspan
=
1
}
return
map
[
string
]
interface
{}{
"background"
:
background
,
"colspan"
:
colspan
,
"rowspan"
:
rowspan
,
}
}
func
markdownNodeMapper
()
NodeMapper
{
func
markdownNodeMapper
()
NodeMapper
{
vanilla
:=
DefaultNodeMapper
vanilla
:=
DefaultNodeMapper
return
NodeMapper
{
return
NodeMapper
{
...
@@ -181,9 +226,22 @@ func markdownNodeMapper() NodeMapper {
...
@@ -181,9 +226,22 @@ func markdownNodeMapper() NodeMapper {
return
nil
return
nil
}
}
var
attrs
map
[
string
]
interface
{}
switch
tableType
{
switch
tableType
{
case
"table"
:
case
"table"
:
// Nothing to do
number
,
ok
:=
node
.
AttributeString
(
"number"
)
if
!
ok
{
number
=
false
}
layout
,
ok
:=
node
.
AttributeString
(
"layout"
)
if
!
ok
{
layout
=
"default"
}
attrs
=
map
[
string
]
interface
{}{
"__autosize"
:
false
,
"isNumberColumnEnabled"
:
number
,
"layout"
:
layout
,
}
case
"tableEnd"
:
case
"tableEnd"
:
if
isTableCell
(
state
.
Top
())
{
if
isTableCell
(
state
.
Top
())
{
if
_
,
err
:=
state
.
CloseNode
();
err
!=
nil
{
// Cell
if
_
,
err
:=
state
.
CloseNode
();
err
!=
nil
{
// Cell
...
@@ -212,12 +270,14 @@ func markdownNodeMapper() NodeMapper {
...
@@ -212,12 +270,14 @@ func markdownNodeMapper() NodeMapper {
return
err
return
err
}
}
}
}
attrs
=
cellAttributes
(
node
)
case
"tableCell"
:
case
"tableCell"
:
if
isTableCell
(
state
.
Top
())
{
if
isTableCell
(
state
.
Top
())
{
if
_
,
err
:=
state
.
CloseNode
();
err
!=
nil
{
if
_
,
err
:=
state
.
CloseNode
();
err
!=
nil
{
return
err
return
err
}
}
}
}
attrs
=
cellAttributes
(
node
)
default
:
default
:
return
nil
return
nil
}
}
...
@@ -225,7 +285,7 @@ func markdownNodeMapper() NodeMapper {
...
@@ -225,7 +285,7 @@ func markdownNodeMapper() NodeMapper {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
state
.
OpenNode
(
typ
,
nil
)
state
.
OpenNode
(
typ
,
attrs
)
return
nil
return
nil
},
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment