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
06c05a87
Commit
06c05a87
authored
4 months ago
by
Miguel Angel Reina Ortega
Browse files
Options
Downloads
Patches
Plain Diff
Adding parameter in functions instead of global variables
parent
6c8a9ddc
No related branches found
No related tags found
1 merge request
!1
Restructuring and cleaning scripts for Mkdocs
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
toMkdocs/gridTableTools.py
+47
-48
47 additions, 48 deletions
toMkdocs/gridTableTools.py
with
47 additions
and
48 deletions
toMkdocs/gridTableTools.py
+
47
−
48
View file @
06c05a87
...
...
@@ -27,7 +27,7 @@ class GridCell:
self
.
auxiliarIndex
:
int
=
0
def
calculateAndSetAlignment
(
self
)
->
None
:
def
calculateAndSetAlignment
(
self
,
headerDelimiterPositions
:
list
[
int
],
delimiterPositions
:
list
[
int
],
defaultAlignments
:
list
[
str
],
hasHeader
:
bool
)
->
None
:
"""
Set the alignment of the cell based on the position of the delimiter.
"""
if
self
.
position
is
None
:
...
...
@@ -91,49 +91,6 @@ class GridRow():
def
__repr__
(
self
):
return
self
.
__str__
()
def
check_delimiter_alignment
(
line
:
str
,
delimiters
:
str
=
"
|+
"
)
->
bool
:
"""
Check if delimiters in a row align with expected positions.
Args:
line: The line of text to check
delimiter_positions: List of expected positions (based on + characters)
delimiters: String containing valid delimiter characters (default:
"
|+
"
)
Returns:
bool: True if delimiters align correctly, False otherwise
"""
if
not
line
or
not
delimiterPositions
:
return
False
print
(
f
"
\n
Checking line:
'
{
line
}
'"
)
print
(
f
"
Expected delimiter positions:
{
delimiterPositions
}
"
)
# For full separator lines (only +)
if
'
+
'
in
line
and
'
|
'
not
in
line
:
currentPositions
=
[
i
for
i
,
char
in
enumerate
(
line
)
if
(
char
==
'
+
'
and
i
!=
0
)]
print
(
f
"
Full separator line - Found + at positions:
{
currentPositions
}
"
)
return
all
(
delimiterPositions
[
-
1
]
in
currentPositions
and
line
.
startswith
(
"
+
"
)
and
pos
in
delimiterPositions
for
pos
in
currentPositions
)
# For data lines (only |)
if
'
|
'
in
line
and
'
+
'
not
in
line
:
currentPositions
=
[
i
for
i
,
char
in
enumerate
(
line
)
if
(
char
==
'
|
'
and
i
!=
0
)]
print
(
f
"
Data line - Found | at positions:
{
current_positions
}
"
)
return
all
(
delimiterPositions
[
-
1
]
in
currentPositions
and
line
.
startswith
(
"
|
"
)
and
pos
in
delimiterPositions
for
pos
in
currentPositions
)
# For partial separators (mix of + and |)
currentPositions
=
[
i
for
i
,
char
in
enumerate
(
line
)
if
(
char
in
delimiters
and
i
!=
0
)]
print
(
f
"
Partial separator - Found delimiters at positions:
{
currentPositions
}
"
)
print
(
f
"
Characters at those positions:
{
[
line
[
pos
]
for
pos
in
currentPositions
]
}
"
)
return
all
(
delimiterPositions
[
-
1
]
in
currentPositions
and
(
line
.
startswith
(
"
+
"
)
or
line
.
startswith
(
"
|
"
))
and
pos
in
delimiterPositions
for
pos
in
currentPositions
)
class
GridRowsTracker
():
"""
Represents the document object.
"""
def
__init__
(
self
,
size
:
int
)
->
None
:
...
...
@@ -167,7 +124,7 @@ def parseGridTableWithSpans(gridTable:str) -> tuple[GridTableRowList, GridTableR
:param pandoc_table: String of the Pandoc-style grid table.
:return: List of lists representing the table with metadata for spans.
"""
global
hasHeader
,
defaultAlignments
,
headerDelimiterPositions
,
delimiterPositions
,
nextListElementMark
#
global hasHeader, defaultAlignments, headerDelimiterPositions, delimiterPositions, nextListElementMark
# Initialize globals
hasHeader
=
False
...
...
@@ -248,6 +205,48 @@ def parseGridTableWithSpans(gridTable:str) -> tuple[GridTableRowList, GridTableR
row
[
columnIndex
].
colspanAdjusted
=
True
# Mark cell as adjusted
def
check_delimiter_alignment
(
line
:
str
,
delimiterPositions
:
list
[
int
],
delimiters
:
str
=
"
|+
"
)
->
bool
:
"""
Check if delimiters in a row align with expected positions.
Args:
line: The line of text to check
delimiter_positions: List of expected positions (based on + characters)
delimiters: String containing valid delimiter characters (default:
"
|+
"
)
Returns:
bool: True if delimiters align correctly, False otherwise
"""
if
not
line
or
not
delimiterPositions
:
return
False
print
(
f
"
\n
Checking line:
'
{
line
}
'"
)
print
(
f
"
Expected delimiter positions:
{
delimiterPositions
}
"
)
# For full separator lines (only +)
if
'
+
'
in
line
and
'
|
'
not
in
line
:
currentPositions
=
[
i
for
i
,
char
in
enumerate
(
line
)
if
(
char
==
'
+
'
and
i
!=
0
)]
print
(
f
"
Full separator line - Found + at positions:
{
currentPositions
}
"
)
return
all
(
delimiterPositions
[
-
1
]
in
currentPositions
and
line
.
startswith
(
"
+
"
)
and
pos
in
delimiterPositions
for
pos
in
currentPositions
)
# For data lines (only |)
if
'
|
'
in
line
and
'
+
'
not
in
line
:
currentPositions
=
[
i
for
i
,
char
in
enumerate
(
line
)
if
(
char
==
'
|
'
and
i
!=
0
)]
print
(
f
"
Data line - Found | at positions:
{
currentPositions
}
"
)
return
all
(
delimiterPositions
[
-
1
]
in
currentPositions
and
line
.
startswith
(
"
|
"
)
and
pos
in
delimiterPositions
for
pos
in
currentPositions
)
# For partial separators (mix of + and |)
currentPositions
=
[
i
for
i
,
char
in
enumerate
(
line
)
if
(
char
in
delimiters
and
i
!=
0
)]
print
(
f
"
Partial separator - Found delimiters at positions:
{
currentPositions
}
"
)
print
(
f
"
Characters at those positions:
{
[
line
[
pos
]
for
pos
in
currentPositions
]
}
"
)
return
all
(
delimiterPositions
[
-
1
]
in
currentPositions
and
(
line
.
startswith
(
"
+
"
)
or
line
.
startswith
(
"
|
"
))
and
pos
in
delimiterPositions
for
pos
in
currentPositions
)
separatorIndices
=
[
i
for
i
,
line
in
enumerate
(
lines
)
if
isSeparator
(
line
)]
...
...
@@ -334,7 +333,7 @@ def parseGridTableWithSpans(gridTable:str) -> tuple[GridTableRowList, GridTableR
cell
.
position
=
delimiterIndex
# Position of cell delimiter +
# Set alignment as defined by header separator line
cell
.
calculateAndSetAlignment
()
cell
.
calculateAndSetAlignment
(
headerDelimiterPositions
,
delimiterPositions
,
defaultAlignments
,
hasHeader
)
while
delimiterIndex
>
delimiterPositions
[
columnIndex
]:
columnIndex
+=
1
...
...
@@ -358,7 +357,7 @@ def parseGridTableWithSpans(gridTable:str) -> tuple[GridTableRowList, GridTableR
auxDelimiterIndex
+=
len
(
content
)
+
1
cell
=
rows
[
-
1
][
auxiliarCellIndex
]
cell
.
position
=
auxDelimiterIndex
# Position of cell delimiter +
cell
.
calculateAndSetAlignment
()
cell
.
calculateAndSetAlignment
(
headerDelimiterPositions
,
delimiterPositions
,
defaultAlignments
,
hasHeader
)
while
auxDelimiterIndex
>
delimiterPositions
[
auxiliarCellIndex
]:
auxiliarCellIndex
+=
1
auxiliarCellIndex
+=
1
...
...
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