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
7b29c65f
Commit
7b29c65f
authored
Oct 03, 2022
by
steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add `inline-code` syntax parser
parent
2298ac6f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
2 deletions
+42
-2
marked.test.ts
web/src/labs/marked/marked.test.ts
+12
-0
InlineCode.ts
web/src/labs/marked/parser/InlineCode.ts
+23
-0
index.ts
web/src/labs/marked/parser/index.ts
+2
-1
memo-content.less
web/src/less/memo-content.less
+5
-1
No files found.
web/src/labs/marked/marked.test.ts
View file @
7b29c65f
...
...
@@ -82,6 +82,18 @@ console.log("hello world!")
},
];
for
(
const
t
of
tests
)
{
expect
(
marked
(
t
.
markdown
)).
toBe
(
t
.
want
);
}
});
test
(
"parse inline code"
,
()
=>
{
const
tests
=
[
{
markdown
:
`Code: \`console.log("Hello world!")\``
,
want
:
`<p>Code: <code>console.log("Hello world!")</code></p>`
,
},
];
for
(
const
t
of
tests
)
{
expect
(
marked
(
t
.
markdown
)).
toBe
(
t
.
want
);
}
...
...
web/src/labs/marked/parser/InlineCode.ts
0 → 100644
View file @
7b29c65f
export
const
INLINE_CODE_REG
=
/`
([\S
]
+
?)
`/
;
const
match
=
(
rawStr
:
string
):
number
=>
{
const
matchResult
=
rawStr
.
match
(
INLINE_CODE_REG
);
if
(
!
matchResult
)
{
return
0
;
}
const
matchStr
=
matchResult
[
0
];
return
matchStr
.
length
;
};
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
parsedStr
=
rawStr
.
replace
(
INLINE_CODE_REG
,
"<code>$1</code>"
);
return
parsedStr
;
};
export
default
{
name
:
"inline code"
,
regex
:
INLINE_CODE_REG
,
match
,
renderer
,
};
web/src/labs/marked/parser/index.ts
View file @
7b29c65f
...
...
@@ -11,6 +11,7 @@ import Mark from "./Mark";
import
Bold
from
"./Bold"
;
import
Emphasis
from
"./Emphasis"
;
import
PlainLink
from
"./PlainLink"
;
import
InlineCode
from
"./InlineCode"
;
export
{
CODE_BLOCK_REG
}
from
"./CodeBlock"
;
export
{
TODO_LIST_REG
}
from
"./TodoList"
;
...
...
@@ -27,5 +28,5 @@ export { EMPHASIS_REG } from "./Emphasis";
// The order determines the order of execution.
export
const
blockElementParserList
=
[
CodeBlock
,
TodoList
,
DoneList
,
OrderedList
,
UnorderedList
,
Paragraph
];
export
const
inlineElementParserList
=
[
Image
,
Mark
,
Link
,
Bold
,
Emphasis
,
PlainLink
,
Tag
];
export
const
inlineElementParserList
=
[
Image
,
Mark
,
Link
,
Bold
,
Emphasis
,
InlineCode
,
PlainLink
,
Tag
];
export
const
parserList
=
[...
blockElementParserList
,
...
inlineElementParserList
];
web/src/less/memo-content.less
View file @
7b29c65f
...
...
@@ -48,7 +48,11 @@
}
pre {
@apply w-full mt-1 py-2 px-3 rounded text-sm bg-gray-100 whitespace-pre-wrap;
@apply w-full my-1 py-2 px-3 rounded text-sm bg-gray-100 whitespace-pre-wrap;
}
code {
@apply bg-gray-100 px-1 rounded text-sm leading-6 inline-block;
}
}
...
...
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