Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
condenser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
condenser
Commits
c85d9592
Commit
c85d9592
authored
2 years ago
by
Quoc Huy Nguyen Dinh
Browse files
Options
Downloads
Patches
Plain Diff
Refactor the embedded player code injection logic in order to not change the initial structure
parent
c399af78
No related branches found
Branches containing commit
No related tags found
2 merge requests
!354
Remove linkify:false from Remarkable call. The option has been removed from...
,
!352
Refactor the embedded player code injection logic in order to not change the initial structure
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/components/cards/MarkdownViewer.jsx
+11
-26
11 additions, 26 deletions
src/app/components/cards/MarkdownViewer.jsx
with
11 additions
and
26 deletions
src/app/components/cards/MarkdownViewer.jsx
+
11
−
26
View file @
c85d9592
import
React
,
{
Component
}
from
'
react
'
;
import
React
,
{
Component
}
from
'
react
'
;
import
{
renderToString
}
from
'
react-dom/server
'
;
import
PropTypes
from
'
prop-types
'
;
import
PropTypes
from
'
prop-types
'
;
import
{
connect
}
from
'
react-redux
'
;
import
{
connect
}
from
'
react-redux
'
;
import
{
Remarkable
}
from
'
remarkable
'
;
import
{
Remarkable
}
from
'
remarkable
'
;
...
@@ -120,37 +121,21 @@ class MarkdownViewer extends Component {
...
@@ -120,37 +121,21 @@ class MarkdownViewer extends Component {
const
noImageActive
=
cleanText
.
indexOf
(
noImageText
)
!==
-
1
;
const
noImageActive
=
cleanText
.
indexOf
(
noImageText
)
!==
-
1
;
const
regex
=
/~~~ embed:
(
.*
?
~~~
)
/gm
;
let
matches
;
let
processedText
=
cleanText
;
// In addition to inserting the youtube component, this allows
// In addition to inserting the youtube component, this allows
// react to compare separately preventing excessive re-rendering.
// react to compare separately preventing excessive re-rendering.
let
idx
=
0
;
let
idx
=
0
;
const
sections
=
[];
function
checksum
(
s
)
{
while
((
matches
=
regex
.
exec
(
processedText
))
!==
null
)
{
let
chk
=
0x12345678
;
// This is necessary to avoid infinite loops with zero-width matches
const
len
=
s
.
length
;
if
(
matches
.
index
===
regex
.
lastIndex
)
{
for
(
let
i
=
0
;
i
<
len
;
i
+=
1
)
{
regex
.
lastIndex
+=
1
;
chk
+=
s
.
charCodeAt
(
i
)
*
(
i
+
1
);
}
}
// eslint-disable-next-line no-bitwise
const
embedMd
=
EmbeddedPlayerGenerateMd
(
matches
[
1
],
idx
,
large
);
return
(
chk
&
0xffffffff
).
toString
(
16
);
processedText
=
processedText
.
replace
(
matches
[
0
],
renderToString
(
embedMd
.
markdown
));
}
// HtmlReady inserts ~~~ embed:${id} type ~~~
for
(
let
section
of
cleanText
.
split
(
'
~~~ embed:
'
))
{
const
embedMd
=
EmbeddedPlayerGenerateMd
(
section
,
idx
,
large
);
if
(
embedMd
)
{
const
{
section
:
newSection
,
markdown
}
=
embedMd
;
section
=
newSection
;
sections
.
push
(
markdown
);
if
(
section
===
''
)
{
// eslint-disable-next-line no-continue
continue
;
}
}
sections
.
push
(<
div
key
=
{
checksum
(
section
)
}
dangerouslySetInnerHTML
=
{
{
__html
:
section
}
}
/>);
idx
+=
1
;
idx
+=
1
;
}
}
...
@@ -162,7 +147,7 @@ class MarkdownViewer extends Component {
...
@@ -162,7 +147,7 @@ class MarkdownViewer extends Component {
return
(
return
(
<
div
className
=
{
'
MarkdownViewer
'
+
cn
}
>
<
div
className
=
{
'
MarkdownViewer
'
+
cn
}
>
{
sections
}
<
div
dangerouslySetInnerHTML
=
{
{
__html
:
processedText
}
}
/>
{
noImageActive
&&
allowNoImage
&&
(
{
noImageActive
&&
allowNoImage
&&
(
<
div
<
div
role
=
"link"
role
=
"link"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment