Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
6c0c1798
Commit
6c0c1798
authored
Jul 02, 2020
by
derek-knox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial html custom renderer
Wrap HTML tokens in uneditable blocks as a v1 implementation.
parent
0cd724f8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
1 deletion
+58
-1
app/assets/javascripts/vue_shared/components/rich_content_editor/services/build_custom_renderer.js
...nts/rich_content_editor/services/build_custom_renderer.js
+10
-1
app/assets/javascripts/vue_shared/components/rich_content_editor/services/renderers/render_html.js
...nts/rich_content_editor/services/renderers/render_html.js
+9
-0
changelogs/unreleased/36250-custom-renderer-html.yml
changelogs/unreleased/36250-custom-renderer-html.yml
+5
-0
spec/frontend/vue_shared/components/rich_content_editor/services/renderers/render_html_spec.js
...ich_content_editor/services/renderers/render_html_spec.js
+34
-0
No files found.
app/assets/javascripts/vue_shared/components/rich_content_editor/services/build_custom_renderer.js
View file @
6c0c1798
import
renderHtml
from
'
./renderers/render_html
'
;
import
renderKramdownList
from
'
./renderers/render_kramdown_list
'
;
import
renderKramdownText
from
'
./renderers/render_kramdown_text
'
;
import
renderIdentifierParagraph
from
'
./renderers/render_identifier_paragraph
'
;
import
renderEmbeddedRubyText
from
'
./renderers/render_embedded_ruby_text
'
;
const
htmlRenderers
=
[
renderHtml
];
const
listRenderers
=
[
renderKramdownList
];
const
paragraphRenderers
=
[
renderIdentifierParagraph
];
const
textRenderers
=
[
renderKramdownText
,
renderEmbeddedRubyText
];
...
...
@@ -23,8 +25,15 @@ const buildCustomRendererFunctions = (customRenderers, defaults) => {
return
Object
.
fromEntries
(
customEntries
);
};
const
buildCustomHTMLRenderer
=
(
customRenderers
=
{
list
:
[],
paragraph
:
[],
text
:
[]
})
=>
{
const
buildCustomHTMLRenderer
=
(
customRenderers
=
{
htmlBlock
:
[],
list
:
[],
paragraph
:
[],
text
:
[]
},
)
=>
{
const
defaults
=
{
htmlBlock
(
node
,
context
)
{
const
allHtmlRenderers
=
[...
customRenderers
.
list
,
...
htmlRenderers
];
return
executeRenderer
(
allHtmlRenderers
,
node
,
context
);
},
list
(
node
,
context
)
{
const
allListRenderers
=
[...
customRenderers
.
list
,
...
listRenderers
];
...
...
app/assets/javascripts/vue_shared/components/rich_content_editor/services/renderers/render_html.js
0 → 100644
View file @
6c0c1798
import
{
buildUneditableTokens
}
from
'
./build_uneditable_token
'
;
const
canRender
=
({
type
})
=>
{
return
type
===
'
htmlBlock
'
;
};
const
render
=
(
_
,
{
origin
})
=>
buildUneditableTokens
(
origin
());
export
default
{
canRender
,
render
};
changelogs/unreleased/36250-custom-renderer-html.yml
0 → 100644
View file @
6c0c1798
---
title
:
Add initial custom HTML renderer to the Static Site Editor to prevent editing in WYSIWYG mode
merge_request
:
36250
author
:
type
:
added
spec/frontend/vue_shared/components/rich_content_editor/services/renderers/render_html_spec.js
0 → 100644
View file @
6c0c1798
import
renderer
from
'
~/vue_shared/components/rich_content_editor/services/renderers/render_html
'
;
import
{
buildUneditableTokens
}
from
'
~/vue_shared/components/rich_content_editor/services/renderers/build_uneditable_token
'
;
import
{
normalTextNode
}
from
'
./mock_data
'
;
const
htmlLiteral
=
'
<div><h1>Heading</h1><p>Paragraph.</p></div>
'
;
const
htmlBlockNode
=
{
firstChild
:
null
,
literal
:
htmlLiteral
,
type
:
'
htmlBlock
'
,
};
describe
(
'
Render HTML renderer
'
,
()
=>
{
describe
(
'
canRender
'
,
()
=>
{
it
(
'
should return true when the argument is an html block
'
,
()
=>
{
expect
(
renderer
.
canRender
(
htmlBlockNode
)).
toBe
(
true
);
});
it
(
'
should return false when the argument is not an html block
'
,
()
=>
{
expect
(
renderer
.
canRender
(
normalTextNode
)).
toBe
(
false
);
});
});
describe
(
'
render
'
,
()
=>
{
it
(
'
should return uneditable tokens wrapping the origin token
'
,
()
=>
{
const
origin
=
jest
.
fn
();
const
context
=
{
origin
};
expect
(
renderer
.
render
(
htmlBlockNode
,
context
)).
toStrictEqual
(
buildUneditableTokens
(
origin
()),
);
});
});
});
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