Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Binary paint shop problem
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
Binary paint shop problem
Commits
12510933
Commit
12510933
authored
Feb 25, 2024
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Update na novou verzi formátitka
parent
5c60027d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
prace/bakalarka/bakalarka.py
+35
-19
35 additions, 19 deletions
prace/bakalarka/bakalarka.py
prace/bakalarka/formatitko_commands.py
+13
-9
13 additions, 9 deletions
prace/bakalarka/formatitko_commands.py
with
48 additions
and
28 deletions
prace/bakalarka/bakalarka.py
+
35
−
19
View file @
12510933
...
...
@@ -13,13 +13,13 @@ import plotly.graph_objects as go
import
formatitko
from
formatitko.transform
import
transform
from
formatitko.util
import
import_md
from
formatitko.context
import
Context
,
BlockGroup
from
formatitko.images
import
ImageProcessor
from
formatitko.output_generator
import
OutputGenerator
from
formatitko.images
import
ImageProcessor
,
ImageProcessorNamespace
from
formatitko.output_generator
import
OutputGenerator
,
FormatitkoRecursiveError
from
formatitko.transform_processor
import
TransformProcessor
from
formatitko.tex_generator
import
UCWTexGenerator
tracebacklimit
=
100
from
panflute
import
convert_text
import
panflute
as
pf
...
...
@@ -38,7 +38,7 @@ def formatitko_command(f):
return
f
@formatitko_command
def
formatitko_code_and_output
(
element
,
context
):
def
formatitko_code_and_output
(
element
,
context
,
processor
):
import
panflute
as
pf
code
=
element
.
text
old_stdout
=
sys
.
stdout
...
...
@@ -50,14 +50,14 @@ def formatitko_code_and_output(element, context):
for
name
in
[
"
highlight
"
]:
if
name
in
element
.
classes
:
attributes
[
name
]
=
element
.
classes
[
"
name
"
]
return
[
return
processor
.
transform
(
[
pf
.
CodeBlock
(
code
,
classes
=
element
.
classes
,
attributes
=
attributes
),
pf
.
Para
(
pf
.
Str
(
"
Output:
"
)),
pf
.
CodeBlock
(
output
.
getvalue
(),
classes
=
[
"
text
"
],
attributes
=
{
"
highlight
"
:
"
True
"
})
]
]
)
@formatitko_command
def
formatitko_plotly
(
element
,
context
):
def
formatitko_plotly
(
element
,
context
,
processor
):
code
=
element
.
text
globals
=
{
"
plotly
"
:
plotly_lib
,
"
go
"
:
go
,
"
fig
"
:
go
.
Figure
()}
...
...
@@ -68,24 +68,24 @@ def formatitko_plotly(element, context):
plotly_lib
.
io
.
kaleido
.
scope
.
mathjax
=
None
plotly_lib
.
io
.
write_image
(
fig
,
file
,
format
=
'
pdf
'
,
width
=
650
)
return
[
pf
.
Image
(
url
=
file
)]
return
processor
.
transform
(
[
pf
.
Image
(
url
=
file
)]
)
@formatitko_command
def
formatitko_sage
(
element
,
context
):
def
formatitko_sage
(
element
,
context
,
processor
):
import
sage.all
code
=
element
.
text
file
=
element
.
attributes
[
"
name
"
]
+
"
.pdf
"
r
=
sage
.
all
.
sage_eval
(
"
r
"
,
cmds
=
code
)
r
.
save
(
file
)
return
[
pf
.
Image
(
url
=
file
)]
r
.
save
(
file
,
figsize
=
3
)
return
processor
.
transform
(
[
pf
.
Image
(
url
=
file
)]
)
@formatitko_command
def
formatitko_head
(
element
,
context
):
def
formatitko_head
(
element
,
context
,
processor
):
keywords
=
"
\n
"
.
join
(
f
"
/field
{
i
+
1
}
{{
{
v
}
}}
"
for
i
,
v
in
enumerate
(
context
.
get_metadata
(
"
ft.keywords
"
)
+
context
.
get_metadata
(
"
ft.en.keywords
"
)))
return
[
pf
.
RawBlock
(
f
"""
return
processor
.
transform
(
[
pf
.
RawBlock
(
f
"""
\\
startmetadata
dc:creator {{
{
context
.
get_metadata
(
"
ft.author
"
)
}
}}
dc:publisher {{Univerzita Karlova}}
...
...
@@ -118,25 +118,37 @@ def formatitko_head(element, context):
\\
def
\\
ftSupervisorDepartmentEN{{
{
context
.
get_metadata
(
"
ft.en.supervisor_department
"
)
or
context
.
get_metadata
(
"
ft.en.department
"
)
}
}}
\\
input head.tex
"""
,
format
=
"
tex
"
),
]
"""
,
format
=
"
tex
"
),
]
)
@formatitko_command
def
formatitko_tail
(
element
,
context
):
def
formatitko_tail
(
element
,
context
,
processor
):
return
[]
def
import_md
(
s
:
str
,
standalone
:
bool
=
True
,
bibliography
=
None
):
from
panflute
import
Element
,
Block
,
Inline
,
Null
,
Str
,
Doc
,
convert_text
,
Para
,
Plain
extra_args
=
[]
if
bibliography
:
extra_args
+=
[
"
-C
"
,
"
--bibliography=
"
+
str
(
bibliography
)]
return
convert_text
(
s
,
standalone
=
standalone
,
input_format
=
"
markdown-definition_lists
"
,
extra_args
=
extra_args
)
def
main
():
# Use panflute to parse the input MD file
doc
=
import_md
(
open
(
"
bakalarka/index.md
"
,
"
r
"
).
read
())
doc
=
import_md
(
open
(
"
bakalarka/index.md
"
,
"
r
"
).
read
()
,
bibliography
=
"
bakalarka/sample.bib
"
)
OutputGenerator
(
sys
.
stdout
).
generate
(
doc
)
tp
=
TransformProcessor
(
"
bakalarka/index.md
"
)
tp
.
add_command_module
(
formatitko_commands
)
try
:
doc
=
tp
.
transform
(
doc
)
except
FormatitkoRecursiveError
as
e
:
e
.
pretty_print
(
tracebacklimit
=
tracebacklimit
)
return
1
imageProcessor
=
ImageProcessor
({
""
:
ImageProcessorNamespace
(
"
img_public_dir
"
,
"
img_web_path
"
,
"
img_cache_dir
"
,
[
"
.
"
],
True
)})
imageProcessor
=
ImageProcessor
(
"
img_public_dir
"
,
"
img_web_path
"
,
"
img_cache_dir
"
,
"
.
"
)
with
open
(
"
formatitko.tex
"
,
"
w
"
)
as
file
:
d
=
pathlib
.
Path
(
"
/
"
.
join
(
formatitko
.
__file__
.
split
(
"
/
"
)[:
-
1
]))
...
...
@@ -144,7 +156,11 @@ def main():
file
.
write
(
source
.
read
())
with
open
(
"
bakalarka.tex
"
,
"
w
"
)
as
file
:
try
:
UCWTexGenerator
(
file
,
imageProcessor
).
generate
(
doc
)
except
FormatitkoRecursiveError
as
e
:
e
.
pretty_print
(
tracebacklimit
=
tracebacklimit
)
return
1
subprocess
.
run
([
"
luatex
"
,
"
bakalarka
"
],
check
=
True
)
...
...
This diff is collapsed.
Click to expand it.
prace/bakalarka/formatitko_commands.py
+
13
−
9
View file @
12510933
import
panflute
as
pf
from
formatitko.command_env
import
parse_string
from
formatitko.elements
import
Slanted
formatitko_commands
=
{}
def
formatitko_command
(
f
):
...
...
@@ -9,39 +10,42 @@ def formatitko_command(f):
return
f
def
make_emph
(
*
elements
):
def
make_emph
(
*
elements
,
wrap_class
=
pf
.
Emph
):
out
=
[]
for
e
in
elements
:
if
isinstance
(
e
,
pf
.
Para
)
or
isinstance
(
e
,
pf
.
Plain
):
out
.
append
(
type
(
e
)(
pf
.
Emph
(
*
e
.
content
)))
out
.
append
(
type
(
e
)(
wrap_class
(
*
e
.
content
)))
elif
isinstance
(
e
,
pf
.
BulletList
):
out
.
append
(
type
(
e
)(
*
(
pf
.
ListItem
(
*
make_emph
(
*
i
.
content
))
for
i
in
e
.
content
)))
out
.
append
(
type
(
e
)(
*
(
pf
.
ListItem
(
*
make_emph
(
*
i
.
content
,
wrap_class
=
wrap_class
))
for
i
in
e
.
content
)))
else
:
print
(
e
,
type
(
e
))
raise
NotImplemented
()
return
out
@formatitko_command
def
box
(
element
,
context
):
def
box
(
element
,
context
,
processor
):
content
=
processor
.
transform
(
element
.
content
)
title
=
{
'
fact
'
:
"
Fakt
"
,
'
task
'
:
"
Úloha
"
,
'
algo
'
:
"
Algoritmus
"
,
'
theorem
'
:
"
Věta
"
,
'
lemma
'
:
"
Lemma
"
}[
element
.
attributes
[
"
t
"
]]
out
=
[]
for
e
in
element
.
content
:
for
e
in
content
:
if
not
out
:
if
isinstance
(
e
,
pf
.
Para
):
out
.
append
(
pf
.
Para
(
pf
.
Strong
(
*
parse_string
(
f
"
{
title
}
:
"
)),
pf
.
Emph
(
*
e
.
content
)))
out
.
append
(
pf
.
Para
(
pf
.
Strong
(
*
parse_string
(
f
"
{
title
}
:
"
)),
Slanted
(
*
e
.
content
)))
else
:
raise
NotImplemented
()
else
:
out
+=
make_emph
(
e
)
out
+=
make_emph
(
e
,
wrap_class
=
Slanted
)
return
out
@formatitko_command
def
proof
(
element
,
context
):
out
=
[
i
for
i
in
element
.
content
]
def
proof
(
element
,
context
,
processor
):
out
=
processor
.
transform
(
element
.
content
)
if
isinstance
(
out
[
0
],
pf
.
Para
):
out
[
0
]
=
pf
.
Para
(
pf
.
Emph
(
*
parse_string
(
f
"
Důkaz:
"
)),
*
out
[
0
].
content
)
else
:
...
...
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