Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
1ea74dfd
Unverified
Commit
1ea74dfd
authored
Dec 04, 2022
by
boojack
Committed by
GitHub
Dec 04, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: remove table syntax (#669)
parent
53cf6ebb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1 addition
and
95 deletions
+1
-95
marked.test.ts
web/src/labs/marked/marked.test.ts
+0
-37
Table.ts
web/src/labs/marked/parser/Table.ts
+0
-45
index.ts
web/src/labs/marked/parser/index.ts
+1
-13
No files found.
web/src/labs/marked/marked.test.ts
View file @
1ea74dfd
...
...
@@ -157,43 +157,6 @@ console.log("hello world!")
expect
(
unescape
(
marked
(
t
.
markdown
))).
toBe
(
t
.
want
);
}
});
test
(
"parse table"
,
()
=>
{
const
tests
=
[
{
markdown
:
`text above the table
| a | b | c |
|---|---|---|
| 1 | 2 | 3 |
| 4 | 5 | 6 |
text below the table
`
,
want
:
`<p>text above the table</p>
<table>
<thead>
<tr>
<th>a</th><th>b</th><th>c</th>
</tr>
</thead>
<tbody>
<tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr>
</tbody>
</table>
<p>text below the table</p>
`
,
},
{
markdown
:
`| a | b | c |
| 1 | 2 | 3 |
| 4 | 5 | 6 |`
,
want
:
`<p>| a | b | c |</p>
<p>| 1 | 2 | 3 |</p>
<p>| 4 | 5 | 6 |</p>`
,
},
];
for
(
const
t
of
tests
)
{
expect
(
unescape
(
marked
(
t
.
markdown
))).
toBe
(
t
.
want
);
}
});
test
(
"parse full width space"
,
()
=>
{
const
tests
=
[
{
...
...
web/src/labs/marked/parser/Table.ts
deleted
100644 → 0
View file @
53cf6ebb
/**
* Match markdown table
* example:
* | a | b | c |
* |---|---|---|
* | 1 | 2 | 3 |
* | 4 | 5 | 6 |
*/
export
const
TABLE_REG
=
/^
(\|
.*
\|)(?:(?:\n(?:\|
-*
)
+
\|))((?:\n\|
.*
\|)
+
)(\n?)
/
;
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
matchResult
=
rawStr
.
match
(
TABLE_REG
);
if
(
!
matchResult
)
{
return
rawStr
;
}
const
tableHeader
=
matchResult
[
1
]
.
split
(
"|"
)
.
filter
((
str
)
=>
str
!==
""
)
.
map
((
str
)
=>
str
.
trim
());
const
tableBody
=
matchResult
[
2
]
.
trim
()
.
split
(
"
\n
"
)
.
map
((
str
)
=>
str
.
split
(
"|"
)
.
filter
((
str
)
=>
str
!==
""
)
.
map
((
str
)
=>
str
.
trim
())
);
return
`<table>
<thead>
<tr>
${
tableHeader
.
map
((
str
)
=>
`<th>
${
str
}
</th>`
).
join
(
""
)}
</tr>
</thead>
<tbody>
${
tableBody
.
map
((
row
)
=>
`<tr>
${
row
.
map
((
str
)
=>
`<td>
${
str
}
</td>`
).
join
(
""
)}
</tr>`
).
join
(
""
)}
</tbody>
</table>
${
matchResult
[
3
]}
`
;
};
export
default
{
name
:
"table"
,
regex
:
TABLE_REG
,
renderer
,
};
web/src/labs/marked/parser/index.ts
View file @
1ea74dfd
...
...
@@ -12,7 +12,6 @@ import Emphasis from "./Emphasis";
import
PlainLink
from
"./PlainLink"
;
import
InlineCode
from
"./InlineCode"
;
import
PlainText
from
"./PlainText"
;
import
Table
from
"./Table"
;
import
BoldEmphasis
from
"./BoldEmphasis"
;
import
Blockquote
from
"./Blockquote"
;
import
HorizontalRules
from
"./HorizontalRules"
;
...
...
@@ -24,20 +23,9 @@ export { DONE_LIST_REG } from "./DoneList";
export
{
TAG_REG
}
from
"./Tag"
;
export
{
IMAGE_REG
}
from
"./Image"
;
export
{
LINK_REG
}
from
"./Link"
;
export
{
TABLE_REG
}
from
"./Table"
;
export
{
HORIZONTAL_RULES_REG
}
from
"./HorizontalRules"
;
// The order determines the order of execution.
export
const
blockElementParserList
=
[
HorizontalRules
,
Table
,
CodeBlock
,
Blockquote
,
TodoList
,
DoneList
,
OrderedList
,
UnorderedList
,
Paragraph
,
];
export
const
blockElementParserList
=
[
HorizontalRules
,
CodeBlock
,
Blockquote
,
TodoList
,
DoneList
,
OrderedList
,
UnorderedList
,
Paragraph
];
export
const
inlineElementParserList
=
[
Image
,
BoldEmphasis
,
Bold
,
Emphasis
,
Link
,
InlineCode
,
PlainLink
,
Strikethrough
,
Tag
,
PlainText
];
export
const
parserList
=
[...
blockElementParserList
,
...
inlineElementParserList
];
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment