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
3a815bf8
Commit
3a815bf8
authored
Jun 22, 2020
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert ADF codeblocks to fenced codeblocks
with proper language attribution
parent
1b1aa81a
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
177 additions
and
41 deletions
+177
-41
changelogs/unreleased/223097-support-fenced-code-blocks-in-atlassian-document-format-converter.yml
...ed-code-blocks-in-atlassian-document-format-converter.yml
+5
-0
lib/kramdown/converter/commonmark.rb
lib/kramdown/converter/commonmark.rb
+40
-0
spec/fixtures/lib/kramdown/atlassian_document_format/code_block.json
...es/lib/kramdown/atlassian_document_format/code_block.json
+43
-0
spec/fixtures/lib/kramdown/atlassian_document_format/code_block.md
...ures/lib/kramdown/atlassian_document_format/code_block.md
+34
-13
spec/fixtures/lib/kramdown/atlassian_document_format/complex_document.md
...ib/kramdown/atlassian_document_format/complex_document.md
+31
-28
spec/fixtures/lib/kramdown/atlassian_document_format/ordered_list.json
.../lib/kramdown/atlassian_document_format/ordered_list.json
+19
-0
spec/fixtures/lib/kramdown/atlassian_document_format/ordered_list.md
...es/lib/kramdown/atlassian_document_format/ordered_list.md
+5
-0
No files found.
changelogs/unreleased/223097-support-fenced-code-blocks-in-atlassian-document-format-converter.yml
0 → 100644
View file @
3a815bf8
---
title
:
Support fenced code blocks in Atlassian Document Format converter
merge_request
:
35065
author
:
type
:
fixed
lib/kramdown/converter/commonmark.rb
View file @
3a815bf8
...
...
@@ -12,6 +12,46 @@ module Kramdown
# Note: this is only an initial implementation. Currently don't
# strip out IALs or other specific kramdown syntax.
class
Commonmark
<
::
Kramdown
::
Converter
::
Kramdown
# replaces the ^ used in kramdown. This forces the current
# block to end, so that a different list or codeblock can be
# started. https://kramdown.gettalong.org/syntax.html#eob-marker
END_OF_BLOCK
=
'<!-- -->'
def
convert
(
el
,
opts
=
{
indent:
0
})
res
=
super
if
[
:ul
,
:dl
,
:ol
,
:codeblock
].
include?
(
el
.
type
)
&&
opts
[
:next
]
&&
([
el
.
type
,
:codeblock
].
include?
(
opts
[
:next
].
type
)
||
(
opts
[
:next
].
type
==
:blank
&&
opts
[
:nnext
]
&&
[
el
.
type
,
:codeblock
].
include?
(
opts
[
:nnext
].
type
)))
# replace the end of block character
res
.
sub!
(
/\^\n\n\z/m
,
"
#{
END_OF_BLOCK
}
\n\n
"
)
end
res
end
def
convert_codeblock
(
el
,
_opts
)
# Although tildes are supported in CommonMark, backticks are more common
"```
#{
el
.
options
[
:lang
]
}
\n
"
+
el
.
value
.
split
(
/\n/
).
map
{
|
l
|
l
.
empty?
?
""
:
"
#{
l
}
"
}.
join
(
"
\n
"
)
+
"
\n
```
\n\n
"
end
def
convert_li
(
el
,
opts
)
res
=
super
if
el
.
children
.
first
&&
el
.
children
.
first
.
type
==
:p
&&
!
el
.
children
.
first
.
options
[
:transparent
]
if
el
.
children
.
size
==
1
&&
@stack
.
last
.
children
.
last
==
el
&&
(
@stack
.
last
.
children
.
any?
{
|
c
|
c
.
children
.
first
.
type
!=
:p
}
||
@stack
.
last
.
children
.
size
==
1
)
# replace the end of block character
res
.
sub!
(
/\^\n\z/m
,
"
#{
END_OF_BLOCK
}
\n
"
)
end
end
res
end
def
convert_table
(
el
,
opts
)
return
super
unless
@options
[
:html_tables
]
...
...
spec/fixtures/lib/kramdown/atlassian_document_format/code_block.json
View file @
3a815bf8
...
...
@@ -14,6 +14,18 @@
}
]
},
{
"type"
:
"codeBlock"
,
"attrs"
:
{
"language"
:
"css"
},
"content"
:
[
{
"type"
:
"text"
,
"text"
:
".overflow { overflow: hidden; }"
}
]
},
{
"type"
:
"bulletList"
,
"content"
:
[
...
...
@@ -37,6 +49,37 @@
"text"
:
"public DemoClass()
\n
{
\n
// assign default value
\n
x = 0;
\n
}"
}
]
},
{
"type"
:
"orderedList"
,
"content"
:
[
{
"type"
:
"listItem"
,
"content"
:
[
{
"type"
:
"paragraph"
,
"content"
:
[
{
"type"
:
"text"
,
"text"
:
"Number list Item 1"
}
]
},
{
"type"
:
"codeBlock"
,
"attrs"
:
{
"language"
:
"ruby"
},
"content"
:
[
{
"type"
:
"text"
,
"text"
:
"def test
\n
# assign default value
\n
x = 0
\n
end"
}
]
}
]
}
]
}
]
}
...
...
spec/fixtures/lib/kramdown/atlassian_document_format/code_block.md
View file @
3a815bf8
export function makeIssue({ parentIssue, project, users }) {
```
javascript
export
function
makeIssue
({
parentIssue
,
project
,
users
})
{
const
issueType
=
pickRandom
(
project
.
issueTypes
)
console
.
log
(
data
)
return
data
}
}
```
<!-- -->
```
css
.overflow
{
overflow
:
hidden
;
}
```
*
Item 1
```
java
public
DemoClass
()
{
// assign default value
x
=
0
;
}
```
1.
Number list Item 1
```
ruby
def
test
# assign default value
x
=
0
end
```
spec/fixtures/lib/kramdown/atlassian_document_format/complex_document.md
View file @
3a815bf8
...
...
@@ -165,7 +165,8 @@ Col 3 Row 3
<del>
Strikethrough
</del>
export function makeIssue({ parentIssue, project, users }) {
```
javascript
export
function
makeIssue
({
parentIssue
,
project
,
users
})
{
const
issueType
=
pickRandom
(
project
.
issueTypes
)
...
...
@@ -195,7 +196,9 @@ Col 3 Row 3
console
.
log
(
data
)
return
data
}
}
```
![
jira-10050-field-description
](
adf-media://79411c6b-50e0-477f-b4ed-ac3a5887750c
)
...
...
spec/fixtures/lib/kramdown/atlassian_document_format/ordered_list.json
View file @
3a815bf8
...
...
@@ -146,6 +146,25 @@
]
}
]
},
{
"type"
:
"orderedList"
,
"content"
:
[
{
"type"
:
"listItem"
,
"content"
:
[
{
"type"
:
"paragraph"
,
"content"
:
[
{
"type"
:
"text"
,
"text"
:
"Another list"
}
]
}
]
}
]
}
]
}
spec/fixtures/lib/kramdown/atlassian_document_format/ordered_list.md
View file @
3a815bf8
...
...
@@ -17,4 +17,9 @@
9.
Number list item 9
10.
Number list item 10
<!-- -->
1.
Another list
<!-- -->
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