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
32ac4caf
Commit
32ac4caf
authored
Sep 04, 2020
by
Enrique Alcantara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Indent list content to four spaces
parent
fe519102
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
2 deletions
+57
-2
app/assets/javascripts/static_site_editor/services/formatter.js
...sets/javascripts/static_site_editor/services/formatter.js
+43
-1
spec/frontend/static_site_editor/services/formatter_spec.js
spec/frontend/static_site_editor/services/formatter_spec.js
+14
-1
No files found.
app/assets/javascripts/static_site_editor/services/formatter.js
View file @
32ac4caf
import
{
repeat
}
from
'
lodash
'
;
const
topLevelOrderedRegexp
=
/^
\d{1,3}
/
;
const
nestedLineRegexp
=
/^
\s
+/
;
/**
* DISCLAIMER: This is a temporary fix that corrects the indentation
* spaces of list items. This workaround originates in the usage of
* the Static Site Editor to edit the Handbook. The Handbook uses a
* Markdown parser called Kramdown interprets lines indented
* with two spaces as content within a list. For example:
*
* 1. ordered list
* - nested unordered list
*
* The Static Site Editor uses a different Markdown parser based on the
* CommonMark specification (official Markdown spec) called ToastMark.
* When the SSE encounters a nested list with only two spaces, it flattens
* the list:
*
* 1. ordered list
* - nested unordered list
*
* This function attempts to correct this problem before the content is loaded
* by Toast UI.
*/
const
correctNestedContentIndenation
=
source
=>
{
const
lines
=
source
.
split
(
'
\n
'
);
let
topLevelOrderedListDetected
=
false
;
return
lines
.
reduce
((
result
,
line
)
=>
{
if
(
topLevelOrderedListDetected
&&
nestedLineRegexp
.
test
(
line
))
{
return
[...
result
,
line
.
replace
(
nestedLineRegexp
,
repeat
(
'
'
,
4
))];
}
topLevelOrderedListDetected
=
topLevelOrderedRegexp
.
test
(
line
);
return
[...
result
,
line
];
},
[])
.
join
(
'
\n
'
);
};
const
removeOrphanedBrTags
=
source
=>
{
/* Until the underlying Squire editor of Toast UI Editor resolves duplicate `<br>` tags, this
`replace` solution will clear out orphaned `<br>` tags that it generates. Additionally,
...
...
@@ -8,7 +50,7 @@ const removeOrphanedBrTags = source => {
};
const
format
=
source
=>
{
return
removeOrphanedBrTags
(
source
);
return
correctNestedContentIndenation
(
removeOrphanedBrTags
(
source
)
);
};
export
default
format
;
spec/frontend/static_site_editor/services/formatter_spec.js
View file @
32ac4caf
import
formatter
from
'
~/static_site_editor/services/formatter
'
;
describe
(
'
formatter
'
,
()
=>
{
describe
(
'
static_site_editor/services/
formatter
'
,
()
=>
{
const
source
=
`Some text
<br>
...
...
@@ -23,4 +23,17 @@ And even more text`;
it
(
'
removes extraneous <br> tags
'
,
()
=>
{
expect
(
formatter
(
source
)).
toMatch
(
sourceWithoutBrTags
);
});
describe
(
'
ordered lists with incorrect content indentation
'
,
()
=>
{
it
.
each
`
input | result
${
'
12. ordered list item
\n
13.Next ordered list item
'
}
|
${
'
12. ordered list item
\n
13.Next ordered list item
'
}
${
'
12. ordered list item
\n
- Next ordered list item
'
}
|
${
'
12. ordered list item
\n
- Next ordered list item
'
}
${
'
12. ordered list item
\n
- Next ordered list item
'
}
|
${
'
12. ordered list item
\n
- Next ordered list item
'
}
${
'
12. ordered list item
\n
Next ordered list item
'
}
|
${
'
12. ordered list item
\n
Next ordered list item
'
}
${
'
1. ordered list item
\n
Next ordered list item
'
}
|
${
'
1. ordered list item
\n
Next ordered list item
'
}
`
(
'
\n
transforms
\n
$input
\n
to
\n
$result
'
,
({
input
,
result
})
=>
{
expect
(
formatter
(
input
)).
toBe
(
result
);
});
});
});
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