Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
hallgrim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
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
Jan Maximilian Michal
hallgrim
Commits
355b843d
Commit
355b843d
authored
8 years ago
by
Jan Maximilian Michal
Browse files
Options
Downloads
Patches
Plain Diff
Added simple Latex support. Escaping is not satisfying yet
parent
2a012ebf
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+1
-0
1 addition, 0 deletions
README.md
gen.py
+3
-9
3 additions, 9 deletions
gen.py
hallgrim/parser.py
+46
-1
46 additions, 1 deletion
hallgrim/parser.py
scripts/multi_proto.py
+1
-1
1 addition, 1 deletion
scripts/multi_proto.py
with
51 additions
and
11 deletions
README.md
+
1
−
0
View file @
355b843d
...
...
@@ -19,6 +19,7 @@ question.
*
Add more functionality (gap, alignment, etc.)
*
Make parsers more robust.
*
reverse ILIAS authentication mechanism for automated upload.
*
Enable LaTeX through custom lexer in mistune.
### Notes
...
...
This diff is collapsed.
Click to expand it.
gen.py
+
3
−
9
View file @
355b843d
#!/usr/local/bin/python3
try
:
import
mistune
except
ImportError
as
err
:
print
(
"
Please install mistune to make use of markdown parsing.
"
)
print
(
"
\t
pip install mistune
"
)
import
importlib
import
argparse
import
os
...
...
@@ -13,8 +7,8 @@ import sys
# local import
from
hallgrim.IliasXMLCreator
import
multi
,
single
import
hallgrim.parser
from
hallgrim.messages
import
*
from
hallgrim.parser
import
*
def
filename_to_module
(
name
):
...
...
@@ -51,12 +45,12 @@ def main():
script
=
importlib
.
import_module
(
filename_to_module
(
script_name
))
data
=
{
'
description
'
:
"
_description
"
,
'
question_text
'
:
mistune
.
markdown
(
script
.
task
),
'
question_text
'
:
markdown
(
script
.
task
),
'
author
'
:
script
.
meta
[
'
author
'
],
'
title
'
:
script
.
meta
[
'
title
'
],
'
maxattempts
'
:
'
0
'
,
'
shuffle
'
:
True
,
'
questions
'
:
hallgrim
.
parser
.
choice_parser
(
script
.
choices
),
'
questions
'
:
choice_parser
(
script
.
choices
),
}
output
=
os
.
path
.
join
(
...
...
This diff is collapsed.
Click to expand it.
hallgrim/parser.py
+
46
−
1
View file @
355b843d
import
re
import
mistune
import
copy
try
:
from
mistune
import
Renderer
,
InlineGrammar
,
InlineLexer
,
Markdown
except
ImportError
as
err
:
print
(
"
Please install mistune to make use of markdown parsing.
"
)
print
(
"
\t
pip install mistune
"
)
class
LaTeXRenderer
(
Renderer
):
def
latex
(
self
,
formula
):
return
'
<span class=
"
latex
"
>{}</span>
'
.
format
(
formula
)
class
LaTeXInlineLexer
(
InlineLexer
):
def
enable_latex
(
self
):
# add latex rules
self
.
rules
.
latex
=
re
.
compile
(
r
'
\[\[
'
# [[
r
'
([^\]]+)
'
# Page 2|Page 2
r
'
\]\](?!\])
'
# ]]
)
# Add latex parser to default rules
# you can insert it some place you like
# but place matters, maybe 3 is not good
self
.
default_rules
.
insert
(
3
,
'
latex
'
)
def
output_latex
(
self
,
m
):
formula
=
m
.
group
(
1
)
# you can create an custom render
# you can also return the html if you like
return
self
.
renderer
.
latex
(
formula
)
def
get_custom_markdown
():
renderer
=
LaTeXRenderer
()
inline
=
LaTeXInlineLexer
(
renderer
)
# enable the feature
inline
.
enable_latex
()
return
Markdown
(
renderer
,
inline
=
inline
)
def
choice_parser
(
raw_choices
):
lines
=
raw_choices
.
strip
().
split
(
'
\n
'
)
parse
=
[
re
.
match
(
'
\[(X| )\] (.*)
'
,
line
).
groups
()
for
line
in
lines
]
final
=
[(
mistune
.
markdown
(
text
),
True
if
mark
==
'
X
'
else
False
,
0.5
)
for
mark
,
text
in
parse
]
final
=
[(
markdown
(
text
),
True
if
mark
==
'
X
'
else
False
,
0.5
)
for
mark
,
text
in
parse
]
return
final
markdown
=
get_custom_markdown
()
This diff is collapsed.
Click to expand it.
scripts/multi_proto.py
+
1
−
1
View file @
355b843d
...
...
@@ -5,7 +5,7 @@ meta = {
}
task
=
"""
Hier der Anfang der Datei `punkte.csv`, die Komma-getrennte Angaben
zu erreichten Übungspunkten enthält:
zu erreichten Übungspunkten enthält
[[Example Formula
\\
sum_{i=0}^n i]]
:
```
21600001,Herr,Bollman,Fritze-Peter,15
...
...
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