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
1ea0f0c9
Commit
1ea0f0c9
authored
2 years ago
by
Andreas Kraft
Browse files
Options
Downloads
Patches
Plain Diff
Added missing sys import. Added figure caption handling.
parent
e4f5e2da
No related branches found
No related tags found
No related merge requests found
Pipeline
#89
passed
2 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pandocFilter/pandocFilter.py
+28
-1
28 additions, 1 deletion
pandocFilter/pandocFilter.py
with
28 additions
and
1 deletion
pandocFilter/pandocFilter.py
+
28
−
1
View file @
1ea0f0c9
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
# License: BSD 3-Clause License. See the LICENSE file for further details.
# License: BSD 3-Clause License. See the LICENSE file for further details.
#
#
import
argparse
,
os
,
re
import
argparse
,
os
,
re
,
sys
from
rich
import
print
from
rich
import
print
from
rich.progress
import
Progress
,
TextColumn
,
TimeElapsedColumn
from
rich.progress
import
Progress
,
TextColumn
,
TimeElapsedColumn
...
@@ -98,11 +98,38 @@ def replaceTableCaptions(progress:Progress, mdLines:list[str]) -> list[str]:
...
@@ -98,11 +98,38 @@ def replaceTableCaptions(progress:Progress, mdLines:list[str]) -> list[str]:
return
_lines
return
_lines
def
replaceFigureCaptions
(
progress
:
Progress
,
mdLines
:
list
[
str
])
->
list
[
str
]:
"""
Replace table captions with a pandoc table caption.
"""
_taskID
=
progress
.
add_task
(
'
[blue]Replacing figure captions
'
,
start
=
False
,
total
=
0
)
# progress.update()
figureregex
=
re
.
compile
(
'
^\*\*(Figure .*)\*\*
'
)
_lines
:
list
[
str
]
=
[]
for
line
in
mdLines
:
matches
=
re
.
findall
(
figureregex
,
line
)
if
matches
:
# Replace the previous figure markdown name with the captions
_idx
=
len
(
_lines
)
-
1
while
_idx
>=
0
and
not
_lines
[
_idx
].
startswith
(
'
![
'
):
_idx
-=
1
if
_idx
>
0
:
_lines
[
_idx
]
=
re
.
sub
(
r
'
^.*?]
'
,
f
'
![
{
matches
[
0
]
}
]
'
,
_lines
[
_idx
])
else
:
_lines
.
append
(
line
)
progress
.
stop_task
(
_taskID
)
return
_lines
def
process
(
document
:
str
,
outDirectory
:
str
)
->
None
:
def
process
(
document
:
str
,
outDirectory
:
str
)
->
None
:
with
Progress
(
TextColumn
(
'
{task.description}
'
),
TimeElapsedColumn
())
as
progress
:
with
Progress
(
TextColumn
(
'
{task.description}
'
),
TimeElapsedColumn
())
as
progress
:
mdLines
=
readMDFile
(
progress
,
document
)
mdLines
=
readMDFile
(
progress
,
document
)
mdLines
=
correctTOC
(
progress
,
mdLines
)
mdLines
=
correctTOC
(
progress
,
mdLines
)
mdLines
=
replaceTableCaptions
(
progress
,
mdLines
)
mdLines
=
replaceTableCaptions
(
progress
,
mdLines
)
mdLines
=
replaceFigureCaptions
(
progress
,
mdLines
)
writeMDFile
(
progress
,
mdLines
,
document
,
outDirectory
)
writeMDFile
(
progress
,
mdLines
,
document
,
outDirectory
)
def
main
(
args
=
None
):
def
main
(
args
=
None
):
...
...
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