Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Specification Tools
Scripts
Commits
d2aba895
Commit
d2aba895
authored
1 year ago
by
Andreas Kraft
Committed by
Miguel Angel Reina Ortega
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Added support to write the text before the first header to 0.md
parent
f1a00539
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
toMkdocs/toMkdocs.py
+63
-8
63 additions, 8 deletions
toMkdocs/toMkdocs.py
with
63 additions
and
8 deletions
toMkdocs/toMkdocs.py
+
63
−
8
View file @
d2aba895
...
...
@@ -37,10 +37,52 @@ class Line:
@dataclass
class
Clause
:
"""
Represents a clause in the markdown file.
"""
level
:
int
clauseNumber
:
str
title
:
str
lines
:
list
[
Line
]
_level
:
int
_clauseNumber
:
str
_title
:
str
_lines
:
list
[
Line
]
@property
def
level
(
self
)
->
int
:
"""
Return the level of the clause.
"""
return
self
.
_level
@property
def
clauseNumber
(
self
)
->
str
:
"""
Return the clause number.
"""
return
self
.
_clauseNumber
if
self
.
_clauseNumber
else
'
0
'
@clauseNumber.setter
def
clauseNumber
(
self
,
value
:
str
)
->
None
:
"""
Set the clause number.
"""
self
.
_clauseNumber
=
value
@property
def
title
(
self
)
->
str
:
"""
Return the title of the clause.
"""
return
self
.
_title
@title.setter
def
title
(
self
,
value
:
str
)
->
None
:
"""
Set the title of the clause.
"""
self
.
_title
=
value
@property
def
lines
(
self
)
->
list
[
Line
]:
"""
Return the lines of the clause.
"""
return
self
.
_lines
@lines.setter
def
lines
(
self
,
value
:
list
[
Line
])
->
None
:
"""
Set the lines of the clause.
"""
self
.
_lines
=
value
@property
...
...
@@ -190,7 +232,7 @@ def analyseMarkdown(filename:str) -> list[Clause]:
def
splitMarkdownDocument
(
clauses
:
list
[
Clause
],
ignoreTitles
:
list
[
str
]
=
[],
splitLevel
:
int
=
1
,
i
gnor
eUntilFirstHeading
:
bool
=
Tru
e
)
->
list
[
Clause
]:
i
nclud
eUntilFirstHeading
:
bool
=
Fals
e
)
->
list
[
Clause
]:
"""
Split the clauses at a certain level. This is used to create the separate
markdown files for MkDocs.
...
...
@@ -198,7 +240,7 @@ def splitMarkdownDocument(clauses:list[Clause],
clauses: The list of clauses.
ignoreTitles: A list of titles that should be ignored. They are not included in the output.
splitLevel: The level at which the clauses should be split.
i
gnor
eUntilFirstHeader: Ignore all clauses until the first heading.
i
nclud
eUntilFirstHeader: Ignore all clauses until the first heading.
Returns:
The list of clauses.
...
...
@@ -221,7 +263,7 @@ def splitMarkdownDocument(clauses:list[Clause],
outClauses
[
-
1
].
extend
(
clause
)
# Remove the first clause if it has no title
if
ignor
eUntilFirstHeading
:
if
not
includ
eUntilFirstHeading
:
while
len
(
outClauses
[
0
].
title
)
==
0
:
outClauses
.
pop
(
0
)
...
...
@@ -391,6 +433,15 @@ def writeClauses(outClauses:list[Clause], filename:str, navTitle:str) -> None:
file
.
write
(
f
'
-
{
navTitle
}
:
\n
'
)
for
i
,
f
in
enumerate
(
outClauses
):
# TODO generate also the navigation for the first non-header clause
# if not f.title:
# if i == 0:
# file.write(f"{' '*(f.level+1)}- '': '{f.clauseNumber}.md'\n")
# continue
if
not
f
.
title
:
continue
# TODO handle if the next clause is more than one level deeper
_title
=
f
.
title
.
replace
(
"'"
,
'"'
)
...
...
@@ -431,7 +482,9 @@ def processDocument(args:argparse.Namespace) -> None:
# Analyse the markdown file
clauses
=
analyseMarkdown
(
document
)
clauses
=
splitMarkdownDocument
(
clauses
,
[
t
.
casefold
()
for
t
in
args
.
ignore_clause
],
args
.
split_level
)
clauses
=
splitMarkdownDocument
(
clauses
,
[
t
.
casefold
()
for
t
in
args
.
ignore_clause
],
args
.
split_level
,
args
.
include_title
)
clauses
=
updateLinks
(
clauses
)
clauses
=
updateNotes
(
clauses
)
clauses
=
prepareForMkdocs
(
clauses
)
...
...
@@ -450,9 +503,11 @@ if __name__ == '__main__':
parser
.
add_argument
(
'
--verbose
'
,
'
-v
'
,
action
=
'
store_true
'
,
help
=
'
verbose output during processing
'
)
parser
.
add_argument
(
'
--very-verbose
'
,
'
-vv
'
,
action
=
'
store_true
'
,
help
=
'
very verbose output during processing
'
)
parser
.
add_argument
(
'
--ignore-clause
'
,
'
-ic
'
,
metavar
=
'
clause
'
,
nargs
=
'
+
'
,
default
=
[
'
Contents
'
,
'
History
'
],
help
=
'
ignore headers in the markdown document
'
)
parser
.
add_argument
(
'
--include-title
'
,
'
-it
'
,
action
=
'
store_true
'
,
help
=
'
include the content before the first heading in the output files as
"
0.md
"'
)
parser
.
add_argument
(
'
--split-level
'
,
'
-sl
'
,
metavar
=
'
level
'
,
type
=
int
,
default
=
2
,
help
=
'
on which level to split clauses to separate files
'
)
parser
.
add_argument
(
'
--media-directory
'
,
'
-md
'
,
metavar
=
'
media-directory
'
,
default
=
'
media
'
,
help
=
'
directory name where media files are stored
'
)
parser
.
add_argument
(
'
--title
'
,
'
-t
'
,
metavar
=
'
title
'
,
required
=
True
,
help
=
'
mkdocs navigation tile
'
)
parser
.
add_argument
(
'
document
'
,
type
=
str
,
help
=
'
a oneM2M markdown specification document to process
'
)
args
=
parser
.
parse_args
()
processDocument
(
args
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment