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
486cf8bd
Commit
486cf8bd
authored
Oct 04, 2022
by
steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add `escape` to renderer
parent
ea911387
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
80 additions
and
17 deletions
+80
-17
CodeBlock.ts
web/src/labs/marked/parser/CodeBlock.ts
+8
-2
Image.ts
web/src/labs/marked/parser/Image.ts
+8
-2
InlineCode.ts
web/src/labs/marked/parser/InlineCode.ts
+8
-2
Link.ts
web/src/labs/marked/parser/Link.ts
+8
-2
Mark.ts
web/src/labs/marked/parser/Mark.ts
+8
-2
PlainLink.ts
web/src/labs/marked/parser/PlainLink.ts
+8
-2
PlainText.ts
web/src/labs/marked/parser/PlainText.ts
+18
-0
Tag.ts
web/src/labs/marked/parser/Tag.ts
+8
-2
TodoList.ts
web/src/labs/marked/parser/TodoList.ts
+2
-1
UnorderedList.ts
web/src/labs/marked/parser/UnorderedList.ts
+2
-1
index.ts
web/src/labs/marked/parser/index.ts
+2
-1
No files found.
web/src/labs/marked/parser/CodeBlock.ts
View file @
486cf8bd
import
{
escape
}
from
"lodash-es"
;
export
const
CODE_BLOCK_REG
=
/^```
(\S
*
?)\s([\s\S]
*
?)
```
(\n?)
/
;
export
const
CODE_BLOCK_REG
=
/^```
(\S
*
?)\s([\s\S]
*
?)
```
(\n?)
/
;
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
parsedStr
=
rawStr
.
replace
(
CODE_BLOCK_REG
,
"<pre lang='$1'>
\n
$2</pre>$3"
);
const
matchResult
=
rawStr
.
match
(
CODE_BLOCK_REG
);
return
parsedStr
;
if
(
!
matchResult
)
{
return
rawStr
;
}
return
`<pre lang='
${
escape
(
matchResult
[
1
])}
'>\n
${
escape
(
matchResult
[
2
])}
</pre>
${
matchResult
[
3
]}
`
;
};
};
export
default
{
export
default
{
...
...
web/src/labs/marked/parser/Image.ts
View file @
486cf8bd
import
{
escape
}
from
"lodash-es"
;
export
const
IMAGE_REG
=
/!
\[
.*
?\]\((
.+
?)\)
/
;
export
const
IMAGE_REG
=
/!
\[
.*
?\]\((
.+
?)\)
/
;
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
parsedStr
=
rawStr
.
replace
(
IMAGE_REG
,
"<img class='img' src='$1' />"
);
const
matchResult
=
rawStr
.
match
(
IMAGE_REG
);
return
parsedStr
;
if
(
!
matchResult
)
{
return
rawStr
;
}
return
`<img class='img' src='
${
escape
(
matchResult
[
1
])}
' />`
;
};
};
export
default
{
export
default
{
...
...
web/src/labs/marked/parser/InlineCode.ts
View file @
486cf8bd
import
{
escape
}
from
"lodash-es"
;
export
const
INLINE_CODE_REG
=
/`
([\S
]
+
?)
`/
;
export
const
INLINE_CODE_REG
=
/`
([\S
]
+
?)
`/
;
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
parsedStr
=
rawStr
.
replace
(
INLINE_CODE_REG
,
"<code>$1</code>"
);
const
matchResult
=
rawStr
.
match
(
INLINE_CODE_REG
);
return
parsedStr
;
if
(
!
matchResult
)
{
return
rawStr
;
}
return
`<code>
${
escape
(
matchResult
[
1
])}
</code>`
;
};
};
export
default
{
export
default
{
...
...
web/src/labs/marked/parser/Link.ts
View file @
486cf8bd
import
{
escape
}
from
"lodash-es"
;
export
const
LINK_REG
=
/
\[(
.*
?)\]\((
.+
?)\)
/
;
export
const
LINK_REG
=
/
\[(
.*
?)\]\((
.+
?)\)
/
;
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
parsedStr
=
rawStr
.
replace
(
LINK_REG
,
"<a class='link' target='_blank' rel='noreferrer' href='$2'>$1</a>"
);
const
matchResult
=
rawStr
.
match
(
LINK_REG
);
return
parsedStr
;
if
(
!
matchResult
)
{
return
rawStr
;
}
return
`<a class='link' target='_blank' rel='noreferrer' href='
${
escape
(
matchResult
[
2
])}
'>
${
escape
(
matchResult
[
1
])}
</a>`
;
};
};
export
default
{
export
default
{
...
...
web/src/labs/marked/parser/Mark.ts
View file @
486cf8bd
import
{
escape
}
from
"lodash-es"
;
export
const
MARK_REG
=
/@
\[([\S
]
+
?)\]\((\S
+
?)\)
/
;
export
const
MARK_REG
=
/@
\[([\S
]
+
?)\]\((\S
+
?)\)
/
;
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
parsedStr
=
rawStr
.
replace
(
MARK_REG
,
"<span class='memo-link-text' data-value='$2'>$1</span>"
);
const
matchResult
=
rawStr
.
match
(
MARK_REG
);
return
parsedStr
;
if
(
!
matchResult
)
{
return
rawStr
;
}
return
`<span class='memo-link-text' data-value='
${
escape
(
matchResult
[
2
])}
'>
${
escape
(
matchResult
[
1
])}
</span>`
;
};
};
export
default
{
export
default
{
...
...
web/src/labs/marked/parser/PlainLink.ts
View file @
486cf8bd
import
{
escape
}
from
"lodash-es"
;
export
const
PLAIN_LINK_REG
=
/
(
https
?
:
\/\/[^
]
+
)
/
;
export
const
PLAIN_LINK_REG
=
/
(
https
?
:
\/\/[^
]
+
)
/
;
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
parsedStr
=
rawStr
.
replace
(
PLAIN_LINK_REG
,
"<a class='link' target='_blank' rel='noreferrer' href='$1'>$1</a>"
);
const
matchResult
=
rawStr
.
match
(
PLAIN_LINK_REG
);
return
parsedStr
;
if
(
!
matchResult
)
{
return
rawStr
;
}
return
`<a class='link' target='_blank' rel='noreferrer' href='
${
escape
(
matchResult
[
1
])}
'>
${
escape
(
matchResult
[
1
])}
</a>`
;
};
};
export
default
{
export
default
{
...
...
web/src/labs/marked/parser/PlainText.ts
0 → 100644
View file @
486cf8bd
import
{
escape
}
from
"lodash-es"
;
export
const
PLAIN_TEXT_REG
=
/
([\S
]
+
)
/
;
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
matchResult
=
rawStr
.
match
(
PLAIN_TEXT_REG
);
if
(
!
matchResult
)
{
return
rawStr
;
}
return
`
${
escape
(
matchResult
[
1
])}
`
;
};
export
default
{
name
:
"plain text"
,
regex
:
PLAIN_TEXT_REG
,
renderer
,
};
web/src/labs/marked/parser/Tag.ts
View file @
486cf8bd
import
{
escape
}
from
"lodash-es"
;
export
const
TAG_REG
=
/
[^\s]?
#
([^\s
#
]
+
?)
/
;
export
const
TAG_REG
=
/
[^\s]?
#
([^\s
#
]
+
?)
/
;
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
renderer
=
(
rawStr
:
string
):
string
=>
{
const
parsedStr
=
rawStr
.
replace
(
TAG_REG
,
"<span class='tag-span'>#$1</span> "
);
const
matchResult
=
rawStr
.
match
(
TAG_REG
);
return
parsedStr
;
if
(
!
matchResult
)
{
return
rawStr
;
}
return
`<span class='tag-span'>#
${
escape
(
matchResult
[
1
])}
</span> `
;
};
};
export
default
{
export
default
{
...
...
web/src/labs/marked/parser/TodoList.ts
View file @
486cf8bd
import
{
escape
}
from
"lodash-es"
;
import
{
inlineElementParserList
}
from
"."
;
import
{
inlineElementParserList
}
from
"."
;
import
{
marked
}
from
".."
;
import
{
marked
}
from
".."
;
...
@@ -10,7 +11,7 @@ const renderer = (rawStr: string): string => {
...
@@ -10,7 +11,7 @@ const renderer = (rawStr: string): string => {
}
}
const
parsedContent
=
marked
(
matchResult
[
1
],
[],
inlineElementParserList
);
const
parsedContent
=
marked
(
matchResult
[
1
],
[],
inlineElementParserList
);
return
`<p><span class='todo-block todo' data-value='TODO'></span>
${
parsedContent
}
</p>
${
matchResult
[
2
]
}
`
;
return
`<p><span class='todo-block todo' data-value='TODO'></span>
${
parsedContent
}
</p>
${
escape
(
matchResult
[
2
])
}
`
;
};
};
export
default
{
export
default
{
...
...
web/src/labs/marked/parser/UnorderedList.ts
View file @
486cf8bd
import
{
escape
}
from
"lodash-es"
;
import
{
inlineElementParserList
}
from
"."
;
import
{
inlineElementParserList
}
from
"."
;
import
{
marked
}
from
".."
;
import
{
marked
}
from
".."
;
...
@@ -10,7 +11,7 @@ const renderer = (rawStr: string): string => {
...
@@ -10,7 +11,7 @@ const renderer = (rawStr: string): string => {
}
}
const
parsedContent
=
marked
(
matchResult
[
1
],
[],
inlineElementParserList
);
const
parsedContent
=
marked
(
matchResult
[
1
],
[],
inlineElementParserList
);
return
`<p><span class='ul-block'>•</span>
${
parsedContent
}
</p>
${
matchResult
[
2
]
}
`
;
return
`<p><span class='ul-block'>•</span>
${
parsedContent
}
</p>
${
escape
(
matchResult
[
2
])
}
`
;
};
};
export
default
{
export
default
{
...
...
web/src/labs/marked/parser/index.ts
View file @
486cf8bd
...
@@ -12,6 +12,7 @@ import Bold from "./Bold";
...
@@ -12,6 +12,7 @@ import Bold from "./Bold";
import
Emphasis
from
"./Emphasis"
;
import
Emphasis
from
"./Emphasis"
;
import
PlainLink
from
"./PlainLink"
;
import
PlainLink
from
"./PlainLink"
;
import
InlineCode
from
"./InlineCode"
;
import
InlineCode
from
"./InlineCode"
;
import
PlainText
from
"./PlainText"
;
export
{
CODE_BLOCK_REG
}
from
"./CodeBlock"
;
export
{
CODE_BLOCK_REG
}
from
"./CodeBlock"
;
export
{
TODO_LIST_REG
}
from
"./TodoList"
;
export
{
TODO_LIST_REG
}
from
"./TodoList"
;
...
@@ -23,5 +24,5 @@ export { MARK_REG } from "./Mark";
...
@@ -23,5 +24,5 @@ export { MARK_REG } from "./Mark";
// The order determines the order of execution.
// The order determines the order of execution.
export
const
blockElementParserList
=
[
CodeBlock
,
TodoList
,
DoneList
,
OrderedList
,
UnorderedList
,
Paragraph
];
export
const
blockElementParserList
=
[
CodeBlock
,
TodoList
,
DoneList
,
OrderedList
,
UnorderedList
,
Paragraph
];
export
const
inlineElementParserList
=
[
Image
,
Mark
,
Bold
,
Emphasis
,
Link
,
InlineCode
,
PlainLink
,
Tag
];
export
const
inlineElementParserList
=
[
Image
,
Mark
,
Bold
,
Emphasis
,
Link
,
InlineCode
,
PlainLink
,
Tag
,
PlainText
];
export
const
parserList
=
[...
blockElementParserList
,
...
inlineElementParserList
];
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