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
72daa4e1
Unverified
Commit
72daa4e1
authored
Dec 22, 2022
by
boojack
Committed by
GitHub
Dec 22, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support heading syntax (#827)
parent
54702db9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
17 deletions
+48
-17
marked.test.ts
web/src/labs/marked/marked.test.ts
+5
-17
Heading.ts
web/src/labs/marked/parser/Heading.ts
+25
-0
index.ts
web/src/labs/marked/parser/index.ts
+2
-0
memo-content.less
web/src/less/memo-content.less
+16
-0
No files found.
web/src/labs/marked/marked.test.ts
View file @
72daa4e1
...
@@ -156,27 +156,15 @@ console.log("hello world!")
...
@@ -156,27 +156,15 @@ console.log("hello world!")
expect
(
unescape
(
marked
(
t
.
markdown
))).
toBe
(
t
.
want
);
expect
(
unescape
(
marked
(
t
.
markdown
))).
toBe
(
t
.
want
);
}
}
});
});
test
(
"parse
tags
"
,
()
=>
{
test
(
"parse
heading
"
,
()
=>
{
const
tests
=
[
const
tests
=
[
{
{
markdown
:
`#123 `
,
markdown
:
`#
123 `
,
want
:
`<
p><span class='tag-span'>#123</span> </p
>`
,
want
:
`<
h1>123 </h1
>`
,
},
},
{
{
markdown
:
`#123#asd`
,
markdown
:
`## 123 `
,
want
:
`<p><span class='tag-span'>#123</span><span class='tag-span'>#asd</span></p>`
,
want
:
`<h2>123 </h2>`
,
},
{
markdown
:
`#123`
,
want
:
`<p><span class='tag-span'>#123</span></p>`
,
},
{
markdown
:
`123123#123`
,
want
:
`<p>123123<span class='tag-span'>#123</span></p>`
,
},
{
markdown
:
`123123 #123`
,
want
:
`<p>123123 <span class='tag-span'>#123</span></p>`
,
},
},
];
];
for
(
const
t
of
tests
)
{
for
(
const
t
of
tests
)
{
...
...
web/src/labs/marked/parser/Heading.ts
0 → 100644
View file @
72daa4e1
import
{
escape
}
from
"lodash"
;
export
const
HEADING_REG
=
/^
(
#+
)
([^\n]
+
)
/
;
const
matcher
=
(
rawStr
:
string
)
=>
{
const
matchResult
=
rawStr
.
match
(
HEADING_REG
);
return
matchResult
;
};
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
matchResult
=
matcher
(
rawStr
);
if
(
!
matchResult
)
{
return
rawStr
;
}
const
level
=
matchResult
[
1
].
length
;
return
`<h
${
level
}
>
${
escape
(
matchResult
[
2
])}
</h
${
level
}
>`
;
};
export
default
{
name
:
"heading"
,
regex
:
HEADING_REG
,
matcher
,
renderer
,
};
web/src/labs/marked/parser/index.ts
View file @
72daa4e1
...
@@ -17,6 +17,7 @@ import BoldEmphasis from "./BoldEmphasis";
...
@@ -17,6 +17,7 @@ import BoldEmphasis from "./BoldEmphasis";
import
Blockquote
from
"./Blockquote"
;
import
Blockquote
from
"./Blockquote"
;
import
HorizontalRules
from
"./HorizontalRules"
;
import
HorizontalRules
from
"./HorizontalRules"
;
import
Strikethrough
from
"./Strikethrough"
;
import
Strikethrough
from
"./Strikethrough"
;
import
Heading
from
"./Heading"
;
export
{
TAG_REG
}
from
"./Tag"
;
export
{
TAG_REG
}
from
"./Tag"
;
export
{
LINK_REG
}
from
"./Link"
;
export
{
LINK_REG
}
from
"./Link"
;
...
@@ -26,6 +27,7 @@ export const blockElementParserList = [
...
@@ -26,6 +27,7 @@ export const blockElementParserList = [
Br
,
Br
,
CodeBlock
,
CodeBlock
,
Blockquote
,
Blockquote
,
Heading
,
TodoList
,
TodoList
,
DoneList
,
DoneList
,
OrderedList
,
OrderedList
,
...
...
web/src/less/memo-content.less
View file @
72daa4e1
...
@@ -4,6 +4,22 @@
...
@@ -4,6 +4,22 @@
> .memo-content-text {
> .memo-content-text {
@apply w-full max-w-full word-break text-base leading-6;
@apply w-full max-w-full word-break text-base leading-6;
> h1 {
@apply text-5xl leading-normal font-bold;
}
> h2 {
@apply text-3xl leading-normal font-medium;
}
> h3 {
@apply text-xl leading-normal font-medium;
}
> h4 {
@apply text-lg;
}
> p {
> p {
@apply w-full h-auto mb-1 last:mb-0 text-base;
@apply w-full h-auto mb-1 last:mb-0 text-base;
min-height: 24px;
min-height: 24px;
...
...
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