Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sectioning support #612

Open
b-studios opened this issue Jan 19, 2022 · 0 comments
Open

Sectioning support #612

b-studios opened this issue Jan 19, 2022 · 0 comments

Comments

@b-studios
Copy link

Imagine the following markdown document

# My Doc
## Common Definitions
```scala mdoc
def foo = 1
```


## Some Section
```scala mdoc:reset
def bar = 1
```

## Some Other Section
```scala mdoc:reset
def bar = 2
```

Sometimes resets are necessary to reuse the same name (bar here). However, full resetting is too restrictive in some cases because I still want to be able to access foo (which also might have been shadowed in-between).

Proposal

One solution would be a scoping mechanism similiar to reset-object, but with the possibility to name the object.

# My Doc
## Common Definitions
```scala mdoc:reset-object:common
def foo = 1
```


## Some Section
```scala mdoc:reset
import common._
def bar = 1 + foo
```

## Some Other Section
```scala mdoc:reset
import common._
def bar = 2 * foo
```

In the above example the first code fence triggers an object definition, named common. The second code fence (by means of reset) closes the prior object definition. It imports foo as a member of common and uses it.

Use Case

When writing text books sometimes it is necessary to refer back to prior definitions while shadowing names in between.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant