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
5854537f
Commit
5854537f
authored
Jun 19, 2019
by
Guillaume Grossetie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable AsciiDoc syntax highlighting (using Rouge)
parent
02ad0c2f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
3 deletions
+91
-3
changelogs/unreleased/asciidoc-enable-syntax-highlighting.yml
...gelogs/unreleased/asciidoc-enable-syntax-highlighting.yml
+5
-0
lib/banzai/filter/syntax_highlight_filter.rb
lib/banzai/filter/syntax_highlight_filter.rb
+1
-1
lib/banzai/pipeline/ascii_doc_pipeline.rb
lib/banzai/pipeline/ascii_doc_pipeline.rb
+1
-0
lib/gitlab/asciidoc.rb
lib/gitlab/asciidoc.rb
+2
-1
lib/gitlab/asciidoc/syntax_highlighter/html_pipeline_adapter.rb
...tlab/asciidoc/syntax_highlighter/html_pipeline_adapter.rb
+15
-0
spec/lib/gitlab/asciidoc_spec.rb
spec/lib/gitlab/asciidoc_spec.rb
+67
-1
No files found.
changelogs/unreleased/asciidoc-enable-syntax-highlighting.yml
0 → 100644
View file @
5854537f
---
title
:
"
Enable
syntax
highlighting
for
AsciiDoc"
merge_request
:
29835
author
:
Guillaume Grossetie
type
:
added
\ No newline at end of file
lib/banzai/filter/syntax_highlight_filter.rb
View file @
5854537f
...
...
@@ -14,7 +14,7 @@ module Banzai
LANG_PARAMS_ATTR
=
'data-lang-params'
.
freeze
def
call
doc
.
search
(
'pre > code'
).
each
do
|
node
|
doc
.
search
(
'pre
:not([data-math-style])
> code'
).
each
do
|
node
|
highlight_node
(
node
)
end
...
...
lib/banzai/pipeline/ascii_doc_pipeline.rb
View file @
5854537f
...
...
@@ -6,6 +6,7 @@ module Banzai
def
self
.
filters
FilterArray
[
Filter
::
SanitizationFilter
,
Filter
::
SyntaxHighlightFilter
,
Filter
::
ExternalLinkFilter
,
Filter
::
PlantumlFilter
,
Filter
::
AsciiDocPostProcessingFilter
...
...
lib/gitlab/asciidoc.rb
View file @
5854537f
...
...
@@ -4,6 +4,7 @@ require 'asciidoctor'
require
'asciidoctor-plantuml'
require
'asciidoctor/extensions'
require
'gitlab/asciidoc/html5_converter'
require
'gitlab/asciidoc/syntax_highlighter/html_pipeline_adapter'
module
Gitlab
# Parser/renderer for the AsciiDoc format that uses Asciidoctor and filters
...
...
@@ -16,7 +17,7 @@ module Gitlab
'idseparator'
=>
'-'
,
'env'
=>
'gitlab'
,
'env-gitlab'
=>
''
,
'source-highlighter'
=>
'html-pipeline'
,
'source-highlighter'
=>
'
gitlab-
html-pipeline'
,
'icons'
=>
'font'
,
'outfilesuffix'
=>
'.adoc'
,
'max-include-depth'
=>
MAX_INCLUDE_DEPTH
...
...
lib/gitlab/asciidoc/syntax_highlighter/html_pipeline_adapter.rb
0 → 100644
View file @
5854537f
# frozen_string_literal: true
module
Gitlab
module
Asciidoc
module
SyntaxHighlighter
class
HtmlPipelineAdapter
<
Asciidoctor
::
SyntaxHighlighter
::
Base
register_for
'gitlab-html-pipeline'
def
format
(
node
,
lang
,
opts
)
%(<pre><code #{lang ? %[ lang="#{lang}"] : ''}>#{node.content}</code></pre>)
end
end
end
end
end
spec/lib/gitlab/asciidoc_spec.rb
View file @
5854537f
...
...
@@ -56,7 +56,7 @@ module Gitlab
},
'pre'
=>
{
input:
'```mypre"><script>alert(3)</script>'
,
output:
"<div>
\n
<div>
\n
<pre
lang=
\"
mypre
\"
>
\"
><code
></code></pre>
\n
</div>
\n
</div>"
output:
"<div>
\n
<div>
\n
<pre
class=
\"
code highlight js-syntax-highlight plaintext
\"
lang=
\"
plaintext
\"
v-pre=
\"
true
\"
><code><span id=
\"
LC1
\"
class=
\"
line
\"
lang=
\"
plaintext
\"
>
\"
></span
></code></pre>
\n
</div>
\n
</div>"
}
}
...
...
@@ -67,6 +67,72 @@ module Gitlab
end
end
context
'with fenced block'
do
it
'highlights syntax'
do
input
=
<<~
ADOC
```js
console.log('hello world')
```
ADOC
output
=
<<~
HTML
<div>
<div>
<pre class="code highlight js-syntax-highlight javascript" lang="javascript" v-pre="true"><code><span id="LC1" class="line" lang="javascript"><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="dl">'</span><span class="s1">hello world</span><span class="dl">'</span><span class="p">)</span></span></code></pre>
</div>
</div>
HTML
expect
(
render
(
input
,
context
)).
to
include
(
output
.
strip
)
end
end
context
'with listing block'
do
it
'highlights syntax'
do
input
=
<<~
ADOC
[source,c++]
.class.cpp
----
#include <stdio.h>
for (int i = 0; i < 5; i++) {
std::cout<<"*"<<std::endl;
}
----
ADOC
output
=
<<~
HTML
<div>
<div>class.cpp</div>
<div>
<pre class="code highlight js-syntax-highlight cpp" lang="cpp" v-pre="true"><code><span id="LC1" class="line" lang="cpp"><span class="cp">#include <stdio.h></span></span>
<span id="LC2" class="line" lang="cpp"></span>
<span id="LC3" class="line" lang="cpp"><span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="mi">5</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span></span>
<span id="LC4" class="line" lang="cpp"> <span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="o"><<</span><span class="s">"*"</span><span class="o"><<</span><span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span></span>
<span id="LC5" class="line" lang="cpp"><span class="p">}</span></span></code></pre>
</div>
</div>
HTML
expect
(
render
(
input
,
context
)).
to
include
(
output
.
strip
)
end
end
context
'with stem block'
do
it
'does not apply syntax highlighting'
do
input
=
<<~
ADOC
[stem]
++++
\s
qrt{4} = 2
++++
ADOC
output
=
"<div>
\n
<div>
\n\\
$ qrt{4} = 2
\\
$
\n
</div>
\n
</div>"
expect
(
render
(
input
,
context
)).
to
include
(
output
)
end
end
context
'external links'
do
it
'adds the `rel` attribute to the link'
do
output
=
render
(
'link:https://google.com[Google]'
,
context
)
...
...
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