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
c2e5d7b8
Commit
c2e5d7b8
authored
Sep 23, 2021
by
Enrique Alcántara
Committed by
Dmitriy Zaporozhets (DZ)
Sep 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Identify frontmatter code blocks when rendering Markdown
parent
662a859c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
8 deletions
+19
-8
lib/banzai/filter/front_matter_filter.rb
lib/banzai/filter/front_matter_filter.rb
+1
-1
lib/banzai/filter/syntax_highlight_filter.rb
lib/banzai/filter/syntax_highlight_filter.rb
+4
-1
spec/lib/banzai/filter/front_matter_filter_spec.rb
spec/lib/banzai/filter/front_matter_filter_spec.rb
+5
-5
spec/lib/banzai/filter/syntax_highlight_filter_spec.rb
spec/lib/banzai/filter/syntax_highlight_filter_spec.rb
+8
-0
spec/lib/banzai/pipeline/pre_process_pipeline_spec.rb
spec/lib/banzai/pipeline/pre_process_pipeline_spec.rb
+1
-1
No files found.
lib/banzai/filter/front_matter_filter.rb
View file @
c2e5d7b8
...
...
@@ -9,7 +9,7 @@ module Banzai
html
.
sub
(
Gitlab
::
FrontMatter
::
PATTERN
)
do
|
_match
|
lang
=
$~
[
:lang
].
presence
||
lang_mapping
[
$~
[
:delim
]]
[
"```
#{
lang
}
"
,
$~
[
:front_matter
],
"```"
,
"
\n
"
].
join
(
"
\n
"
)
[
"```
#{
lang
}
:frontmatter
"
,
$~
[
:front_matter
],
"```"
,
"
\n
"
].
join
(
"
\n
"
)
end
end
end
...
...
lib/banzai/filter/syntax_highlight_filter.rb
View file @
c2e5d7b8
...
...
@@ -28,6 +28,7 @@ module Banzai
def
highlight_node
(
node
)
css_classes
=
+
'code highlight js-syntax-highlight'
lang
,
lang_params
=
parse_lang_params
(
node
.
attr
(
'lang'
))
sourcepos
=
node
.
parent
.
attr
(
'data-sourcepos'
)
retried
=
false
if
use_rouge?
(
lang
)
...
...
@@ -55,7 +56,9 @@ module Banzai
retry
end
highlighted
=
%(<pre class="#{css_classes}"
sourcepos_attr
=
sourcepos
?
"data-sourcepos=
\"
#{
sourcepos
}
\"
"
:
""
highlighted
=
%(<pre #{sourcepos_attr} class="#{css_classes}"
lang="#{language}"
#{lang_params}
v-pre="true"><code>#{code}</code></pre>)
...
...
spec/lib/banzai/filter/front_matter_filter_spec.rb
View file @
c2e5d7b8
...
...
@@ -39,7 +39,7 @@ RSpec.describe Banzai::Filter::FrontMatterFilter do
aggregate_failures
do
expect
(
output
).
not_to
include
'---'
expect
(
output
).
to
include
"```yaml
\n
foo: :foo_symbol
\n
"
expect
(
output
).
to
include
"```yaml
:frontmatter
\n
foo: :foo_symbol
\n
"
end
end
...
...
@@ -59,7 +59,7 @@ RSpec.describe Banzai::Filter::FrontMatterFilter do
aggregate_failures
do
expect
(
output
).
not_to
include
'+++'
expect
(
output
).
to
include
"```toml
\n
foo = :foo_symbol
\n
"
expect
(
output
).
to
include
"```toml
:frontmatter
\n
foo = :foo_symbol
\n
"
end
end
...
...
@@ -81,7 +81,7 @@ RSpec.describe Banzai::Filter::FrontMatterFilter do
aggregate_failures
do
expect
(
output
).
not_to
include
';;;'
expect
(
output
).
to
include
"```json
\n
{
\n
\"
foo
\"
:
\"
:foo_symbol
\"
,
\n
"
expect
(
output
).
to
include
"```json
:frontmatter
\n
{
\n
\"
foo
\"
:
\"
:foo_symbol
\"
,
\n
"
end
end
...
...
@@ -101,7 +101,7 @@ RSpec.describe Banzai::Filter::FrontMatterFilter do
aggregate_failures
do
expect
(
output
).
not_to
include
'---arbitrary'
expect
(
output
).
to
include
"```arbitrary
\n
foo = :foo_symbol
\n
"
expect
(
output
).
to
include
"```arbitrary
:frontmatter
\n
foo = :foo_symbol
\n
"
end
end
...
...
@@ -130,7 +130,7 @@ RSpec.describe Banzai::Filter::FrontMatterFilter do
aggregate_failures
do
expect
(
output
).
to
eq
<<~
MD
```yaml
```yaml
:frontmatter
foo: :foo_symbol
bar: :bar_symbol
```
...
...
spec/lib/banzai/filter/syntax_highlight_filter_spec.rb
View file @
c2e5d7b8
...
...
@@ -98,6 +98,14 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
end
end
context
"when sourcepos metadata is available"
do
it
"includes it in the highlighted code block"
do
result
=
filter
(
'<pre data-sourcepos="1:1-3:3"><code lang="plaintext">This is a test</code></pre>'
)
expect
(
result
.
to_html
).
to
eq
(
'<pre data-sourcepos="1:1-3:3" class="code highlight js-syntax-highlight language-plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext">This is a test</span></code></pre>'
)
end
end
context
"when Rouge lexing fails"
do
before
do
allow_next_instance_of
(
Rouge
::
Lexers
::
Ruby
)
do
|
instance
|
...
...
spec/lib/banzai/pipeline/pre_process_pipeline_spec.rb
View file @
c2e5d7b8
...
...
@@ -20,7 +20,7 @@ RSpec.describe Banzai::Pipeline::PreProcessPipeline do
aggregate_failures
do
expect
(
result
[
:output
]).
not_to
include
"
\xEF\xBB\xBF
"
expect
(
result
[
:output
]).
not_to
include
'---'
expect
(
result
[
:output
]).
to
include
"```yaml
\n
foo: :foo_symbol
\n
"
expect
(
result
[
:output
]).
to
include
"```yaml
:frontmatter
\n
foo: :foo_symbol
\n
"
expect
(
result
[
:output
]).
to
include
"> blockquote
\n
"
end
end
...
...
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