alexmojaki / alexmojaki/futurecoder

Better tokenization of revealed solution

Offen
#97 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
1.5k
Forks
183
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

The `get_solution` function uses the standard Python tokenizer to split an exercise solution into tokens which the user can gradually reveal. This works pretty well, but:

1. f-strings are considered a single massive token, which reveals too much information in a single click.
2. There's no syntax highlighting :cry:

I think a good solution would be to use Pygments to highlight the solution and then treat each individual span as a separate token to be revealed by the user. For example, this Python code:

```python
print(f"{name} went to {meal} with {friend}.")
```

gets converted into:

```html
print(f"{name} went to {meal} with {friend}.")

```

Each span like `print` is a token. Any whitespace between tags (I don't see any in the example above) should be preserved, but is already 'revealed' from the beginning.

This could probably be done either by hooking into pygments, e.g. writing a custom formatter, or parsing the HTML produced by the standard formatter.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.