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
e59de28e
Commit
e59de28e
authored
Dec 27, 2019
by
Jouke Witteveen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set AsciiDoc docname attribute using the requested path
parent
2ca2e390
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
1 deletion
+52
-1
changelogs/unreleased/asciidoc-attr.yml
changelogs/unreleased/asciidoc-attr.yml
+5
-0
doc/user/asciidoc.md
doc/user/asciidoc.md
+11
-0
lib/gitlab/asciidoc.rb
lib/gitlab/asciidoc.rb
+15
-1
spec/lib/gitlab/asciidoc_spec.rb
spec/lib/gitlab/asciidoc_spec.rb
+21
-0
No files found.
changelogs/unreleased/asciidoc-attr.yml
0 → 100644
View file @
e59de28e
---
title
:
Support Asciidoc docname attribute
merge_request
:
22313
author
:
Jouke Witteveen
type
:
added
doc/user/asciidoc.md
View file @
e59de28e
...
...
@@ -91,6 +91,8 @@ stem:[sqrt(4) = 2]
### Attributes
**User-defined attributes**
```
asciidoc
// define attributes in the document header
:name: value
...
...
@@ -104,6 +106,15 @@ C{pp} is not required, only Ruby.
Use a leading backslash to output a word enclosed in curly braces, like \{name}.
```
**Environment attributes**
GitLab sets the following environment attributes:
| Attribute | Description |
| :-------------- | :--------------------------------------------------------------------------------------------------------------------- |
|
`docname`
| Root name of the source document (no leading path or file extension). |
|
`outfilesuffix`
| File extension corresponding to the backend output (defaults to
`.adoc`
to make inter-document cross references work). |
### Links
```
asciidoc
...
...
lib/gitlab/asciidoc.rb
View file @
e59de28e
...
...
@@ -25,6 +25,19 @@ module Gitlab
'max-include-depth'
=>
MAX_INCLUDE_DEPTH
}.
freeze
def
self
.
path_attrs
(
path
)
return
{}
unless
path
{
# Set an empty docname if the path is a directory
'docname'
=>
if
path
[
-
1
]
==
::
File
::
SEPARATOR
''
else
::
File
.
basename
(
path
,
'.*'
)
end
}
end
# Public: Converts the provided Asciidoc markup into HTML.
#
# input - the source text in Asciidoc format
...
...
@@ -35,9 +48,10 @@ module Gitlab
include_processor
::
Gitlab
::
Asciidoc
::
IncludeProcessor
.
new
(
context
)
end
extra_attrs
=
path_attrs
(
context
[
:requested_path
])
asciidoc_opts
=
{
safe: :secure
,
backend: :gitlab_html5
,
attributes:
DEFAULT_ADOC_ATTRS
,
attributes:
DEFAULT_ADOC_ATTRS
.
merge
(
extra_attrs
)
,
extensions:
extensions
}
context
[
:pipeline
]
=
:ascii_doc
...
...
spec/lib/gitlab/asciidoc_spec.rb
View file @
e59de28e
...
...
@@ -46,6 +46,27 @@ module Gitlab
end
end
context
"with requested path"
do
input
=
<<~
ADOC
Document name: {docname}.
ADOC
it
"ignores {docname} when not available"
do
expect
(
render
(
input
,
{})).
to
include
(
input
.
strip
)
end
[
[
'/'
,
''
,
'root'
],
[
'README'
,
'README'
,
'just a filename'
],
[
'doc/api/'
,
''
,
'a directory'
],
[
'doc/api/README.adoc'
,
'README'
,
'a complete path'
]
].
each
do
|
path
,
basename
,
desc
|
it
"sets {docname} for
#{
desc
}
"
do
expect
(
render
(
input
,
{
requested_path:
path
})).
to
include
(
":
#{
basename
}
."
)
end
end
end
context
"XSS"
do
items
=
{
'link with extra attribute'
=>
{
...
...
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