Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
f38cd437
Unverified
Commit
f38cd437
authored
Apr 13, 2021
by
Sylvain Gugger
Committed by
GitHub
Apr 13, 2021
Browse files
Indent code block in the documentation (#11233)
* Indent code block * Indent code blocks version 2 * Quality
parent
9d8e8a87
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
382 additions
and
357 deletions
+382
-357
docs/source/add_new_model.rst
docs/source/add_new_model.rst
+9
-9
docs/source/converting_tensorflow_models.rst
docs/source/converting_tensorflow_models.rst
+46
-46
docs/source/glossary.rst
docs/source/glossary.rst
+1
-1
docs/source/main_classes/trainer.rst
docs/source/main_classes/trainer.rst
+158
-158
docs/source/model_doc/bert_japanese.rst
docs/source/model_doc/bert_japanese.rst
+18
-18
docs/source/model_doc/bertgeneration.rst
docs/source/model_doc/bertgeneration.rst
+19
-19
docs/source/model_doc/bertweet.rst
docs/source/model_doc/bertweet.rst
+15
-15
docs/source/model_doc/herbert.rst
docs/source/model_doc/herbert.rst
+10
-10
docs/source/model_doc/layoutlm.rst
docs/source/model_doc/layoutlm.rst
+10
-10
docs/source/model_doc/megatron_bert.rst
docs/source/model_doc/megatron_bert.rst
+6
-6
docs/source/model_doc/megatron_gpt2.rst
docs/source/model_doc/megatron_gpt2.rst
+3
-3
docs/source/model_doc/phobert.rst
docs/source/model_doc/phobert.rst
+12
-12
docs/source/model_doc/reformer.rst
docs/source/model_doc/reformer.rst
+2
-2
docs/source/model_doc/t5.rst
docs/source/model_doc/t5.rst
+8
-8
docs/source/testing.rst
docs/source/testing.rst
+39
-39
utils/style_doc.py
utils/style_doc.py
+26
-1
No files found.
docs/source/add_new_model.rst
View file @
f38cd437
docs/source/converting_tensorflow_models.rst
View file @
f38cd437
docs/source/glossary.rst
View file @
f38cd437
docs/source/main_classes/trainer.rst
View file @
f38cd437
docs/source/model_doc/bert_japanese.rst
View file @
f38cd437
docs/source/model_doc/bertgeneration.rst
View file @
f38cd437
docs/source/model_doc/bertweet.rst
View file @
f38cd437
docs/source/model_doc/herbert.rst
View file @
f38cd437
docs/source/model_doc/layoutlm.rst
View file @
f38cd437
docs/source/model_doc/megatron_bert.rst
View file @
f38cd437
docs/source/model_doc/megatron_gpt2.rst
View file @
f38cd437
docs/source/model_doc/phobert.rst
View file @
f38cd437
docs/source/model_doc/reformer.rst
View file @
f38cd437
docs/source/model_doc/t5.rst
View file @
f38cd437
docs/source/testing.rst
View file @
f38cd437
utils/style_doc.py
View file @
f38cd437
...
...
@@ -49,6 +49,7 @@ _re_indent = re.compile(r"^(\s*)\S")
_re_table
=
re
.
compile
(
r
"(\+-+)+\+\s*$"
)
# Matches a code block in rst `:: `.
_re_code_block
=
re
.
compile
(
r
"^\s*::\s*$"
)
_re_code_block_explicit
=
re
.
compile
(
r
"^\.\.\s+code\-block::"
)
# Matches any block of the form `.. something::` or `.. something:: bla`.
_re_ignore
=
re
.
compile
(
r
"^\s*\.\.\s+(.*?)\s*::\s*\S*\s*$"
)
# Matches comment introduction in rst.
...
...
@@ -374,6 +375,28 @@ rst_styler = CodeStyler()
doc_styler
=
DocstringStyler
()
def
_reindent_code_blocks
(
text
):
"""Checks indent in code blocks is of four"""
lines
=
text
.
split
(
"
\n
"
)
idx
=
0
while
idx
<
len
(
lines
):
# Detect if the line is the start of a new code-block.
if
_re_code_block
.
search
(
lines
[
idx
])
is
not
None
or
_re_code_block_explicit
.
search
(
lines
[
idx
])
is
not
None
:
while
len
(
get_indent
(
lines
[
idx
]))
==
0
:
idx
+=
1
indent
=
len
(
get_indent
(
lines
[
idx
]))
should_continue
=
True
while
should_continue
:
if
len
(
lines
[
idx
])
>
0
and
indent
<
4
:
lines
[
idx
]
=
" "
*
4
+
lines
[
idx
][
indent
:]
idx
+=
1
should_continue
=
(
idx
<
len
(
lines
))
and
(
len
(
lines
[
idx
])
==
0
or
len
(
get_indent
(
lines
[
idx
]))
>
0
)
else
:
idx
+=
1
return
"
\n
"
.
join
(
lines
)
def
_add_new_lines_before_list
(
text
):
"""Add a new empty line before a list begins."""
lines
=
text
.
split
(
"
\n
"
)
...
...
@@ -412,8 +435,10 @@ def style_rst_file(doc_file, max_len=119, check_only=False):
with
open
(
doc_file
,
"r"
,
encoding
=
"utf-8"
,
newline
=
"
\n
"
)
as
f
:
doc
=
f
.
read
()
# Make sure code blocks are indented at 4
clean_doc
=
_reindent_code_blocks
(
doc
)
# Add missing new lines before lists
clean_doc
=
_add_new_lines_before_list
(
doc
)
clean_doc
=
_add_new_lines_before_list
(
clean_
doc
)
# Style
clean_doc
=
rst_styler
.
style
(
clean_doc
,
max_len
=
max_len
)
...
...
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