Skip to content

Commit

Permalink
feat: shorthand
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Aug 6, 2023
1 parent ac369bd commit 6717332
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
9 changes: 9 additions & 0 deletions examples/just_paths.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
`data/mcc/functions/demo.mcfunction`
```
function mcc:thingy/baked_7gixa943r3e39
```

`data/mcc/functions/thingy/baked_7gixa943r3e39.mcfunction`
```
execute as @a[tag=foo] run say hello
```
16 changes: 15 additions & 1 deletion lectern/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
FragmentLoader = Callable[[Fragment, Mapping[str, Directive]], Optional[Fragment]]


RELATIVE_PATH_REGEX = re.compile(r"^(?:assets|data)(?:/[a-zA-Z0-9_.]+)+$")


class Extractor:
"""Base class for extractors."""

Expand Down Expand Up @@ -291,7 +294,18 @@ def parse_fragments(
and (inline := tokens[i + 1])
and inline.children
and self.match_tokens(inline.children, "code_inline")
and (match := regex.match(inline.children[0].content))
and (
match := regex.match(inline := inline.children[0].content)
or (
RELATIVE_PATH_REGEX.match(inline)
and (
directive := "@resource_pack"
if inline.startswith("assets")
else "@data_pack"
)
and regex.match(f"{directive} {inline}")
)
)
):
yield self.create_fragment(
current_line, skip_to, match, content=tokens[i + 3].content
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Lectern snapshot

## Data pack

`@data_pack pack.mcmeta`

```json
{
"pack": {
"pack_format": 15,
"description": ""
}
}
```

### mcc

`@function mcc:demo`

```mcfunction
function mcc:thingy/baked_7gixa943r3e39
```

`@function mcc:thingy/baked_7gixa943r3e39`

```mcfunction
execute as @a[tag=foo] run say hello
```
13 changes: 13 additions & 0 deletions tests/snapshots/examples__text_examples_just_paths_md__0.pack.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@data_pack pack.mcmeta
{
"pack": {
"pack_format": 15,
"description": ""
}
}

@function mcc:demo
function mcc:thingy/baked_7gixa943r3e39

@function mcc:thingy/baked_7gixa943r3e39
execute as @a[tag=foo] run say hello

0 comments on commit 6717332

Please sign in to comment.