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
797accbc
Unverified
Commit
797accbc
authored
Nov 15, 2022
by
Stephen Zhou
Committed by
GitHub
Nov 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: parser for horizontal rule (#477)
* feat: parser for horizontal rule * chore: revert
parent
66f9bc48
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
1 deletion
+55
-1
marked.test.ts
web/src/labs/marked/marked.test.ts
+23
-0
HorizontalRules.ts
web/src/labs/marked/parser/HorizontalRules.ts
+15
-0
index.ts
web/src/labs/marked/parser/index.ts
+13
-1
memo-content.less
web/src/less/memo-content.less
+4
-0
No files found.
web/src/labs/marked/marked.test.ts
View file @
797accbc
...
...
@@ -4,6 +4,29 @@ import { unescape } from "lodash-es";
import
{
marked
}
from
"."
;
describe
(
"test marked parser"
,
()
=>
{
test
(
"horizontal rule"
,
()
=>
{
const
tests
=
[
{
markdown
:
`To create a horizontal rule, use three or more asterisks (***), dashes (---), or underscores (___) on a line by themselves.
---
This is some text after the horizontal rule.
___
This is some text after the horizontal rule.
***
This is some text after the horizontal rule.`
,
want
:
`<p>To create a horizontal rule, use three or more asterisks (<em>*</em>), dashes (---), or underscores (___) on a line by themselves.</p>
<hr>
<p>This is some text after the horizontal rule.</p>
<hr>
<p>This is some text after the horizontal rule.</p>
<hr>
<p>This is some text after the horizontal rule.</p>`
,
},
];
for
(
const
t
of
tests
)
{
expect
(
unescape
(
marked
(
t
.
markdown
))).
toBe
(
t
.
want
);
}
});
test
(
"parse code block"
,
()
=>
{
const
tests
=
[
{
...
...
web/src/labs/marked/parser/HorizontalRules.ts
0 → 100644
View file @
797accbc
export
const
HORIZONTAL_RULES_REG
=
/^---
\n
|^
\*\*\*\n
|^___
\n
/
;
export
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
matchResult
=
rawStr
.
match
(
HORIZONTAL_RULES_REG
);
if
(
!
matchResult
)
{
return
rawStr
;
}
return
`<hr>\n`
;
};
export
default
{
name
:
"horizontal rules"
,
regex
:
HORIZONTAL_RULES_REG
,
renderer
,
};
web/src/labs/marked/parser/index.ts
View file @
797accbc
...
...
@@ -15,6 +15,7 @@ import PlainText from "./PlainText";
import
Table
from
"./Table"
;
import
BoldEmphasis
from
"./BoldEmphasis"
;
import
Blockquote
from
"./Blockquote"
;
import
HorizontalRules
from
"./HorizontalRules"
;
export
{
CODE_BLOCK_REG
}
from
"./CodeBlock"
;
export
{
TODO_LIST_REG
}
from
"./TodoList"
;
...
...
@@ -23,8 +24,19 @@ 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
=
[
Table
,
CodeBlock
,
Blockquote
,
TodoList
,
DoneList
,
OrderedList
,
UnorderedList
,
Paragraph
];
export
const
blockElementParserList
=
[
HorizontalRules
,
Table
,
CodeBlock
,
Blockquote
,
TodoList
,
DoneList
,
OrderedList
,
UnorderedList
,
Paragraph
,
];
export
const
inlineElementParserList
=
[
Image
,
BoldEmphasis
,
Bold
,
Emphasis
,
Link
,
InlineCode
,
PlainLink
,
Tag
,
PlainText
];
export
const
parserList
=
[...
blockElementParserList
,
...
inlineElementParserList
];
web/src/less/memo-content.less
View file @
797accbc
...
...
@@ -81,6 +81,10 @@
blockquote {
@apply border-l-4 pl-2 text-gray-400;
}
hr {
@apply my-1;
}
}
> .expand-btn-container {
...
...
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